+ from .publish import OrmDocProvider
+
+ if infile is None:
+ infile = IOFile.from_filename(self.xml_file.path)
+ for att in self.attachment_set.all():
+ infile.attachments["%s.%s" % (att.slug, att.ext)] = \
+ IOFile.from_filename(att.file.path)
+ return WLDocument(infile, provider=OrmDocProvider())
+
+ def build_html(self, infile=None):
+ from .publish import HtmlFormat
+ wldoc = self.wldocument(infile)
+ html = HtmlFormat(wldoc).build()
+ self.html_file.save("%s.html" % self.slug, File(open(html.get_filename())))
+
+ def build_pdf(self, student=False):
+ from .publish import PdfFormat
+ # PDF uses document with attachments already saved as media,
+ # otherwise sorl.thumbnail complains about SuspiciousOperations.
+ wldoc = self.wldocument()
+ 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 build_pdf_from_html(self, **kwargs):
+ from .publish import PdfFromHtmlFormat
+ wldoc = self.wldocument()
+ pdf = PdfFromHtmlFormat(
+ wldoc, media_root=settings.MEDIA_ROOT,
+ html_to_pdf_command=settings.HTML_TO_PDF_COMMAND,
+ **kwargs).build()
+ self.weasy_pdf.save("%s.pdf" % self.slug, File(open(pdf.get_filename())))
+
+ def add_to_zip(self, zipf, student=False, prefix=''):
+ pdf = self.student_pdf if student else self.pdf
+ if pdf:
+ 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))
+ zipf.write(self.xml_file.path, "%spliki-zrodlowe/%s.xml" % (prefix, self.slug))