diff options
author | Guillaume Seguin <guillaume@segu.in> | 2008-08-11 04:36:16 +0200 |
---|---|---|
committer | Guillaume Seguin <guillaume@segu.in> | 2008-08-11 04:36:16 +0200 |
commit | daa8080ff04165fe8fe80cd2f560750fff073fad (patch) | |
tree | 36f7c93964769186d6b7c66a21a84231abb7a508 /main/models.py | |
download | dusu_website-daa8080ff04165fe8fe80cd2f560750fff073fad.tar.gz dusu_website-daa8080ff04165fe8fe80cd2f560750fff073fad.tar.bz2 |
Diffstat (limited to 'main/models.py')
-rw-r--r-- | main/models.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/main/models.py b/main/models.py new file mode 100644 index 0000000..56c05cb --- /dev/null +++ b/main/models.py @@ -0,0 +1,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) |