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
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))
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
att.file.save(att_name, ContentFile(tempfile.getvalue()))
return att.file.url
+class PdfFormat(EduModulePDFFormat):
+ pass
+
class OrmDocProvider(DocProvider):
def by_slug(self, slug):