source: telemeta/models/system.py @ fad4d14

cremcrem2devdev2diademsfeature/breadcrumbsfeature/ts-0.5feature/ts-0.5.4feature/writecachegenericinstru_searchlamlam2mapsv3mergenlivemultiproductionrelease/1.4.4sabiodsecurityserversocialstoragetelecastertest
Last change on this file since fad4d14 was fad4d14, checked in by yomguy <yomguy@…>, 2 years ago

readd profile properties

  • Property mode set to 100644
File size: 4.9 KB
Line 
1# -*- coding: utf-8 -*-
2# Copyright (C) 2007-2010 Samalyse SARL
3# Copyright (C) 2010-2011 Parisson SARL
4
5# This software is a computer program whose purpose is to backup, analyse,
6# transcode and stream any audio content with its metadata over a web frontend.
7
8# This software is governed by the CeCILL  license under French law and
9# abiding by the rules of distribution of free software.  You can  use,
10# modify and/ or redistribute the software under the terms of the CeCILL
11# license as circulated by CEA, CNRS and INRIA at the following URL
12# "http://www.cecill.info".
13
14# As a counterpart to the access to the source code and  rights to copy,
15# modify and redistribute granted by the license, users are provided only
16# with a limited warranty  and the software's author,  the holder of the
17# economic rights,  and the successive licensors  have only  limited
18# liability.
19
20# In this respect, the user's attention is drawn to the risks associated
21# with loading,  using,  modifying and/or developing or reproducing the
22# software by the user in light of its specific status of free software,
23# that may mean  that it is complicated to manipulate,  and  that  also
24# therefore means  that it is reserved for developers  and  experienced
25# professionals having in-depth computer knowledge. Users are therefore
26# encouraged to load and test the software's suitability as regards their
27# requirements in conditions enabling the security of their systems and/or
28# data to be ensured and,  more generally, to use and operate it in the
29# same conditions as regards security.
30
31# The fact that you are presently reading this means that you have had
32# knowledge of the CeCILL license and that you accept its terms.
33#
34# Authors: Olivier Guilyardi <olivier@samalyse.com>
35#          David LIPSZYC <davidlipszyc@gmail.com>
36#          Guillaume Pellerin <yomguy@parisson.com>
37
38from django.contrib.auth.models import User
39from telemeta.models.core import *
40from django.core.exceptions import ObjectDoesNotExist
41from django.utils.translation import ugettext_lazy as _
42import django.db.models as models
43from django.forms import ModelForm
44
45
46class Revision(ModelCore):
47    "Revision made by user"
48
49    ELEMENT_TYPE_CHOICES = (('collection', 'collection'), ('item', 'item'), ('part', 'part'), ('marker', 'marker'), ('media', 'media'), ('fonds', 'fonds'), ('corpus', 'corpus'))
50    CHANGE_TYPE_CHOICES  = (('import', 'import'), ('create', 'create'), ('update', 'update'), ('delete','delete'))
51
52    element_type         = CharField(_('element type'), choices=ELEMENT_TYPE_CHOICES, max_length=16, required=True)
53    element_id           = IntegerField(_('element identifier'), required=True)
54    change_type          = CharField(_('modification type'), choices=CHANGE_TYPE_CHOICES, max_length=16, required=True)
55    time                 = DateTimeField(_('time'), auto_now_add=True)
56    user                 = ForeignKey(User, db_column='username', related_name="revisions", verbose_name=_('user'))
57
58    @classmethod
59    def touch(cls, element, user):
60        "Create or update a revision"
61        revision = cls(element_type=element.element_type, element_id=element.pk,
62                       user=user, change_type='create')
63        if element.pk:
64            try:
65                element.__class__.objects.get(pk=element.pk)
66            except ObjectDoesNotExist:
67                pass
68            else:
69                revision.change_type = 'update'
70
71        revision.save()
72        return revision
73
74    def __str__(self):
75        return str(self.time) + ' : ' + self.element_type + ' : ' + str(self.element_id)
76
77    class Meta(MetaCore):
78        db_table = 'revisions'
79
80
81class UserProfile(models.Model):
82    "User profile extension"
83
84    user            = ForeignKey(User, unique=True, required=True)
85    institution     = CharField(_('Institution'))
86    department      = CharField(_('Department'))
87    attachment      = CharField(_('attachment'))
88    function        = CharField(_('Function'))
89    address         = TextField(_('Address'))
90    telephone       = CharField(_('Telephone'))
91    expiration_date = DateField(_('Expiration_date'))
92
93    class Meta(MetaCore):
94        db_table = 'profiles'
95
96
97class Criteria(ModelCore):
98    "Search criteria"
99
100    element_type = 'search_criteria'
101
102    key = CharField(_('key'), required=True)
103    value = CharField(_('value'), required=True)
104
105    class Meta(MetaCore):
106        db_table = 'search_criteria'
107
108
109class Search(ModelCore):
110    "Keywork search"
111
112    element_type = 'search'
113
114    username = ForeignKey(User, related_name="searches", db_column="username")
115    date = DateTimeField(_('date'), auto_now_add=True)
116    description = CharField(_('Description'))
117    criteria = models.ManyToManyField(Criteria, related_name="search",
118                                      verbose_name=_('criteria'), blank=True, null=True)
119
120    class Meta(MetaCore):
121        db_table = 'searches'
122        ordering = ['-date']
123
124    def __unicode__(self):
125        return self.keywords
126
127
128
Note: See TracBrowser for help on using the repository browser.