+ 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())
+ 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 add_to_zip(self, zipf, student=False, prefix=''):
+ zipf.write(self.xml_file.path,
+ "%spliki-zrodlowe/%s.xml" % (prefix, self.slug))
+ 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))
+
+
+