X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/ea300f6c03d47f6c17dd7721b8d6690489af79da..d8e360fe85b5f15df034d87f123f781f071d49a1:/catalogue/models.py diff --git a/catalogue/models.py b/catalogue/models.py index 4af4810..85f0af0 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -3,9 +3,11 @@ from django.core.files import File from django.core.urlresolvers import reverse from django.db import models from jsonfield import JSONField +from fnpdjango.storage import BofhFileSystemStorage from curriculum.models import Level, Curriculum, CurriculumCourse import logging +bofh_storage = BofhFileSystemStorage() class Section(models.Model): @@ -13,7 +15,8 @@ class Section(models.Model): slug = models.SlugField(max_length=255, unique=True) order = models.IntegerField() xml_file = models.FileField(upload_to="catalogue/section/xml", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, + storage=bofh_storage) image = models.ImageField(upload_to="catalogue/section/image", null=True, blank=True) @@ -88,17 +91,17 @@ class Lesson(models.Model): description = models.TextField(null=True, blank=True) xml_file = models.FileField(upload_to="catalogue/lesson/xml", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) html_file = models.FileField(upload_to="catalogue/lesson/html", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) package = models.FileField(upload_to="catalogue/lesson/pack", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) student_package = models.FileField(upload_to="catalogue/lesson/student_pack", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) pdf = models.FileField(upload_to="catalogue/lesson/pdf", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) student_pdf = models.FileField(upload_to="catalogue/lesson/student_pdf", - null=True, blank=True, max_length=255) + null=True, blank=True, max_length=255, storage=bofh_storage) class Meta: ordering = ['section', 'level', 'order'] @@ -148,7 +151,7 @@ class Lesson(models.Model): wldoc = WLDocument.from_file(self.xml_file.path) self.dc = wldoc.book_info.to_dict() self.type = self.dc["type"] - assert self.type in ('appendix', 'course', 'synthetic', 'project'), \ + assert self.type in ('appendix', 'course', 'synthetic', 'project', 'added', 'added-var'), \ u"Unknown lesson type: %s" % self.type self.save() @@ -168,10 +171,14 @@ class Lesson(models.Model): def populate_description(self, wldoc=None, infile=None): if wldoc is None: wldoc = self.wldocument(infile) - for nagl in wldoc.edoc.findall('.//naglowek_rozdzial'): - if (nagl.text or '').strip() == u'Pomysł na lekcję': + if self.type == 'project': + lookup = u'Zadanie' + else: + lookup = u'Pomysł na lekcję' + for header in wldoc.edoc.findall('.//naglowek_rozdzial'): + if (header.text or '').strip() == lookup: from lxml import etree - self.description = etree.tostring(nagl.getnext(), + self.description = etree.tostring(header.getnext(), method='text', encoding='unicode').strip() self.save() return @@ -269,7 +276,7 @@ class Attachment(models.Model): slug = models.CharField(max_length=255) ext = models.CharField(max_length=15) lesson = models.ForeignKey(Lesson) - file = models.FileField(upload_to="catalogue/attachment") + file = models.FileField(upload_to="catalogue/attachment", storage=bofh_storage) class Meta: ordering = ['slug', 'ext']