build pdf
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 14 Feb 2013 16:00:09 +0000 (17:00 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 14 Feb 2013 16:00:09 +0000 (17:00 +0100)
catalogue/models.py
catalogue/publish.py
requirements.txt

index f05688d..6e615a8 100644 (file)
@@ -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))
index f79a809..9f79dae 100755 (executable)
@@ -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):
index 32f519f..ea7ea79 100644 (file)
@@ -17,6 +17,7 @@ Feedparser
 
 # Librarian
 lxml
+texml
 
 # sponsors
 pillow