Skip to content

Commit 707e933

Browse files
committed
Dashboard: return unicode in models
`ugettext_lazy` is aliased as `_()` in `main.models`. This is needed in most cases but `__unicode__` should ensure that the returned value is text and not `django.utils.functional.__proxy__`. This is connected to archivematica/Issues#308.
1 parent 60b17a1 commit 707e933

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

src/dashboard/src/main/models.py

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def __unicode__(self):
224224
if self.title:
225225
return u'%s' % self.title
226226
else:
227-
return _('Untitled')
227+
return six.text_type(_('Untitled'))
228228

229229

230230
class MetadataAppliesToType(models.Model):
@@ -261,11 +261,11 @@ class Meta:
261261
db_table = u'Events'
262262

263263
def __unicode__(self):
264-
return _('%(type)s event on %(file_uuid)s (%(detail)s)') % {
264+
return six.text_type(_('%(type)s event on %(file_uuid)s (%(detail)s)') % {
265265
'type': self.even_type,
266266
'file_uuid': self.file_uuid,
267267
'detail': self.event_detail
268-
}
268+
})
269269

270270

271271
class Derivation(models.Model):
@@ -283,11 +283,11 @@ class Meta:
283283
db_table = u'Derivations'
284284

285285
def __unicode__(self):
286-
return _('%(derived)s derived from %(src)s in %(event)s') % {
286+
return six.text_type(_('%(derived)s derived from %(src)s in %(event)s') % {
287287
'derived': self.derived_file,
288288
'src': self.source_file,
289289
'event': self.event
290-
}
290+
})
291291

292292

293293
class UnitHiddenManager(models.Manager):
@@ -323,7 +323,7 @@ class Meta:
323323
db_table = u'SIPs'
324324

325325
def __unicode__(self):
326-
return _('SIP: {path}') % {'path': self.currentpath}
326+
return six.text_type(_('SIP: {path}') % {'path': self.currentpath})
327327

328328

329329
class TransferManager(models.Manager):
@@ -370,10 +370,10 @@ class Meta:
370370
verbose_name = _("Arranged SIPs")
371371

372372
def __unicode__(self):
373-
return _('%(original)s -> %(arrange)s') % {
373+
return six.text_type(_('%(original)s -> %(arrange)s') % {
374374
'original': self.original_path,
375375
'arrange': self.arrange_path
376-
}
376+
})
377377

378378

379379
class SIPArrangeAccessMapping(models.Model):
@@ -449,11 +449,12 @@ class Meta:
449449
db_table = u'Files'
450450

451451
def __unicode__(self):
452-
return _('File %(uuid)s: %(originallocation)s now at %(currentlocation)s') % {
453-
'uuid': self.uuid,
454-
'originallocation': self.originallocation,
455-
'currentlocation': self.currentlocation
456-
}
452+
return six.text_type(
453+
_('File %(uuid)s:%(originallocation)s'
454+
' now at %(currentlocation)s') % {
455+
'uuid': self.uuid,
456+
'originallocation': self.originallocation,
457+
'currentlocation': self.currentlocation})
457458

458459

459460
class Directory(models.Model):
@@ -477,11 +478,12 @@ class Meta:
477478
db_table = u'Directories'
478479

479480
def __unicode__(self):
480-
return _('Directory %(uuid)s: %(originallocation)s now at %(currentlocation)s') % {
481-
'uuid': self.uuid,
482-
'originallocation': self.originallocation,
483-
'currentlocation': self.currentlocation
484-
}
481+
return six.text_type(_(
482+
'Directory %(uuid)s: %(originallocation)s'
483+
' now at %(currentlocation)s') % {
484+
'uuid': self.uuid,
485+
'originallocation': self.originallocation,
486+
'currentlocation': self.currentlocation})
485487

486488
@classmethod
487489
def create_many(cls, dir_paths_uuids, unit_mdl, unit_type='transfer'):
@@ -520,10 +522,10 @@ class Meta:
520522
db_table = u'FilesIdentifiedIDs'
521523

522524
def __unicode__(self):
523-
return u'%(file)s is %(format)s' % {
525+
return six.text_type(_('%(file)s is %(format)s') % {
524526
'file': self.file_uuid,
525527
'format': self.format_version
526-
}
528+
})
527529

528530

529531
class Job(models.Model):
@@ -642,11 +644,11 @@ class Meta:
642644
verbose_name = _('Rights Statement')
643645

644646
def __unicode__(self):
645-
return _('%(basis)s for %(unit)s (%(id)s)') % {
647+
return six.text_type(_('%(basis)s for %(unit)s (%(id)s)') % {
646648
'basis': self.rightsbasis,
647649
'unit': self.metadataappliestoidentifier,
648650
'id': self.id
649-
}
651+
})
650652

651653

652654
class RightsStatementCopyright(models.Model):
@@ -855,10 +857,10 @@ class Meta:
855857
db_table = u'MicroServiceChains'
856858

857859
def __unicode__(self):
858-
return _('MicroServiceChain ID: %(uuid)s; %(desc)s') % {
860+
return six.text_type(_('MicroServiceChain ID: %(uuid)s; %(desc)s') % {
859861
'uuid': self.id,
860862
'desc': self.description
861-
}
863+
})
862864

863865

864866
class MicroServiceChainLink(models.Model):
@@ -875,7 +877,8 @@ class Meta:
875877
db_table = u'MicroServiceChainLinks'
876878

877879
def __unicode__(self):
878-
return _('MicroServiceChainLink ID: %(id)s') % {'id': self.id}
880+
return six.text_type(
881+
_('MicroServiceChainLink ID: %(id)s') % {'id': self.id})
879882

880883

881884
class MicroServiceChainLinkExitCode(models.Model):
@@ -902,11 +905,12 @@ class Meta:
902905
db_table = u'MicroServiceChainChoice'
903906

904907
def __unicode__(self):
905-
return _('MicroServiceChainChoice ID: %(uuid)s (%(chain)s at %(choice)s)') % {
906-
'uuid': self.id,
907-
'chain': self.chainavailable,
908-
'choice': self.choiceavailableatlink
909-
}
908+
return six.text_type(
909+
_('MicroServiceChainChoice ID: %(uuid)s'
910+
' (%(chain)s at %(choice)s)') % {
911+
'uuid': self.id,
912+
'chain': self.chainavailable,
913+
'choice': self.choiceavailableatlink})
910914

911915

912916
class MicroServiceChoiceReplacementDic(models.Model):
@@ -942,10 +946,10 @@ class Meta:
942946
db_table = 'TaskTypes'
943947

944948
def __unicode__(self):
945-
return _('TaskType ID: %(id)s, desc: %(desc)s') % {
949+
return six.text_type(_('TaskType ID: %(id)s, desc: %(desc)s') % {
946950
'id': self.id,
947951
'desc': self.description
948-
}
952+
})
949953

950954

951955
class TaskConfig(models.Model):
@@ -1162,7 +1166,8 @@ class FPCommandOutput(models.Model):
11621166
# Table name is main_fpcommandoutput
11631167

11641168
def __unicode__(self):
1165-
return u'<file: {file}; rule: {rule}; content: {content}'.format(file=self.file, rule=self.rule, content=self.content[:20])
1169+
return u'<file: {file}; rule: {rule}; content: {content}'.format(
1170+
file=self.file, rule=self.rule, content=self.content[:20])
11661171

11671172

11681173
class FileID(models.Model):
@@ -1189,7 +1194,7 @@ class LevelOfDescription(models.Model):
11891194
sortorder = models.IntegerField(default=0, db_column='sortOrder')
11901195

11911196
def __unicode__(self):
1192-
return _('%(sortorder)s: %(name)s') % {
1197+
return six.text_type(_('%(sortorder)s: %(name)s') % {
11931198
'sortorder': self.sortorder,
11941199
'name': self.name
1195-
}
1200+
})

0 commit comments

Comments
 (0)