From: Radek Czajka Date: Thu, 14 Feb 2013 16:00:09 +0000 (+0100) Subject: build pdf X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/698b793845a58fcac88a2bd40a8b93d018549931?hp=ecc9959eb6ce63d64b20423e324b772a4a55e5bc build pdf --- diff --git a/catalogue/models.py b/catalogue/models.py index f05688d..6e615a8 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 @@ -154,6 +156,22 @@ class Lesson(models.Model): 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()) + pdf = PdfFormat(wldoc).build() + if student: + self.student_pdf.save("%s.pdf" % self.slug, + File(open(pdf.get_filename()))) + else: + 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)) diff --git a/catalogue/publish.py b/catalogue/publish.py index f79a809..9f79dae 100755 --- a/catalogue/publish.py +++ b/catalogue/publish.py @@ -3,6 +3,7 @@ from django.core.files.base import ContentFile from django.core.files import File from librarian import DocProvider, IOFile from librarian.pyhtml import EduModuleFormat +from librarian.pypdf import EduModulePDFFormat from .models import Lesson, Attachment @@ -60,6 +61,9 @@ class HtmlFormat(EduModuleFormat): att.file.save(att_name, ContentFile(tempfile.getvalue())) return att.file.url +class PdfFormat(EduModulePDFFormat): + pass + class OrmDocProvider(DocProvider): def by_slug(self, slug): diff --git a/requirements.txt b/requirements.txt index 32f519f..ea7ea79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ Feedparser # Librarian lxml +texml # sponsors pillow