1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# coding: utf8
'''
Copyright (C) 2008 Guillaume Seguin <guillaume@segu.in>
This application is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this application. If not, see <http://www.gnu.org/licenses/>.
'''
from django.db import models
from django.utils.encoding import smart_str
from django.contrib import admin
from django.core.files.storage import FileSystemStorage
from os.path import join, abspath
import dusu_website.settings as settings
class Page (models.Model):
'''Page object'''
TEMPLATE_CHOICES= (
("simple_page.html", "Page simple"),
("raw_page.html", "Page simple (html brut)"),
("file_page.html", "Page des fichiers"),
("calendar_page.html", "Page du planning")
)
position = models.IntegerField ("Position de la page")
enabled = models.BooleanField ("Activée")
name = models.CharField ("Nom interne de la page", max_length = 100)
title = models.CharField ("Titre de la page", max_length = 200)
template = models.CharField ("Nom du modèle", max_length = 100,
default = "simple_page.html",
choices = TEMPLATE_CHOICES)
content = models.TextField ("Contenu de la page")
def __str__ (self):
return smart_str (self.title)
class PageAdmin (admin.ModelAdmin):
ordering = ("position",)
fs = FileSystemStorage (location = settings.FILES_ROOT)
def make_file_path (instance, filename):
'''Build storage path for given file'''
return "%s%s/%s" % (settings.FILES_ROOT, instance.type, filename)
class File (models.Model):
'''File object'''
TYPE_CHOICES = (
("td", "TDs"),
("tp", "TPs"),
("poly", "Polys"),
("colle", "Programme de colles"),
)
type = models.CharField ("Type de fichier", max_length = 5,
choices = TYPE_CHOICES)
position = models.IntegerField ("Position du fichier")
published = models.BooleanField ("Publié")
name = models.CharField ("Nom du fichier", max_length = 200)
mainfile = models.FileField ("Fichier", max_length = 200,
upload_to = make_file_path, storage = fs)
solution = models.FileField ("Corrigé", max_length = 200,
upload_to = make_file_path, storage = fs)
def __str__ (self):
return smart_str ("%s - %s" % (self.get_type_display (), self.name))
class FileAdmin (admin.ModelAdmin):
ordering = ("position",)
class Test (models.Model):
'''Test object for calendar'''
number = models.IntegerField ("Numéro du DS")
date = models.DateField ("Date du DS")
class Meta:
verbose_name = "DS"
def __str__ (self):
return smart_str ("DS %s - %s" % (self.number, self.date))
class TestAdmin (admin.ModelAdmin):
ordering = ("number",)
admin.site.register (Page, PageAdmin)
admin.site.register (File, FileAdmin)
admin.site.register (Test, TestAdmin)
|