source: telemeta/models.py @ 01bf9f7

cremcrem2crem3devdev2diademsdj1.6feature/breadcrumbsfeature/ts-0.5feature/ts-0.5.4feature/writecacheformagenericinstru_searchlamlam2mapsv3mergenlivemultiprobproductionrelease/1.4.4sabiodsearchsecurityserversocialstoragetelecastertestvideo
Last change on this file since 01bf9f7 was 01bf9f7, checked in by olivier <>, 8 years ago
  • add dublin core modelization and new to_dublincore() model methods
  • improved dublin core mapping
  • add dublin core HTML-based views of collections and items
  • fixed URL handling with non aplhanumeric record IDs
  • fix #21: the web view now properly handle export streams
  • turn the model list() method into the tolist template filter
  • new submenu template block + css fixes
  • Property mode set to 100644
File size: 9.8 KB
Line 
1# Copyright (C) 2007 Samalyse SARL
2# All rights reserved.
3#
4# This software is licensed as described in the file COPYING, which
5# you should have received as part of this distribution. The terms
6# are also available at http://svn.parisson.org/telemeta/TelemetaLicense.
7#
8# Author: Olivier Guilyardi <olivier@samalyse.com>
9
10import telemeta
11from django.db import models
12from django.db.models import Q
13from telemeta.core import *
14from django.core.exceptions import ObjectDoesNotExist
15from telemeta import dublincore as dc
16
17class MediaModel(Component):
18    pass
19
20class MediaCore:
21    def to_dict(self): 
22        "Return model fields as a dict of name/value pairs"
23        fields_dict = {}
24        for field in self._meta.fields:
25            fields_dict[field.name] = getattr(self, field.name)
26        return fields_dict
27
28#    def dc_elements(self):       
29#        """Return model fields mapped to Dublin Core elements, as a dict of
30#        the form: {dc_element_name: [value1, value2, ....], ...}
31#        """
32#        fields_dict = {}
33#        for field in self._meta.fields:
34#            if (hasattr(field, 'dc_element')):
35#                if fields_dict.has_key(field.dc_element):
36#                    fields_dict[field.dc_element].append(getattr(self, field.name))
37#                else:
38#                    fields_dict[field.dc_element] = [getattr(self, field.name)]
39#                   
40#        return fields_dict
41
42class PhysicalFormat(models.Model):
43    value = models.CharField(maxlength=250)
44    is_dictionary = True
45    def __str__(self):
46        return self.value
47    class Meta:
48        ordering = ['value']
49       
50class MediaCollectionManager(models.Manager):
51    def quick_search(self, pattern):
52        return super(MediaCollectionManager, self).get_query_set().filter(
53            Q(id__icontains=pattern) |
54            Q(title__icontains=pattern) |
55            Q(creator__icontains=pattern)
56        )
57
58
59class MediaCollection(models.Model, MediaCore):
60    "Group related media items"
61
62    publisher_reference = models.CharField(maxlength=250, blank=True)
63    physical_format = models.CharField(maxlength=250, blank=True)
64    id = models.CharField(maxlength=250, primary_key=True, 
65        verbose_name='identifier')
66    title = models.CharField(maxlength=250)
67    native_title = models.CharField(maxlength=250, blank=True)
68    physical_items_num = models.CharField(maxlength=250, blank=True) 
69    publishing_status = models.CharField(maxlength=250, blank=True)
70    is_original = models.CharField(maxlength=250)
71    is_full_copy = models.CharField(maxlength=250)
72    copied_from = models.ForeignKey('self', null=True, blank=True)
73    creator = models.CharField(maxlength=250)
74    booklet_writer = models.CharField(maxlength=250, blank=True)
75    booklet_description = models.TextField(blank=True)
76    collector = models.CharField(maxlength=250, blank=True)
77    publisher = models.CharField(maxlength=250, blank=True)
78    date_published = models.CharField(maxlength=250, blank=True)
79    publisher_collection = models.CharField(maxlength=250, blank=True)
80    publisher_serial_id = models.CharField(maxlength=250, blank=True)
81    ref_biblio = models.TextField(blank=True)
82    acquisition_mode = models.CharField(maxlength=250, blank=True)
83    comment = models.TextField(blank=True)
84    record_author = models.CharField(maxlength=250, blank=True)
85    record_writer = models.CharField(maxlength=250, blank=True)
86    rights = models.CharField(maxlength=250, blank=True)
87    annee_enr = models.CharField(maxlength=250, blank=True)
88    terrain_ou_autre = models.CharField(maxlength=250, blank=True)
89    duree_approx = models.CharField(maxlength=250, blank=True)
90    tri_dibm = models.CharField(maxlength=250, blank=True)
91    travail = models.CharField(maxlength=250, blank=True)
92    compil_face_plage = models.TextField(blank=True)
93    deposant_cnrs = models.CharField(maxlength=250, blank=True)
94    fiches = models.CharField(maxlength=250, blank=True)
95    a_informer = models.CharField(maxlength=250, blank=True)
96    numerisation = models.CharField(maxlength=250, blank=True)
97    champ36 = models.CharField(maxlength=250, blank=True)
98     
99    objects = MediaCollectionManager()
100
101    def to_dublincore(self):
102        if (self.date_published):
103            date = self.date_published
104        else:
105            date = self.annee_enr
106
107        if (self.copied_from):
108            copied_from = self.copied_from.id
109        else:
110            copied_from = ''
111
112        resource = dc.Resource(
113            dc.Element('identifier','id', self.id),
114            dc.Element('type', value='Collection'),
115            dc.Element('title', 'title', self.title),
116            dc.Element('title', 'native_title', self.native_title),
117            dc.Element('creator', 'creator', self.creator),
118            dc.Element('relation', 'copied_from', copied_from, 
119                'isVersionOf'),
120            dc.Element('contributor', 'booklet_writer', self.booklet_writer),
121            dc.Element('contributor', 'collector', self.collector),
122            dc.Element('publisher', 'publisher', self.publisher),
123            dc.Element('date', value=date),
124            dc.Element('rights', 'rights', self.rights),
125        )
126        return resource
127
128    def __str__(self):
129        #return self.title
130        return self.id
131
132    class Meta:
133        ordering = ['title']
134        db_table = 'telemeta_collection'
135
136    class Admin:
137        pass
138
139class MediaItemManager(models.Manager):
140    def quick_search(self, pattern):
141        return super(MediaItemManager, self).get_query_set().filter(
142            Q(id__icontains=pattern) |
143            Q(_title__icontains=pattern) 
144        )
145
146class MediaItem(models.Model, MediaCore):
147    "Describe a item with metadata" 
148
149    ref = models.CharField(maxlength=250, blank=True)
150    format = models.CharField(maxlength=250, blank=True)
151    collection = models.ForeignKey(MediaCollection, related_name="items")
152    face_plage = models.CharField(maxlength=250, blank=True)
153    id = models.CharField(maxlength=250, primary_key=True, 
154        verbose_name='identifier')
155    duree = models.CharField(maxlength=250, blank=True)
156    dates_enregistr = models.CharField(maxlength=250, blank=True)
157    etat = models.CharField(maxlength=250, blank=True)
158    region_village = models.CharField(maxlength=250, blank=True)
159    ethnie_grsocial = models.CharField(maxlength=250, blank=True)
160    titre_support = models.CharField(maxlength=250, blank=True)
161    _title = models.CharField(maxlength=250, db_column='title')
162    transcrip_trad = models.CharField(maxlength=250, blank=True)
163    auteur = models.CharField(maxlength=250, blank=True)
164    form_genr_style = models.CharField(maxlength=250, blank=True)
165    struct_modale = models.CharField(maxlength=250, blank=True)
166    struct_rythm = models.CharField(maxlength=250, blank=True)
167    comm_fonctusage = models.TextField(blank=True)
168    documentation = models.TextField(maxlength=250, blank=True)
169    remarques = models.TextField(maxlength=250, blank=True)
170    moda_execut = models.CharField(maxlength=250, blank=True)
171    copie_de = models.CharField(maxlength=250, blank=True)
172    enregistre_par = models.CharField(maxlength=250, blank=True)
173    aire_geo_cult = models.CharField(maxlength=250, blank=True)
174    annee_enreg = models.CharField(maxlength=250, blank=True)
175    formstyl_generi = models.CharField(maxlength=250, blank=True)
176    choixcollecteur = models.CharField(maxlength=250, blank=True)
177    repere_bande = models.CharField(maxlength=250, blank=True)
178    nroband_nropiec = models.CharField(maxlength=250, blank=True)
179    continent = models.CharField(maxlength=250, blank=True)
180    file = models.FileField(upload_to='items/%Y/%m/%d', blank=True)
181
182    objects = MediaItemManager()
183
184    def _get_title(self):
185        if self._title == "":
186            try:
187                title = self.collection.title + " - Face/Plage: " \
188                    + self.face_plage
189            except ObjectDoesNotExist:
190                title = self.id
191        else:
192            title = self._title
193
194        return title
195    title = property(_get_title)       
196
197    def to_dublincore(self):
198        if self.auteur:
199            creator = self.auteur
200        else: 
201            creator = self.collection.creator
202
203        resource = dc.Resource(
204            dc.Element('identifier','id', self.id),
205            dc.Element('type', value='Sound'),
206            dc.Element('relation', 'collection', self.collection.id, 'isPartOf'),
207            dc.Element('title', 'title', self.title),
208            dc.Element('creator', value=creator),
209            dc.Element('publisher', value=self.collection.publisher),
210        )
211        return resource
212
213    def __str__(self):
214        return self.title
215
216    class Admin:
217        pass
218
219    class Meta:
220        ordering = ['_title']
221        db_table = 'telemeta_item'
222
223
224class MediaPart(models.Model, MediaCore):
225    "Describe the part of a media item"
226
227    contributor = models.CharField(maxlength=250)
228    coverage = models.CharField(maxlength=250)
229    creator = models.CharField(maxlength=250)
230    date = models.DateField()
231    description = models.CharField(maxlength=250)
232    format = models.CharField(maxlength=250)
233    identifier = models.CharField(maxlength=250)
234    language = models.CharField(maxlength=250)
235    publisher = models.CharField(maxlength=250)
236    rights = models.CharField(maxlength=250)
237    source = models.CharField(maxlength=250)
238    subject = models.CharField(maxlength=250)
239    title = models.CharField(maxlength=250)
240    media_item = models.ForeignKey(MediaItem)
241    media_item.dublin_core = 'relation'
242    parent = models.ForeignKey('self', null=True, related_name='children')
243    media_item.dublin_core = 'relation'
244    start = models.FloatField(max_digits=11, decimal_places=3)
245    end = models.FloatField(max_digits=11, decimal_places=3)
246
247    def __str__(self):
248        return self.title
249
250    class Meta:
251        ordering = ['title']
252        db_table = 'telemeta_part'
253
254    class Admin:
255        pass
256
Note: See TracBrowser for help on using the repository browser.