]> git.parisson.com Git - telemeta.git/commitdiff
add internationalized verbose names to model fields, and gettext french translation...
authorolivier <>
Wed, 27 Jan 2010 13:21:03 +0000 (13:21 +0000)
committerolivier <>
Wed, 27 Jan 2010 13:21:03 +0000 (13:21 +0000)
telemeta/locale/fr/LC_MESSAGES/django.mo [new file with mode: 0644]
telemeta/locale/fr/LC_MESSAGES/django.po [new file with mode: 0644]
telemeta/models/core.py
telemeta/models/crem.py
telemeta/models/dublincore.py
telemeta/templates/telemeta_default/base.html
telemeta/templates/telemeta_default/collection_detail.html
telemeta/templatetags/telemeta_utils.py

diff --git a/telemeta/locale/fr/LC_MESSAGES/django.mo b/telemeta/locale/fr/LC_MESSAGES/django.mo
new file mode 100644 (file)
index 0000000..ac40e2e
Binary files /dev/null and b/telemeta/locale/fr/LC_MESSAGES/django.mo differ
diff --git a/telemeta/locale/fr/LC_MESSAGES/django.po b/telemeta/locale/fr/LC_MESSAGES/django.po
new file mode 100644 (file)
index 0000000..2a6d04a
--- /dev/null
@@ -0,0 +1,418 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-01-27 14:13+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: models/core.py:127
+msgid "Duration"
+msgstr ""
+
+#: models/core.py:132
+msgid "Enter a valid duration in HH:MM[:ss[.uuuuuu]] format."
+msgstr ""
+
+#: models/crem.py:150
+msgid "reference"
+msgstr "référence"
+
+#: models/crem.py:152
+msgid "archive format"
+msgstr "format d'archivage"
+
+#: models/crem.py:153 models/crem.py:289
+msgid "old code"
+msgstr "ancienne cote"
+
+#: models/crem.py:154 models/crem.py:290
+msgid "code"
+msgstr "cote"
+
+#: models/crem.py:155 models/crem.py:299 models/crem.py:379
+msgid "title"
+msgstr "titre"
+
+#: models/crem.py:156 models/crem.py:300
+msgid "original title / translation"
+msgstr "titre original / traduction"
+
+#: models/crem.py:157
+msgid "number of components (medium / piece)"
+msgstr "nb de composants (support / pièce)"
+
+#: models/crem.py:159
+msgid "secondary edition"
+msgstr "réédition"
+
+#: models/crem.py:160
+msgid "depositor / contributor"
+msgstr "déposant / contributeur"
+
+#: models/crem.py:161
+msgid "author of published notice"
+msgstr "auteur de la notice éditée"
+
+#: models/crem.py:162
+msgid "related documentation"
+msgstr "documentation associée"
+
+#: models/crem.py:163 models/crem.py:308
+msgid "collector"
+msgstr "collecteur"
+
+#: models/crem.py:164
+msgid "collector identical to depositor"
+msgstr "collecteur identique au déposant"
+
+#: models/crem.py:166
+msgid "publisher / status"
+msgstr "éditeur / statut"
+
+#: models/crem.py:167
+msgid "published"
+msgstr "édité"
+
+#: models/crem.py:168
+msgid "year published"
+msgstr "année de parution"
+
+#: models/crem.py:170
+msgid "publisher collection"
+msgstr "collection éditeur"
+
+#: models/crem.py:171
+msgid "publisher serial number"
+msgstr "numéro dans la série"
+
+#: models/crem.py:172
+msgid "bibliographic references"
+msgstr "références bibliographiques"
+
+#: models/crem.py:174
+msgid "mode of acquisition"
+msgstr "mode d'acquisition"
+
+#: models/crem.py:175 models/crem.py:314
+msgid "comment"
+msgstr "commentaire"
+
+#: models/crem.py:177
+msgid "record author"
+msgstr "rédacteur fiche"
+
+#: models/crem.py:179
+msgid "record writer"
+msgstr "saisie fiche"
+
+#: models/crem.py:181
+msgid "legal rights"
+msgstr "droit d'utilisation"
+
+#: models/crem.py:182
+msgid "copies"
+msgstr "autres exemplaires"
+
+#: models/crem.py:183
+msgid "recording year (from)"
+msgstr "année d'enregistrement (depuis)"
+
+#: models/crem.py:184
+msgid "recording year (until)"
+msgstr "année d'enregistrement (jusqu'à)"
+
+#: models/crem.py:186
+msgid "recording context"
+msgstr "context d'enregistrement"
+
+#: models/crem.py:187 models/crem.py:291
+msgid "approximative duration"
+msgstr "durée approximative"
+
+#: models/crem.py:188
+msgid "document type"
+msgstr "type de document"
+
+#: models/crem.py:189
+msgid "archiver notes"
+msgstr "notes de l'archiviste"
+
+#: models/crem.py:190
+msgid "status"
+msgstr "etat"
+
+#: models/crem.py:191
+msgid "CNRS depositor"
+msgstr "déposant CNRS"
+
+#: models/crem.py:192
+msgid "items finished"
+msgstr "fiches faîtes"
+
+#: models/crem.py:193
+msgid "a_informer_07_03"
+msgstr ""
+
+#: models/crem.py:195
+msgid "A/D conversion"
+msgstr "numérisation"
+
+#: models/crem.py:196 models/crem.py:316
+msgid "public access"
+msgstr "accès public"
+
+#: models/crem.py:232
+msgid "states / nations"
+msgstr "états / nations"
+
+#: models/crem.py:245
+msgid "populations / social groups"
+msgstr "populations / groupes sociaux"
+
+#: models/crem.py:253 models/crem.py:368
+msgid "computed duration"
+msgstr "durée calculée"
+
+#: models/crem.py:287
+msgid "collection"
+msgstr ""
+
+#: models/crem.py:288
+msgid "item number"
+msgstr "n° de l'item"
+
+#: models/crem.py:292
+msgid "recording date (from)"
+msgstr "date d'enregistrement (depuis)"
+
+#: models/crem.py:293
+msgid "recording date (until)"
+msgstr "date d'enregistrement (jusqu'à)"
+
+#: models/crem.py:295 models/crem.py:614 models/crem.py:628
+msgid "location"
+msgstr "lieu"
+
+#: models/crem.py:296
+msgid "location comment"
+msgstr "commentaire lieu"
+
+#: models/crem.py:298 models/crem.py:710
+msgid "population / social group"
+msgstr "population / groupe social"
+
+#: models/crem.py:301
+msgid "author"
+msgstr "auteur"
+
+#: models/crem.py:303
+msgid "vernacular name"
+msgstr "nom vernaculaire"
+
+#: models/crem.py:304
+msgid "comments"
+msgstr "commentaires"
+
+#: models/crem.py:305
+msgid "published reference"
+msgstr "référence éditée"
+
+#: models/crem.py:306
+msgid "moda_execut"
+msgstr ""
+
+#: models/crem.py:307
+msgid "copy of"
+msgstr "copie de"
+
+#: models/crem.py:309
+msgid "cultural area"
+msgstr "aire culturelle"
+
+#: models/crem.py:311
+msgid "generic name"
+msgstr "nom générique"
+
+#: models/crem.py:312
+msgid "collector selection"
+msgstr "sélection collecteur"
+
+#: models/crem.py:313
+msgid "depositor reference"
+msgstr "référence du déposant"
+
+#: models/crem.py:315
+msgid "file"
+msgstr "fichier"
+
+#: models/crem.py:378 models/crem.py:504 models/crem.py:644
+msgid "item"
+msgstr "item"
+
+#: models/crem.py:380
+msgid "start"
+msgstr "début"
+
+#: models/crem.py:381
+msgid "end"
+msgstr "fin"
+
+#: models/crem.py:391 models/crem.py:660
+msgid "value"
+msgstr "valeur"
+
+#: models/crem.py:461 models/crem.py:471 models/crem.py:535 models/crem.py:558
+#: models/crem.py:606 models/crem.py:700 models/crem.py:711
+msgid "name"
+msgstr "nom"
+
+#: models/crem.py:482 models/crem.py:495 models/crem.py:506
+msgid "instrument"
+msgstr ""
+
+#: models/crem.py:484
+msgid "parent instrument"
+msgstr "instrument parent"
+
+#: models/crem.py:493 models/crem.py:508 models/crem.py:615
+msgid "alias"
+msgstr "alias"
+
+#: models/crem.py:509
+msgid "instruments num"
+msgstr "nb instruments"
+
+#: models/crem.py:510
+msgid "interprets"
+msgstr "interprètes"
+
+#: models/crem.py:519
+msgid "username"
+msgstr "nom d'utilisateur"
+
+#: models/crem.py:520
+msgid "level"
+msgstr "niveau"
+
+#: models/crem.py:521
+msgid "first name"
+msgstr "prénom"
+
+#: models/crem.py:522
+msgid "last name"
+msgstr "nom de famille"
+
+#: models/crem.py:523
+msgid "phone"
+msgstr "téléphone"
+
+#: models/crem.py:524
+msgid "email"
+msgstr "e-mail"
+
+#: models/crem.py:547
+msgid "playlist"
+msgstr "liste de lecture"
+
+#: models/crem.py:548
+msgid "resource type"
+msgstr "type de ressource"
+
+#: models/crem.py:549
+msgid "resource"
+msgstr "ressource"
+
+#: models/crem.py:559
+msgid "type"
+msgstr ""
+
+#: models/crem.py:560
+msgid "complete type"
+msgstr "type complet"
+
+#: models/crem.py:562
+msgid "current name"
+msgstr "nom actuel"
+
+#: models/crem.py:563 models/crem.py:616
+msgid "authoritative"
+msgstr "officiel"
+
+#: models/crem.py:605
+msgid "identifier"
+msgstr "identifiant"
+
+#: models/crem.py:630
+msgid "parent location"
+msgstr "lieu parent"
+
+#: models/crem.py:645
+msgid "keyword"
+msgstr "mot-clé"
+
+#: models/crem.py:659
+msgid "publisher"
+msgstr "éditeur"
+
+#: models/crem.py:673
+msgid "element type"
+msgstr "type d'élément"
+
+#: models/crem.py:674
+msgid "element identifier"
+msgstr "identifiant de l'élément"
+
+#: models/crem.py:675
+msgid "modification type"
+msgstr "type de modification"
+
+#: models/crem.py:676
+msgid "time"
+msgstr "heure"
+
+#: models/crem.py:677
+msgid "user"
+msgstr "utilisateur"
+
+#: templates/telemeta_default/collection_detail.html:51
+msgid "Recording year"
+msgstr "Année d'enregistrement"
+
+#: templates/telemeta_default/collection_detail.html:61
+msgid "Geographic and cultural informations"
+msgstr "Indications géographiques et culturelles"
+
+#: templates/telemeta_default/collection_detail.html:74
+msgid "Legal mentions"
+msgstr "Mentions légales"
+
+#: templates/telemeta_default/collection_detail.html:94
+msgid "Archiving data"
+msgstr "Données d'archivage"
+
+#: templates/telemeta_default/collection_detail.html:115
+msgid "Technical data"
+msgstr "Données techniques"
+
+#: templates/telemeta_default/collection_detail.html:120
+msgid "Media type"
+msgstr "Type de media"
+
+#: templates/telemeta_default/collection_detail.html:120
+msgid "Audio"
+msgstr ""
+
+#: templates/telemeta_default/collection_detail.html:124
+msgid "Number of items"
+msgstr "Nombre d'items"
index 8e9ac64f5c07603590048acbd0a7d85424db44c9..c0618c2d7b4b5302c48014b56b0dd6e8edb9e2d0 100644 (file)
@@ -133,7 +133,7 @@ class DurationField(models.Field):
     }
 
     def __init__(self, *args, **kwargs):
-        super(DurationField, self).__init__(args, **normalize_field(kwargs, '00:00'))
+        super(DurationField, self).__init__(*args, **normalize_field(kwargs, '00:00'))
 
     def get_internal_type(self):
         return 'TimeField'
index e4804531b5e8142808794d62da81aa6d2d9af189..dd9378400349fa57d8c898b29778411c029c0846 100755 (executable)
@@ -38,10 +38,12 @@ import cremquery as query
 from xml.dom.minidom import getDOMImplementation
 from telemeta.util.unaccent import unaccent_icmp
 import re
+from django.db.models import FieldDoesNotExist
 from telemeta.models.core import DurationField, Duration, WeakForeignKey, EnhancedModel, \
                                  CharField, TextField, IntegerField, BooleanField, \
                                  DateTimeField, FileField, ForeignKey, FloatField, DateField
 from telemeta.models import dublincore as dc
+from django.utils.translation import ugettext_lazy as _
 
 class ModelCore(EnhancedModel):
 
@@ -114,6 +116,16 @@ class ModelCore(EnhancedModel):
             fields_list.append({'name': field.name, 'value': getattr(self, field.name)})
         return fields_list
 
+    @classmethod
+    def field_label(cls, field_name):
+        try:
+            return cls._meta.get_field(field_name).verbose_name
+        except FieldDoesNotExist:
+            try:
+                return getattr(cls, field_name).verbose_name
+            except AttributeError:
+                return field_name
+
     class Meta:
         abstract = True
 
@@ -135,43 +147,54 @@ class MediaCollection(MediaResource):
     unpublished_code_regex = 'CNRSMH_I_[0-9]{4}_[0-9]{3}'
     code_regex             = '(?:%s|%s)' % (published_code_regex, unpublished_code_regex)
 
-    reference             = CharField(unique=True, null=True)
-    physical_format       = WeakForeignKey('PhysicalFormat', related_name="collections")
-    old_code              = CharField(unique=True, null=True)
-    code                  = CharField(unique=True, required=True)
-    title                 = CharField(required=True)
-    alt_title             = CharField()
-    physical_items_num    = IntegerField(default=0)
-    publishing_status     = WeakForeignKey('PublishingStatus', related_name="collections")
-    creator               = CharField()
-    booklet_author        = CharField()
-    booklet_description   = TextField()
-    collector             = CharField()
-    collector_is_creator  = BooleanField()
-    publisher             = WeakForeignKey('Publisher', related_name="collections")     
-    is_published          = BooleanField()
-    year_published        = IntegerField()
-    publisher_collection  = WeakForeignKey('PublisherCollection', related_name="collections")
-    publisher_serial      = CharField()
-    external_references   = TextField()
-    acquisition_mode      = WeakForeignKey('AcquisitionMode', related_name="collections")
-    comment               = TextField()
-    metadata_author       = WeakForeignKey('MetadataAuthor', related_name="collections")
-    metadata_writer       = WeakForeignKey('MetadataWriter', related_name="collections")
-    legal_rights          = WeakForeignKey('LegalRight', related_name="collections")
-    alt_ids               = CharField()
-    recorded_from_year    = IntegerField()
-    recorded_to_year      = IntegerField()
-    recording_context     = WeakForeignKey('RecordingContext', related_name="collections")
-    approx_duration       = DurationField()
-    doctype_code          = IntegerField()
-    travail               = CharField()
-    state                 = TextField()
-    cnrs_contributor      = CharField()
-    items_done            = CharField()
-    a_informer_07_03      = CharField()
-    ad_conversion         = WeakForeignKey('AdConversion', related_name='collections')
-    public_access         = CharField(choices=PUBLIC_ACCESS_CHOICES, max_length=16, default="metadata")
+    reference             = CharField(_('reference'), unique=True, null=True)
+    physical_format       = WeakForeignKey('PhysicalFormat', related_name="collections", 
+                                           verbose_name=_('archive format'))
+    old_code              = CharField(_('old code'), unique=True, null=True)
+    code                  = CharField(_('code'), unique=True, required=True)
+    title                 = CharField(_('title'), required=True)
+    alt_title             = CharField(_('original title / translation'))
+    physical_items_num    = IntegerField(_('number of components (medium / piece)'))
+    publishing_status     = WeakForeignKey('PublishingStatus', related_name="collections", 
+                                           verbose_name=_('secondary edition'))
+    creator               = CharField(_('depositor / contributor'))
+    booklet_author        = CharField(_('author of published notice'))
+    booklet_description   = TextField(_('related documentation'))
+    collector             = CharField(_('collector'))
+    collector_is_creator  = BooleanField(_('collector identical to depositor'))
+    publisher             = WeakForeignKey('Publisher', related_name="collections", 
+                                           verbose_name=_('publisher / status'))     
+    is_published          = BooleanField(_('published'))
+    year_published        = IntegerField(_('year published'))
+    publisher_collection  = WeakForeignKey('PublisherCollection', related_name="collections", 
+                                            verbose_name=_('publisher collection'))
+    publisher_serial      = CharField(_('publisher serial number'))
+    external_references   = TextField(_('bibliographic references'))
+    acquisition_mode      = WeakForeignKey('AcquisitionMode', related_name="collections", 
+                                            verbose_name=_('mode of acquisition'))
+    comment               = TextField(_('comment'))
+    metadata_author       = WeakForeignKey('MetadataAuthor', related_name="collections", 
+                                           verbose_name=_('record author'))
+    metadata_writer       = WeakForeignKey('MetadataWriter', related_name="collections", 
+                                           verbose_name=_('record writer'))
+    legal_rights          = WeakForeignKey('LegalRight', related_name="collections", 
+                                           verbose_name=_('legal rights'))
+    alt_ids               = CharField(_('copies'))
+    recorded_from_year    = IntegerField(_('recording year (from)'))
+    recorded_to_year      = IntegerField(_('recording year (until)'))
+    recording_context     = WeakForeignKey('RecordingContext', related_name="collections", 
+                                           verbose_name=_('recording context'))
+    approx_duration       = DurationField(_('approximative duration'))
+    doctype_code          = IntegerField(_('document type'))
+    travail               = CharField(_('archiver notes'))
+    state                 = TextField(_('status'))
+    cnrs_contributor      = CharField(_('CNRS depositor'))
+    items_done            = CharField(_('items finished'))
+    a_informer_07_03      = CharField(_('a_informer_07_03'))
+    ad_conversion         = WeakForeignKey('AdConversion', related_name='collections', 
+                                           verbose_name=_('A/D conversion'))
+    public_access         = CharField(_('public access'), choices=PUBLIC_ACCESS_CHOICES, 
+                                      max_length=16, default="metadata")
 
     objects               = query.MediaCollectionManager()
 
@@ -193,7 +216,7 @@ class MediaCollection(MediaResource):
     def __name_cmp(self, obj1, obj2):
         return unaccent_icmp(obj1.name, obj2.name)
 
-    def get_countries(self):
+    def countries(self):
         "Return the countries of the items"
         countries = []
         items = self.items.all()
@@ -206,8 +229,9 @@ class MediaCollection(MediaResource):
         countries.sort(self.__name_cmp)                
 
         return countries
+    countries.verbose_name = _("states / nations")
 
-    def get_ethnic_groups(self):
+    def ethnic_groups(self):
         "Return the ethnic groups of the items"
         groups = []
         items = self.items.all()
@@ -218,6 +242,15 @@ class MediaCollection(MediaResource):
         groups.sort(self.__name_cmp)                
 
         return groups
+    ethnic_groups.verbose_name = _('populations / social groups')
+
+    def computed_duration(self):
+        duration = Duration()
+        for item in self.items.all():
+            duration += item.computed_duration()
+
+        return duration
+    computed_duration.verbose_name = _('computed duration')        
 
     def is_valid_code(self, code):
         "Check if the collection code is well formed"
@@ -250,33 +283,37 @@ class MediaItem(MediaResource):
     unpublished_code_regex  = MediaCollection.unpublished_code_regex + '_[0-9]{2,3}(?:_[0-9]{2}){0,2}'
     code_regex              = '(?:%s|%s)' % (published_code_regex, unpublished_code_regex)
 
-    collection            = ForeignKey('MediaCollection', related_name="items")
-    track                 = CharField()
-    old_code              = CharField(unique=True, null=True)
-    code                  = CharField(unique=True, null=True)
-    approx_duration       = DurationField()
-    recorded_from_date    = DateField()
-    recorded_to_date      = DateField()
-    location              = WeakForeignKey('Location', related_name="items",
-                                           db_column='location_name')
-    location_comment      = CharField()
-    ethnic_group          = WeakForeignKey('EthnicGroup', related_name="items")
-    title                 = CharField(required=True)
-    alt_title             = CharField()
-    author                = CharField()
-    vernacular_style      = WeakForeignKey('VernacularStyle', related_name="items")
-    context_comment       = TextField()
-    external_references   = TextField()
-    moda_execut           = CharField()
-    copied_from_item      = WeakForeignKey('self', related_name="copies")
-    collector             = CharField()
-    cultural_area         = CharField()
-    generic_style         = WeakForeignKey('GenericStyle', related_name="items")
-    collector_selection   = CharField()
-    creator_reference     = CharField()
-    comment               = TextField()
-    file                  = FileField(upload_to='items/%Y/%m/%d', db_column="filename")
-    public_access         = CharField(choices=PUBLIC_ACCESS_CHOICES, max_length=16, default="metadata")
+    collection            = ForeignKey('MediaCollection', related_name="items", 
+                                       verbose_name=_('collection'))
+    track                 = CharField(_('item number'))
+    old_code              = CharField(_('old code'), unique=True, null=True)
+    code                  = CharField(_('code'), unique=True, null=True)
+    approx_duration       = DurationField(_('approximative duration'))
+    recorded_from_date    = DateField(_('recording date (from)'))
+    recorded_to_date      = DateField(_('recording date (until)'))
+    location              = WeakForeignKey('Location', related_name="items", 
+                                           db_column='location_name', verbose_name=_('location'))
+    location_comment      = CharField(_('location comment'))
+    ethnic_group          = WeakForeignKey('EthnicGroup', related_name="items", 
+                                           verbose_name=_('population / social group'))
+    title                 = CharField(_('title'), required=True)
+    alt_title             = CharField(_('original title / translation'))
+    author                = CharField(_('author'))
+    vernacular_style      = WeakForeignKey('VernacularStyle', related_name="items", 
+                                           verbose_name=_('vernacular name'))
+    context_comment       = TextField(_('comments'))
+    external_references   = TextField(_('published reference'))
+    moda_execut           = CharField(_('moda_execut'))
+    copied_from_item      = WeakForeignKey('self', related_name="copies", verbose_name=_('copy of'))
+    collector             = CharField(_('collector'))
+    cultural_area         = CharField(_('cultural area'))
+    generic_style         = WeakForeignKey('GenericStyle', related_name="items", 
+                                           verbose_name=_('generic name'))
+    collector_selection   = CharField(_('collector selection'))
+    creator_reference     = CharField(_('depositor reference'))
+    comment               = TextField(_('comment'))
+    file                  = FileField(_('file'), upload_to='items/%Y/%m/%d', db_column="filename")
+    public_access         = CharField(_('public access'), choices=PUBLIC_ACCESS_CHOICES, max_length=16, default="metadata")
 
     objects               = query.MediaItemManager()
 
@@ -316,7 +353,7 @@ class MediaItem(MediaResource):
                                         % (self.code, self.collection.code))
         super(MediaItem, self).save(force_insert, force_update, using)
 
-    def duration(self):
+    def computed_duration(self):
         "Tell the length in seconds of this item media data"
         # FIXME: use TimeSide?
         seconds = 0
@@ -326,10 +363,9 @@ class MediaItem(MediaResource):
             seconds = media.getnframes() / media.getframerate()
             media.close()
 
-        if seconds:
-            return Duration(seconds=seconds)
+        return Duration(seconds=seconds)
 
-        return self.approx_duration
+    computed_duration.verbose_name = _('computed duration')        
 
     def __unicode__(self):
         if self.code:
@@ -339,10 +375,10 @@ class MediaItem(MediaResource):
 class MediaPart(MediaResource):
     "Describe an item part"
     element_type = 'part'
-    item  = ForeignKey('MediaItem', related_name="parts")
-    title = CharField(required=True)
-    start = FloatField(required=True)
-    end   = FloatField(required=True)
+    item  = ForeignKey('MediaItem', related_name="parts", verbose_name=_('item'))
+    title = CharField(_('title'), required=True)
+    start = FloatField(_('start'), required=True)
+    end   = FloatField(_('end'), required=True)
     
     class Meta(MetaCore):
         db_table = 'media_parts'
@@ -352,7 +388,7 @@ class MediaPart(MediaResource):
 
 class Enumeration(ModelCore):
     "Abstract enumerations base class"
-    value = CharField(required=True, unique=True)
+    value = CharField(_('value'), required=True, unique=True)
     
     def __unicode__(self):
         return self.value
@@ -422,7 +458,7 @@ class GenericStyle(Enumeration):
 
 class Instrument(ModelCore):
     "Instrument used in the item"
-    name    = CharField(required=True)
+    name    = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
         db_table = 'instruments'
@@ -432,7 +468,7 @@ class Instrument(ModelCore):
 
 class InstrumentAlias(ModelCore):
     "Instrument other name"
-    name = CharField(required=True)
+    name = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
         db_table = 'instrument_aliases'
@@ -442,8 +478,10 @@ class InstrumentAlias(ModelCore):
 
 class InstrumentRelation(ModelCore):
     "Instrument family"
-    instrument        = ForeignKey('Instrument', related_name="parent_relation")
-    parent_instrument = ForeignKey('Instrument', related_name="child_relation")
+    instrument        = ForeignKey('Instrument', related_name="parent_relation", 
+                                   verbose_name=_('instrument'))
+    parent_instrument = ForeignKey('Instrument', related_name="child_relation", 
+                                   verbose_name=_('parent instrument'))
 
     class Meta(MetaCore):
         db_table = 'instrument_relations'
@@ -451,8 +489,10 @@ class InstrumentRelation(ModelCore):
 
 class InstrumentAliasRelation(ModelCore):
     "Instrument family other name"
-    alias      = ForeignKey('InstrumentAlias', related_name="other_name")
-    instrument = ForeignKey('InstrumentAlias', related_name="relation")
+    alias      = ForeignKey('InstrumentAlias', related_name="other_name", 
+                            verbose_name=_('alias'))
+    instrument = ForeignKey('InstrumentAlias', related_name="relation", 
+                            verbose_name=_('instrument'))
 
     class Meta(MetaCore):
         db_table = 'instrument_alias_relations'
@@ -460,11 +500,14 @@ class InstrumentAliasRelation(ModelCore):
 
 class MediaItemPerformance(ModelCore):
     "Item performance"
-    media_item      = ForeignKey('MediaItem', related_name="performances")
-    instrument      = WeakForeignKey('Instrument', related_name="performances")
-    alias           = WeakForeignKey('InstrumentAlias', related_name="performances")
-    instruments_num = CharField()
-    musicians       = CharField()
+    media_item      = ForeignKey('MediaItem', related_name="performances", 
+                                 verbose_name=_('item'))
+    instrument      = WeakForeignKey('Instrument', related_name="performances", 
+                                     verbose_name=_('instrument'))
+    alias           = WeakForeignKey('InstrumentAlias', related_name="performances", 
+                                     verbose_name=_('alias'))
+    instruments_num = CharField(_('instruments num'))
+    musicians       = CharField(_('interprets'))
 
     class Meta(MetaCore):
         db_table = 'media_item_performances'
@@ -473,12 +516,12 @@ class User(ModelCore):
     "Telemeta user"
     LEVEL_CHOICES = (('user', 'user'), ('maintainer', 'maintainer'), ('admin', 'admin'))    
 
-    username   = CharField(primary_key=True, max_length=64, required=True)
-    level      = CharField(choices=LEVEL_CHOICES, max_length=32, required=True)
-    first_name = CharField()
-    last_name  = CharField()
-    phone      = CharField()
-    email      = CharField()
+    username   = CharField(_('username'), primary_key=True, max_length=64, required=True)
+    level      = CharField(_('level'), choices=LEVEL_CHOICES, max_length=32, required=True)
+    first_name = CharField(_('first name'))
+    last_name  = CharField(_('last name'))
+    phone      = CharField(_('phone'))
+    email      = CharField(_('email'))
 
     class Meta(MetaCore):
         db_table = 'users'
@@ -489,7 +532,7 @@ class User(ModelCore):
 class Playlist(ModelCore):
     "Item or collection playlist"
     owner_username = ForeignKey('User', related_name="playlists", db_column="owner_username") 
-    name           = CharField(required=True)
+    name           = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
         db_table = 'playlists'
@@ -501,9 +544,9 @@ class PlaylistResource(ModelCore):
     "Playlist components"
     RESOURCE_TYPE_CHOICES = (('item', 'item'), ('collection', 'collection'))
 
-    playlist              = ForeignKey('Playlist', related_name="resources")
-    resource_type         = CharField(choices=RESOURCE_TYPE_CHOICES, required=True)
-    resource              = IntegerField(required=True)
+    playlist              = ForeignKey('Playlist', related_name="resources", verbose_name=_('playlist'))
+    resource_type         = CharField(_('resource type'), choices=RESOURCE_TYPE_CHOICES, required=True)
+    resource              = IntegerField(_('resource'), required=True)
 
     class Meta(MetaCore):
         db_table = 'playlist_resources'
@@ -512,12 +555,12 @@ class Location(ModelCore):
     "Item location"
     TYPE_CHOICES     = (('country', 'country'), ('continent', 'continent'), ('other', 'other'))
 
-    name             = CharField(primary_key=True, max_length=150, required=True)
-    type             = CharField(choices=TYPE_CHOICES, max_length=16, required=True)
-    complete_type    = ForeignKey('LocationType', related_name="types")
-    current_name     = WeakForeignKey('self', related_name="past_names", 
-                                      db_column="current_name"
-    is_authoritative = BooleanField()
+    name             = CharField(_('name'), primary_key=True, max_length=150, required=True)
+    type             = CharField(_('type'), choices=TYPE_CHOICES, max_length=16, required=True)
+    complete_type    = ForeignKey('LocationType', related_name="types", verbose_name=_('complete type'))
+    current_name     = WeakForeignKey('self', related_name="past_names", db_column="current_name", 
+                                      verbose_name=_('current name')
+    is_authoritative = BooleanField(_('authoritative'))
 
     def parent(self):
         relations = self.parent_relations.all()
@@ -559,18 +602,18 @@ class Location(ModelCore):
 
 class LocationType(ModelCore):
     "Location type of an item location"
-    id   = CharField(max_length=64, primary_key=True, required=True)
-    name = CharField(max_length=150, required=True)
+    id   = CharField(_('identifier'), max_length=64, primary_key=True, required=True)
+    name = CharField(_('name'), max_length=150, required=True)
 
     class Meta(MetaCore):
         db_table = 'location_types'
 
 class LocationAlias(ModelCore):
     "Location other name"
-    location         = ForeignKey('Location', related_name="aliases",
-                                          db_column="location_name", max_length=150)
-    alias            = CharField(max_length=150, required=True)
-    is_authoritative = BooleanField()
+    location         = ForeignKey('Location', related_name="aliases", db_column="location_name", 
+                                  max_length=150, verbose_name=_('location'))
+    alias            = CharField(_('alias'), max_length=150, required=True)
+    is_authoritative = BooleanField(_('authoritative'))
 
     def __unicode__(self):
         return self.alias
@@ -581,10 +624,10 @@ class LocationAlias(ModelCore):
     
 class LocationRelation(ModelCore):
     "Location family"
-    location             = ForeignKey('Location', related_name="parent_relations",
-                                              db_column="location_name", max_length=150)
-    parent_location      = ForeignKey('Location', related_name="child_relations",
-                                              db_column="parent_location_name", null=True, max_length=150)
+    location             = ForeignKey('Location', related_name="parent_relations", 
+                                      db_column="location_name", max_length=150, verbose_name=_('location'))
+    parent_location      = ForeignKey('Location', related_name="child_relations", db_column="parent_location_name", 
+                                      null=True, max_length=150, verbose_name=_('parent location'))
     is_authoritative     = BooleanField()
 
     class Meta(MetaCore):
@@ -598,8 +641,8 @@ class ContextKeyword(Enumeration):
 
 class MediaItemKeyword(ModelCore):
     "Item keyword"
-    item    = ForeignKey('MediaItem')
-    keyword = ForeignKey('ContextKeyword')
+    item    = ForeignKey('MediaItem', verbose_name=_('item'))
+    keyword = ForeignKey('ContextKeyword', verbose_name=_('keyword'))
 
     class Meta(MetaCore):
         db_table = 'media_item_keywords'
@@ -613,8 +656,8 @@ class Publisher(Enumeration):
 
 class PublisherCollection(ModelCore):
     "Collection which belongs to publisher"
-    publisher = ForeignKey('Publisher', related_name="publisher_collections")
-    value     = CharField(required=True)
+    publisher = ForeignKey('Publisher', related_name="publisher_collections", verbose_name=_('publisher'))
+    value     = CharField(_('value'), required=True)
 
     def __unicode__(self):
         return self.value
@@ -627,11 +670,11 @@ class Revision(ModelCore):
     ELEMENT_TYPE_CHOICES = (('collection', 'collection'), ('item', 'item'), ('part', 'part'))
     CHANGE_TYPE_CHOICES  = (('import', 'import'), ('create', 'create'), ('update', 'update'), ('delete','delete'))
 
-    element_type         = CharField(choices=ELEMENT_TYPE_CHOICES, max_length=16, required=True)
-    element_id           = IntegerField(required=True)
-    change_type          = CharField(choices=CHANGE_TYPE_CHOICES, max_length=16, required=True)
-    time                 = DateTimeField(auto_now_add=True)
-    user                 = ForeignKey('User', db_column='username', related_name="revisions")
+    element_type         = CharField(_('element type'), choices=ELEMENT_TYPE_CHOICES, max_length=16, required=True)
+    element_id           = IntegerField(_('element identifier'), required=True)
+    change_type          = CharField(_('modification type'), choices=CHANGE_TYPE_CHOICES, max_length=16, required=True)
+    time                 = DateTimeField(_('time'), auto_now_add=True)
+    user                 = ForeignKey('User', db_column='username', related_name="revisions", verbose_name=_('user'))
     
     @classmethod
     def touch(cls, element, user):    
@@ -654,7 +697,7 @@ class Revision(ModelCore):
     
 class EthnicGroup(ModelCore):
     "Item ethnic group"
-    name = CharField(required=True)
+    name = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
         db_table = 'ethnic_groups'
@@ -664,8 +707,8 @@ class EthnicGroup(ModelCore):
 
 class EthnicGroupAlias(ModelCore):
     "Item ethnic group other name" 
-    ethnic_group = ForeignKey('EthnicGroup', related_name="aliases")
-    name         = CharField(required=True)
+    ethnic_group = ForeignKey('EthnicGroup', related_name="aliases", verbose_name=_('population / social group'))
+    name         = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
         db_table = 'ethnic_group_aliases'
index 2718f80cb8119fbdde37f0182f21a98ac2ed7dbe..5c833371f6549854a23542099ac74183bd1486f0 100644 (file)
@@ -144,18 +144,13 @@ def express_collection(collection):
     else:                        
         creator = Element('creator', collection.creator)
 
-    duration = Duration()
+    duration = max(collection.approx_duration, collection.computed_duration())
     parts = []
     for item in collection.items.all():
-        duration += item.duration()
-
         id = media_identifier(item)
         if id:
             parts.append(Element('relation', id, 'hasPart', item))
 
-    if duration < collection.approx_duration:            
-        duration = collection.approx_duration
-
     resource = Resource(
         Element('identifier',       media_identifier(collection), related=collection),
         Element('type',             'Collection'),
@@ -220,7 +215,8 @@ def express_item(item):
         Element('coverage',         item.location_comment, 'spatial'),
         Element('rights',           item.collection.legal_rights, 'license'),
         Element('rights',           media_access_rights(item.collection), 'accessRights'),
-        Element('format',           item.duration(), 'extent'),
+    
+        Element('format',           max(item.approx_duration, item.computed_duration()), 'extent'),
         Element('format',           item.collection.physical_format, 'medium'),
         #FIXME: audio mime types are missing,
         Element('relation',         media_identifier(item.collection), 'isPartOf', item.collection)
index 906666f1636af8ad3020bd937ed44ae46fde2784..8dbb01c24f278c01a7686f70c1f77d3ecaaacee7 100644 (file)
 {% load i18n %}
 {% load telemeta_utils %}
 <body>
-<!--
-{% if user.is_authenticated and user.is_staff %}
-<div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a> / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
-{% endif %}
--->
 <div id="layout">
 <div id="header">
 <div id="logo">
index 04171651c0da444549e74dc3c5006152ced80c4e..fdf8c94bc1b75864badabdd44b899198f868bcd5 100644 (file)
@@ -1,5 +1,6 @@
 {% extends "telemeta/base.html" %}\r
 {% load telemeta_utils %}\r
+{% load i18n %}\r
 \r
 {% block extra_javascript %}\r
 <script src="{% url telemeta-js "jquery.js" %}" type="text/javascript"></script>\r
               <p><b>Listen to this collection</b>\r
               (<a href="{% url telemeta-collection-m3u collection.public_id %}">M3U</a>,\r
               <a href="{% url telemeta-collection-xspf collection.public_id %}">XSPF</a>)</p>\r
-              {% if 0 %} {# Use 1/0 for alternate player #}\r
-                <!-- This is the XSPF Web Music Player, under the BSD license, \r
-                  from: http://musicplayer.sourceforge.net/-->\r
-                <object type="application/x-shockwave-flash" width="362" height="200"\r
-                  data="{% url telemeta-swf "xspf_player.swf" %}?playlist_url={% url telemeta-collection-xspf collection.public_id %}">\r
-                  <param name="movie" \r
-                    value="{% url telemeta-swf "xspf_player.swf" %}?playlist_url={% url telemeta-collection-xspf collection.public_id %}" />\r
-                </object>\r
-              {% else %}\r
                 <!-- This is Jeroen Wijering's Flash MP3 Player, \r
                   under CC Attribution-NonCommercial-ShareAlike 2.0 license\r
                   from: http://www.jeroenwijering.com/?item=Flash_MP3_Player-->\r
@@ -43,7 +35,6 @@
                   so.addVariable("displayheight","0");\r
                   so.write('collection_player_c');\r
                 </script> \r
-              {% endif %}\r
             </div>\r
         </div>\r
         {% endif %}\r
         <div class="infos">\r
         {% block general_info %}\r
             <dl class="listing">\r
-                {% if collection.creator %}<dt>Auteur / Cédant</dt><dd>{{ collection.creator }}</dd>{% endif %}\r
-\r
-                {% if collection.is_published %}\r
-                {% if collection.date_published %}<dt>Date</dt><dd>{{ collection.date_published }}</dd>{% endif %}\r
-                {% else %}\r
-                {% if collection.annee_enr %}<dt>Date</dt><dd>{{ collection.annee_enr }}</dd>{% endif %}\r
-                {% endif %}\r
-\r
-                {% if collection.title %}<dt>Titre</dt><dd>{{ collection.title }}</dd>{% endif %}\r
-                {% if collection.native_title %}<dt>Traduction du titre</dt><dd>{{ collection.native_title }}</dd>{% endif %}\r
-                {% if collection.duree_approx %}<dt>Durée</dt><dd>{{ collection.duree_approx }}</dd>{% endif %}\r
-\r
-                {% if collection.is_published %}\r
-                {% if collection.publisher %}<dt>Éditeur</dt><dd>{{ collection.publisher }}</dd>{% endif %}\r
-                {% if collection.publisher_reference %}<dt>Référence</dt><dd>{{ collection.publisher_reference }}</dd>{% endif %}\r
+                {% dl_field collection.title %}\r
+                {% dl_field collection.alt_title %}\r
+                {% dl_field collection.creator %}\r
+                {% if collection.recorded_from_year %}\r
+                <dt>{% trans "Recording year" %}</dt>\r
+                <dd>{{ collection.recorded_from_year }} {{ collection.recorded_to_year|prepend:" - "  }}</dd>\r
                 {% endif %}\r
-\r
+                {% dl_field collection.year_published %}\r
             </dl>\r
         {% endblock general_info %}\r
         </div>\r
         <div class="extraInfos">\r
         {% block geoethnic_data %}\r
             <div>\r
-                <h4><a href="#">Données ethnographiques</a></h4>\r
+                <h4><a href="#">{% trans "Geographic and cultural informations" %}</a></h4>\r
                 <div>\r
                     <dl class="listing">\r
-\r
-                    {% if collection.get_countries %}\r
-                    <dt>État / Nation</dt><dd>{{collection.get_countries|join:", "}}</dd>\r
-                    {% endif %}\r
-\r
-                    {% if collection.get_ethnic_groups %}\r
-                    <dt>Ethnie / Groupe social</dt><dd>{{ collection.get_ethnic_groups|join:", " }}</dd>\r
-                    {% endif %}\r
-\r
-                    {% if collection.terrain_ou_autre %}<dt>Contexte de l’enregistrement</dt><dd>{{ collection.terrain_ou_autre }}</dd>{% endif %}\r
-\r
+                    {% dl_field collection.countries join with ", " %}\r
+                    {% dl_field collection.ethnic_groups join with ", " %}\r
                     </dl>\r
                 </div>\r
             </div>\r
         {% endblock geoethnic_data %}\r
         </div>\r
-        {% if collection.is_published %}\r
         <div class="extraInfos">\r
-        {% block publication_data %}\r
-            <div class="folded">\r
-                <h4><a href="#">Détails du document édité</a></h4>\r
+        {% block legal_data %}\r
+            <div>\r
+                <h4><a href="#">{% trans "Legal mentions" %}</a></h4>\r
                 <div>\r
                     <dl class="listing">\r
-                    {% if collection.publishing_status %}<dt>Réédition</dt><dd>{{ collection.publishing_status }}</dd>{% endif %}\r
-                    {% if collection.booklet_writer %}<dt>Auteur Notice</dt><dd>{{ collection.booklet_writer }}</dd>{% endif %}\r
-                    {% if collection.booklet_description %}<dt>Notice</dt><dd>{{ collection.booklet_description }}</dd>{% endif %}\r
+                        {% dl_field collection.collector %}\r
+                        {% dl_field collection.publisher %}\r
+                        {% dl_field collection.publisher_collection %}\r
+                        {% dl_field collection.publisher_serial %}\r
+                        {% dl_field collection.booklet_author %}\r
+                        {% dl_field collection.external_references %}\r
+                        {% dl_field collection.doctype_code %}\r
+                        {% dl_field collection.public_access %}\r
+                        {% dl_field collection.legal_rights %}\r
                     </dl>\r
                 </div>\r
             </div>\r
-            <div class="nett"></div>\r
-        {% endblock publication_data %}\r
+        {% endblock legal_data %}\r
         </div>\r
-        {% endif %}\r
         <div class="extraInfos">\r
-        {% block document_identification %}\r
-            <div class="folded">\r
-                <h4><a href="#">Identification du document</a></h4>\r
+        {% block archive_data %}\r
+            <div>\r
+                <h4><a href="#">{% trans "Archiving data" %}</a></h4>\r
                 <div>\r
                     <dl class="listing">\r
-                    {% if collection.id %}<dt>Cote</dt><dd>{{ collection.id }}</dd>{% endif %}\r
-                    {% if collection.physical_format %}<dt>Format de l'original</dt><dd>{{ collection.physical_format }}</dd>{% endif %}\r
+                        {% dl_field collection.acquisition_mode %}\r
+                        {% dl_field collection.cnrs_contributor %}\r
+                        {% dl_field collection.metadata_writer %}\r
+                        {% dl_field collection.booklet_description %}\r
+                        {% dl_field collection.publishing_status %}\r
+                        {% dl_field collection.alt_ids %}\r
+                        {% dl_field collection.comment %}\r
+                        {% dl_field collection.metadata_writer %}\r
+                        {% dl_field collection.travail %}\r
+                        {% dl_field collection.items_done %}\r
                     </dl>\r
                 </div>\r
             </div>\r
-        {% endblock document_identification %}\r
+        {% endblock archive_data %}\r
         </div>\r
         <div class="extraInfos">\r
-        {% block document_data %}\r
-            <div class="folded">\r
-                <h4><a href="#">Informations documentaires</a></h4>\r
+        {% block technical_data %}\r
+            <div>\r
+                <h4><a href="#">{% trans "Technical data" %}</a></h4>\r
                 <div>\r
                     <dl class="listing">\r
-                    {% if collection.a_informer %}<dt>a informer</dt><dd>{{ collection.a_informer }}</dd>{% endif %}\r
-                    {% if collection.acquisition_mode %}<dt>acquisition mode</dt><dd>{{ collection.acquisition_mode }}</dd>{% endif %}\r
-                    {% if collection.champ36 %}<dt>champ36</dt><dd>{{ collection.champ36 }}</dd>{% endif %}\r
-                    {% if collection.collector %}<dt>collector</dt><dd>{{ collection.collector }}</dd>{% endif %}\r
-                    {% if collection.comment %}<dt>comment</dt><dd>{{ collection.comment }}</dd>{% endif %}\r
-                    <!--\r
-                    <dt>compil face plage</dt><dd>{{ object.compil_face_plage }}</dd>\r
-                    -->\r
-                    {% if collection.deposant_cnrs %}<dt>deposant cnrs</dt><dd>{{ collection.deposant_cnrs }}</dd>{% endif %}\r
-                    {% if collection.fiches %}<dt>fiches</dt><dd>{{ collection.fiches }}</dd>{% endif %}\r
-                    {% if collection.is_full_copy %}<dt>is full copy</dt><dd>{{ collection.is_full_copy }}</dd>{% endif %}\r
-                    {% if collection.is_original %}<dt>is original</dt><dd>{{ collection.is_original }}</dd>{% endif %}\r
-                    {% if collection.numerisation %}<dt>numerisation</dt><dd>{{ collection.numerisation }}</dd>{% endif %}\r
-                    {% if collection.physical_items_num %}<dt>physical items num</dt><dd>{{ collection.physical_items_num }}</dd>{% endif %}\r
-                    {% if collection.publisher_collection %}<dt>publisher collection</dt><dd>{{ collection.publisher_collection }}</dd>{% endif %}\r
-                    {% if collection.publisher_serial_id %}<dt>publisher serial id</dt><dd>{{ collection.publisher_serial_id }}</dd>{% endif %}\r
-                    {% if collection.record_author %}<dt>record author</dt><dd>{{ collection.record_author }}</dd>{% endif %}\r
-                    {% if collection.record_writer %}<dt>record writer</dt><dd>{{ collection.record_writer }}</dd>{% endif %}\r
-                    {% if collection.ref_biblio %}<dt>ref biblio</dt><dd>{{ collection.ref_biblio }}</dd>{% endif %}\r
-                    {% if collection.rights %}<dt>rights</dt><dd>{{ collection.rights }}</dd>{% endif %}\r
-                    {% if collection.travail %}<dt>travail</dt><dd>{{ collection.travail }}</dd>{% endif %}\r
-                    {% if collection.tri_dibm %}<dt>tri dibm</dt><dd>{{ collection.tri_dibm }}</dd>{% endif %}\r
+                        {% dl_field collection.code %}\r
+                        {% dl_field collection.old_code %}\r
+                        <dt>{% trans "Media type" %}</dt><dd>{% trans "Audio" %}</dd>\r
+                        {% dl_field collection.approx_duration %}\r
+                        {% dl_field collection.computed_duration %}\r
+                        {% dl_field collection.physical_items_num %}\r
+                        <dt>{% trans "Number of items" %}</dt><dd>{{ collection.items.count }}</dd>\r
+                        {% dl_field collection.physical_format %}\r
+                        {% dl_field collection.ad_conversion %}\r
                     </dl>\r
                 </div>\r
             </div>\r
-        {% endblock document_data %}\r
+        {% endblock technical_data %}\r
         </div>\r
         <h4>Items</h4>\r
+        {% with collection.items.all as items %}\r
+            {% include "telemeta/inc/mediaitem_list.html" %}\r
+        {% endwith %}\r
+        <!--\r
         {% with collection.ordered_items as items %}\r
             {% include "telemeta/inc/mediaitem_list.html" %}\r
         {% endwith %}\r
+        -->\r
         </div>\r
     </div>\r
 {% endblock %}\r
index 622cec0a9d2a4c436592298ab85f5a6be066556e..0fb014d4fc97d5e335f22d6f16c0da50f1af5ab9 100644 (file)
@@ -3,6 +3,9 @@ from django.utils.http import urlquote
 from telemeta.models import MediaItem, MediaCollection
 from django.core.urlresolvers import reverse
 import telemeta.models.dublincore as dc
+from django.utils import html
+from django import template
+from django.utils.text import capfirst
 
 register = template.Library()
 
@@ -93,3 +96,60 @@ def to_dublincore(resource):
         return dc.express_item(resource)
     else:
         return dc.express_collection(resource)
+
+class DescriptionListFieldNode(template.Node):
+    def __init__(self, variable, join_with = None):
+        cut   = variable.split('.')
+        self.model  = template.Variable('.'.join(cut[:-1]))
+        self.member = cut[-1]
+        self.join_with = join_with
+
+    def render(self, context):
+        try:
+            model = self.model.resolve(context)
+            label = html.escape(capfirst(unicode(model.field_label(self.member))))
+            try:
+                value = getattr(model, self.member)
+            except AttributeError:
+                value = '<ERROR: no such field>'
+        except template.VariableDoesNotExist:
+            label = unicode(self.model) + '.' + self.member
+            value = '<ERROR: can\'t find variable>'
+
+        try:
+            value = value()
+        except TypeError:
+            pass
+        if self.join_with:
+            value = self.join_with.join([unicode(v) for v in value])
+        if value:
+            value = html.escape(unicode(value))
+            markup  = '<dt>%s</dt><dd>%s</dd>' % (label, value)
+            return markup
+
+        return ''
+
+@register.tag
+def dl_field(parser, token):
+    cut = token.split_contents()
+    join_with = None
+    try:
+        tag_name, variable = cut
+    except ValueError:
+        try:
+            tag_name, variable, arg3, arg4, arg5  = cut
+            if arg3 == 'join' and arg4 == 'with'and arg5[0] == arg5[-1] and arg5[0] in ('"', "'"):
+                join_with = arg5[1:-1]
+            else:
+                raise ValueError()
+        except ValueError:
+            raise template.TemplateSyntaxError("%r tag: invalid arguments" 
+                                               % token.contents.split()[0])
+
+    return DescriptionListFieldNode(variable, join_with=join_with)
+
+@register.filter
+def prepend(str, prefix):
+    if str:
+        return prefix + unicode(str)
+    return ''