X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/f8b34544329e05b7c27990ffe9c241df877cd95c..cf61eb00421c5f6bb1b530e1d499815bc266faac:/catalogue/models.py diff --git a/catalogue/models.py b/catalogue/models.py index b42a463..c684ab5 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -121,6 +121,8 @@ class Lesson(models.Model): lesson.level = Level.objects.get(slug=wldoc.book_info.audience) 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) return lesson @@ -144,23 +146,44 @@ class Lesson(models.Model): def build_html(self, infile=None): from librarian.parser import WLDocument - from .publish import HtmlFormat + from .publish import HtmlFormat, OrmDocProvider if infile is None: - wldoc = WLDocument.from_file(self.xml_file.path) + wldoc = WLDocument.from_file(self.xml_file.path, provider=OrmDocProvider) else: - wldoc = WLDocument(infile) + wldoc = WLDocument(infile, provider=OrmDocProvider()) html = HtmlFormat(wldoc).build() self.html_file.save("%s.html" % self.slug, File(open(html.get_filename()))) + def build_pdf(self, student=False, infile=None): + from librarian.parser import WLDocument + from .publish import PdfFormat, OrmDocProvider + + if infile is None: + wldoc = WLDocument.from_file(self.xml_file.path, provider=OrmDocProvider) + else: + wldoc = WLDocument(infile, provider=OrmDocProvider()) + if student: + pdf = PdfFormat(wldoc).build() + self.student_pdf.save("%s.pdf" % self.slug, + File(open(pdf.get_filename()))) + else: + pdf = PdfFormat(wldoc, teacher=True).build() + self.pdf.save("%s.pdf" % self.slug, + 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(self.xml_file.path, + 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)) + def build_package(self, student=False):