+ try:
+ # If already saved, use it.
+ att = Attachment.objects.get(lesson__slug=lesson_slug,
+ slug=slug, ext=fmt)
+ except Attachment.DoesNotExist, e:
+ # If attached to source IOFile, save now.
+ att_name = "%s.%s" % (slug, fmt)
+ try:
+ att_file = self.wldoc.source.attachments[att_name]
+ except KeyError:
+ print u"ATTACHMENT MISSING:", att_name
+ raise self.MaterialNotFound()
+ else:
+ lesson = Lesson.objects.get(slug=lesson_slug)
+ att = lesson.attachment_set.create(slug=slug, ext=fmt)
+ att.file.save(att_name, File(att_file.get_file()))
+ return att
+ else:
+ return att
+
+ def url_for_material(self, slug, fmt):
+ return self.find_attachment(slug, fmt).file.url
+
+ def url_for_image(self, slug, fmt, width=None):
+ try:
+ src_img = self.find_attachment(slug, fmt).file
+ except self.MaterialNotFound:
+ return ''
+ img = get_image(src_img.path, width, self.DEFAULT_IMAGE_WIDTH, self.IMAGE_FORMATS)
+ return (img or src_img).url
+
+ def text_to_anchor(self, text):
+ return slughifi(text)
+
+ def get_forma_url(self, forma):
+ return '%s#%s' % (
+ reverse('catalogue_lesson', args=['metody']),
+ self.text_to_anchor(forma)
+ )
+
+ def get_help_url(self, naglowek):
+ return '%s%s#%s' % (
+ '//edukacjamedialna.edu.pl',
+ reverse('info', args=['jak-korzystac/']),
+ self.naglowek_to_anchor(naglowek)
+ )
+
+
+class PdfFormat(EduModulePDFFormat):
+ IMAGE_FORMATS = ('PNG', 'JPEG', 'GIF')
+ DEFAULT_IMAGE_WIDTH = 1600