source: telemeta/models/system.py @ 0f7c20f

security
Last change on this file since 0f7c20f was 0f7c20f, checked in by yomguy <yomguy@…>, 3 years ago

Merge branch 'master' into security

  • Property mode set to 100644
File size: 5.0 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
44from django.contrib.sessions.models import Session
45
46
47class Revision(ModelCore):
48    "Revision made by user"
49
50    ELEMENT_TYPE_CHOICES = (('collection', 'collection'), ('item', 'item'), ('part', 'part'), ('marker', 'marker'), ('media', 'media'), ('fonds', 'fonds'), ('corpus', 'corpus'))
51    CHANGE_TYPE_CHOICES  = (('import', 'import'), ('create', 'create'), ('update', 'update'), ('delete','delete'))
52
53    element_type         = CharField(_('element type'), choices=ELEMENT_TYPE_CHOICES, max_length=16, required=True)
54    element_id           = IntegerField(_('element identifier'), required=True)
55    change_type          = CharField(_('modification type'), choices=CHANGE_TYPE_CHOICES, max_length=16, required=True)
56    time                 = DateTimeField(_('time'), auto_now_add=True)
57    user                 = ForeignKey(User, db_column='username', related_name="revisions", verbose_name=_('user'))
58
59    @classmethod
60    def touch(cls, element, user):
61        "Create or update a revision"
62        revision = cls(element_type=element.element_type, element_id=element.pk,
63                       user=user, change_type='create')
64        if element.pk:
65            try:
66                element.__class__.objects.get(pk=element.pk)
67            except ObjectDoesNotExist:
68                pass
69            else:
70                revision.change_type = 'update'
71
72        revision.save()
73        return revision
74
75    def __str__(self):
76        return str(self.time) + ' : ' + self.element_type + ' : ' + str(self.element_id)
77
78    class Meta(MetaCore):
79        db_table = 'revisions'
80
81
82class UserProfile(models.Model):
83    "User profile extension"
84
85    user            = ForeignKey(User, unique=True, required=True)
86    institution     = CharField(_('Institution'))
87    department      = CharField(_('Department'))
88    attachment      = CharField(_('attachment'))
89    function        = CharField(_('Function'))
90    address         = TextField(_('Address'))
91    telephone       = CharField(_('Telephone'))
92    expiration_date = DateField(_('Expiration_date'))
93    last_session_key = CharField(blank=True, null=True, max_length=40)
94
95    class Meta(MetaCore):
96        db_table = 'profiles'
97
98
99class Criteria(ModelCore):
100    "Search criteria"
101
102    element_type = 'search_criteria'
103
104    key = CharField(_('key'), required=True)
105    value = CharField(_('value'), required=True)
106
107    class Meta(MetaCore):
108        db_table = 'search_criteria'
109
110
111class Search(ModelCore):
112    "Keywork search"
113
114    element_type = 'search'
115
116    username = ForeignKey(User, related_name="searches", db_column="username")
117    date = DateTimeField(_('date'), auto_now_add=True)
118    description = CharField(_('Description'))
119    criteria = models.ManyToManyField(Criteria, related_name="search",
120                                      verbose_name=_('criteria'), blank=True, null=True)
121
122    class Meta(MetaCore):
123        db_table = 'searches'
124        ordering = ['-date']
125
126    def __unicode__(self):
127        return self.keywords
128
129
130
Note: See TracBrowser for help on using the repository browser.