source: telemeta/models/forma.py @ fb2f1cf

forma
Last change on this file since fb2f1cf was fb2f1cf, checked in by yomguy <yomguy@…>, 3 years ago

add forma, fix item edit

  • Property mode set to 100644
File size: 11.6 KB
Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3"""
4   Forma
5
6   Copyright (c) 2006-2012 Guillaume Pellerin <yomguy@parisson.com>
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# Author: Guillaume Pellerin <yomguy@parisson.com>
35"""
36
37import os
38import re
39import pwd
40import time
41import urllib
42import datetime
43import mimetypes
44import django.db.models as models
45from django.db.models import *
46from django.forms import ModelForm, TextInput, Textarea
47from django.utils.translation import ugettext_lazy as _
48from django.contrib.auth.models import User
49from django.core.exceptions import ValidationError
50from telemeta.fields import *
51from telemeta.models.media import *
52
53app_label = 'forma'
54
55n_sessions = 21
56session_choices = [(str(x), str(y)) for x in range(1, n_sessions) for y in range(1, n_sessions) if x == y]
57
58
59class Organization(Model):
60
61    name            = CharField(_('name'), max_length=255)
62    description     = CharField(_('description'), max_length=255, blank=True)
63
64    def __str__(self):
65        return self.name
66
67    class Meta:
68        db_table = app_label + '_' + 'organization'
69        verbose_name = _('organization')
70
71class Department(Model):
72
73    name            = CharField(_('name'), max_length=255)
74    description     = CharField(_('description'), max_length=255, blank=True)
75    organization    = ForeignKey('Organization', related_name='department', verbose_name=_('organization'))
76
77    def __str__(self):
78        return self.name
79
80    class Meta:
81        db_table = app_label + '_' + 'department'
82        verbose_name = _('department')
83
84
85class Category(Model):
86
87    name            = CharField(_('name'), max_length=255)
88    description     = CharField(_('description'), max_length=255, blank=True)
89
90    def __str__(self):
91        return self.name
92
93    class Meta:
94        db_table = app_label + '_' + 'category'
95        verbose_name = _('category')
96        verbose_name_plural = _('categories')
97
98
99class Course(Model):
100
101    department      = ForeignKey('Department', related_name='course', verbose_name=_('department'))
102    title           = CharField(_('title'), max_length=255)
103    description     = CharField(_('description'), max_length=255, blank=True)
104    category        = ForeignKey('Category', related_name='course', verbose_name=_('category'))
105    public_id       = CharField(_('public_id'), max_length=255, blank=True)
106
107    def __str__(self):
108        return self.department.name + ' - '  + self.category.name + ' - ' + self.title
109
110    class Meta:
111        db_table = app_label + '_' + 'course'
112        verbose_name = _('course')
113
114
115class Professor(Model):
116
117    user            = ForeignKey(User, related_name='professor', verbose_name=_('user'), unique=True)
118    courses         = ManyToManyField('Course', related_name="professor", verbose_name=_('courses'),
119                                        blank=True, null=True)
120
121    def __str__(self):
122        return self.user.username
123
124    class Meta:
125        db_table = app_label + '_' + 'professor'
126        verbose_name = _('professor')
127
128
129class Room(Model):
130
131    organization    = ForeignKey('Organization', related_name='room', verbose_name=_('organization'))
132    name            = CharField(_('name'), max_length=255)
133    description     = CharField(_('description'), max_length=255, blank=True)
134
135    def __str__(self):
136        return self.organization.name + ' - ' + self.name
137
138    class Meta:
139        db_table = app_label + '_' + 'room'
140        verbose_name = _('room')
141
142
143class Conference(Model):
144
145    course          = ForeignKey('Course', related_name='conference', verbose_name=_('course'))
146    professor       = ForeignKey('Professor', related_name='conference', verbose_name=_('professor'))
147    session         = CharField(_('session'), choices=session_choices,
148                                      max_length=16, default="1")
149    room            = ForeignKey('Room', related_name='conference', verbose_name=_('room'),
150                                 null=True, blank=True)
151    comment         = CharField(_('comment'), max_length=255, blank=True)
152    date_begin      = DateTimeField(_('begin date'), null=True, blank=True)
153    date_end        = DateTimeField(_('end date'), null=True, blank=True)
154
155    @property
156    def description(self):
157        return self.course.department.name + ' - ' + self.course.title + ' - ' + \
158                self.professor.user.first_name +  ' - ' + \
159                self.professor.user.last_name +  ' - ' + str(self.date_begin)
160
161    def __str__(self):
162        return self.description
163
164    class Meta:
165        db_table = app_label + '_' + 'conference'
166        verbose_name = _('conference')
167
168
169class MediaBase(Model):
170    "Base media resource"
171
172    credits         = CharField(_('credits'), max_length=255, blank=True)
173    is_published    = BooleanField(_('published'))
174    date_added      = DateTimeField(_('date added'), auto_now_add=True)
175    date_modified   = DateTimeField(_('date modified'), auto_now=True)
176
177    def get_fields(self):
178        return self._meta.fields
179
180    class Meta:
181        abstract = True
182        ordering = ['date_added']
183
184
185class Document(MediaBase):
186
187    element_type = 'document'
188
189    title           = CharField(_('title'), max_length=255, blank=True)
190    description     = CharField(_('description'), max_length=255, blank=True)
191    code            = CharField(_('code'), max_length=255, blank=True)
192    course          = ForeignKey('Course', related_name='document', verbose_name='course')
193    conference      = ForeignKey('Conference', related_name='document', verbose_name=_('conference'),
194                                 blank=True, null=True)
195    is_annal        = BooleanField(_('annal'))
196    file            = FileField(_('file'), upload_to='items/%Y/%m/%d', db_column="filename", blank=True)
197
198    def is_image(self):
199        is_url_image = False
200        if self.url:
201            url_types = ['.png', '.jpg', '.gif', '.jpeg']
202            for type in url_types:
203                if type in self.url or type.upper() in self.url:
204                    is_url_image = True
205        return 'image' in self.mime_type or is_url_image
206
207    def set_mime_type(self):
208        if self.file:
209            self.mime_type = mimetypes.guess_type(self.file.path)[0]
210
211    def __str__(self):
212        if self.title and not re.match('^ *N *$', self.title):
213            return  self.title
214        else:
215            return  unicode(self.title)
216
217    class Meta:
218        db_table = app_label + '_' + 'document'
219
220
221class Media(MediaBase):
222    "Describe a media resource linked to a conference and a telemeta item"
223
224    element_type = 'media'
225
226    conference      = ForeignKey('Conference', related_name='media', verbose_name=_('conference'))
227    item            = ForeignKey(MediaItem, related_name='media',
228                                 verbose_name='item', blank=True, null=True)
229    is_live         = BooleanField(_('is live'))
230
231    def __unicode__(self):
232        description = self.conference.description
233        if self.item:
234            return description + ' _ ' + self.item.title
235        else:
236            return description
237
238    class Meta:
239        db_table = app_label + '_' + 'media'
240
241
242# STUDENT
243
244class IEJ(Model):
245
246    name            = CharField(_('name'), max_length=255)
247    description     = CharField(_('description'), max_length=255, blank=True)
248
249    def __str__(self):
250        return self.name
251
252    class Meta:
253        db_table = app_label + '_' + 'iej'
254        verbose_name = _('IEJ')
255        verbose_name_plural = _('IEJ')
256
257
258class Training(Model):
259
260    name            = CharField(_('name'), max_length=255, blank=True)
261    courses         = ManyToManyField('Course', related_name="training", verbose_name=_('courses'),
262                                        blank=True, null=True)
263
264    def __str__(self):
265        return self.name
266
267    class Meta:
268        db_table = app_label + '_' + 'training'
269        verbose_name = _('training')
270
271
272class Procedure(Model):
273
274    name           = CharField(_('name'), max_length=255, blank=True)
275
276    def __str__(self):
277        return self.name
278
279    class Meta:
280        db_table = app_label + '_' + 'procedure'
281        verbose_name = _('procedure')
282
283
284class Speciality(Model):
285
286    name           = CharField(_('name'), max_length=255, blank=True)
287
288    def __str__(self):
289        return self.name
290
291    class Meta:
292        db_table = app_label + '_' + 'speciality'
293        verbose_name = _('speciality')
294
295
296class Student(Model):
297
298    user            = ForeignKey(User, related_name='student', verbose_name=_('user'), unique=True )
299    category        = ForeignKey('Category', related_name='student', verbose_name=_('category'))
300    iej             = ForeignKey('IEJ', related_name='student', verbose_name=_('iej'))
301    training        = ForeignKey('Training', related_name='student',
302                                 verbose_name='training', blank=True, null=True)
303    procedure       = ForeignKey('Procedure', related_name='student',
304                                 verbose_name='procedure', blank=True, null=True)
305    oral_speciality = ForeignKey('Speciality', related_name='student_oral_spe',
306                                 verbose_name='oral speciality', blank=True, null=True)
307    written_speciality = ForeignKey('Speciality', related_name='student_written_spe',
308                                verbose_name='written speciality', blank=True, null=True)
309    oral_1          = CharField(_('oral 1'), max_length=255, blank=True)
310    oral_2          = CharField(_('oral 2'), max_length=255, blank=True)
311
312
313    def __str__(self):
314        return self.user.username
315
316    class Meta:
317        db_table = app_label + '_' + 'student'
318        verbose_name = _('student')
319
320
321class Profile(models.Model):
322    "User profile extension"
323
324    user            = ForeignKey(User, related_name='profile', verbose_name=_('user'), unique=True)
325    address         = TextField(_('Address'))
326    postal_code     = CharField(_('Postal code'), max_length=255)
327    city            = CharField(_('City'), max_length=255)
328    country         = CharField(_('Country'), max_length=255, blank=True)
329    language        = CharField(_('Language'), max_length=255, blank=True)
330    telephone       = CharField(_('Telephone'), max_length=255, blank=True)
331    expiration_date = DateField(_('Expiration_date'), blank=True, null=True)
332    init_password   = BooleanField(_('Password initialization'))
333
334    class Meta:
335        db_table = app_label + '_' + 'profiles'
336        verbose_name = _('profile')
337
Note: See TracBrowser for help on using the repository browser.