+class EduModuleFormat(Format):
+ PRIMARY_MATERIAL_FORMATS = ('pdf', 'odt')
+
+ class MaterialNotFound(BaseException):
+ pass
+
+ def __init__(self, wldoc, **kwargs):
+ super(EduModuleFormat, self).__init__(wldoc, **kwargs)
+
+ def build(self):
+ # Sort materials by slug.
+ self.materials_by_slug = {}
+ for name, att in self.wldoc.source.attachments.items():
+ parts = name.rsplit('.', 1)
+ if len(parts) == 1:
+ continue
+ slug, ext = parts
+ if slug not in self.materials_by_slug:
+ self.materials_by_slug[slug] = {}
+ self.materials_by_slug[slug][ext] = att
+
+ edumod = EduModule({'provider': self.wldoc.provider, 'urlmapper': self, 'wldoc': self.wldoc})
+
+ html = edumod.generate(self.wldoc.edoc.getroot())
+
+ return IOFile.from_string(html.encode('utf-8'))
+
+ def materials(self, slug):
+ """Returns a list of pairs: (ext, iofile)."""
+ order = dict(reversed(k) for k in enumerate(self.PRIMARY_MATERIAL_FORMATS))
+ mats = self.materials_by_slug.get(slug, {}).items()
+ if not mats:
+ pass # print "!! Material missing: '%s'" % slug
+ return sorted(mats, key=lambda (x, y): order.get(x, x))
+
+ def url_for_material(self, slug, fmt):
+ return "%s.%s" % (slug, fmt)
+
+