From 698b793845a58fcac88a2bd40a8b93d018549931 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 14 Feb 2013 17:00:09 +0100 Subject: [PATCH] build pdf --- catalogue/models.py | 18 ++++++++++++++++++ catalogue/publish.py | 4 ++++ requirements.txt | 1 + 3 files changed, 23 insertions(+) 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 -- 2.20.1