X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/4e8f2e48704705b61bd674497aaaf33ef9f1c90b..a87786b8abce90bf32e1950b7fe2ea41ccf52ad5:/catalogue/models.py diff --git a/catalogue/models.py b/catalogue/models.py index e20d58c..239f60c 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -11,6 +11,8 @@ class Section(models.Model): order = models.IntegerField() xml_file = models.FileField(upload_to="catalogue/section/xml", null=True, blank=True, max_length=255) + image = models.ImageField(upload_to="catalogue/section/image", + null=True, blank=True) class Meta: ordering = ['order'] @@ -71,7 +73,7 @@ class Lesson(models.Model): type = models.CharField(max_length=15, db_index=True) order = models.IntegerField(db_index=True) dc = JSONField(default='{}') - curriculum_courses = models.ManyToManyField(CurriculumCourse) + curriculum_courses = models.ManyToManyField(CurriculumCourse, blank=True) xml_file = models.FileField(upload_to="catalogue/lesson/xml", null=True, blank=True, max_length=255) @@ -122,9 +124,10 @@ class Lesson(models.Model): lesson.populate_dc() lesson.build_html(infile=infile) lesson.build_pdf(infile=infile) - lesson.build_pdf(student=True, infile=infile) lesson.build_package() - lesson.build_package(student=True) + if lesson.type != 'project': + lesson.build_pdf(student=True, infile=infile) + lesson.build_package(student=True) return lesson def populate_dc(self): @@ -176,17 +179,15 @@ class Lesson(models.Model): File(open(pdf.get_filename()))) def add_to_zip(self, zipf, student=False, prefix=''): - zipf.write(self.xml_file.path, - "%spliki-zrodlowe/%s.xml" % (prefix, self.slug)) pdf = self.student_pdf if student else self.pdf if pdf: zipf.write(pdf.path, "%s%s%s.pdf" % (prefix, self.slug, "_student" if student else "")) - for attachment in self.attachment_set.all(): - zipf.write(attachment.file.path, - u"%smaterialy/%s.%s" % (prefix, attachment.slug, attachment.ext)) - - + for attachment in self.attachment_set.all(): + zipf.write(attachment.file.path, + u"%smaterialy/%s.%s" % (prefix, attachment.slug, attachment.ext)) + zipf.write(self.xml_file.path, + "%spliki-zrodlowe/%s.xml" % (prefix, self.slug)) def build_package(self, student=False): from StringIO import StringIO @@ -202,8 +203,15 @@ class Lesson(models.Model): ContentFile(buff.getvalue())) def get_syntetic(self): + if self.section is None: return None return self.section.syntetic_lesson(self.level) + def get_other_level(self): + if self.section is None: return None + other_levels = self.section.lesson_set.exclude(level=self.level) + if other_levels.exists(): + return other_levels[0].level + def get_previous(self): if self.section is None: return None try: @@ -243,3 +251,17 @@ class Part(models.Model): null=True, blank=True) student_pdf = models.FileField(upload_to="catalogue/part/student_pdf", null=True, blank=True) + + +class LessonStub(models.Model): + section = models.ForeignKey(Section, null=True, blank=True) + level = models.ForeignKey(Level) + title = models.CharField(max_length=255) + type = models.CharField(max_length=15, db_index=True) + order = models.IntegerField(db_index=True) + + class Meta: + ordering = ['section', 'level', 'order'] + + def __unicode__(self): + return self.title