+class EduModuleFormat(Format):
+ PRIMARY_MATERIAL_FORMATS = ('pdf', 'odt')
+
+ class MaterialNotFound(BaseException):
+ pass
+
+ def __init__(self, wldoc, **kwargs):
+ super(EduModuleFormat, self).__init__(wldoc, **kwargs)
+ self.materials_by_slug = None
+
+ 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 = {pmf: i for (i, pmf) in enumerate(self.PRIMARY_MATERIAL_FORMATS)}
+ mats = self.materials_by_slug.get(slug, {}).items()
+ if not mats:
+ print ("!! Material missing: '%s'" % slug).encode('utf-8')
+ return sorted(mats, key=lambda (x, y): order.get(x, x))
+
+ def url_for_material(self, slug, fmt):
+ return "%s.%s" % (slug, fmt)
+
+ # WTF: tutaj był błąd, ale nikomu to nie przeszkadzało?
+ def url_for_image(self, slug, fmt, width=None):
+ return self.url_for_material(slug, fmt)
+
+ def text_to_anchor(self, text):
+ return re.sub(r" +", " ", text)
+
+ def naglowek_to_anchor(self, naglowek):
+ return self.text_to_anchor(naglowek.text.strip())
+
+ def get_forma_url(self, forma):
+ return None
+
+ def get_help_url(self, naglowek):
+ return None
+
+
+def transform(wldoc, stylesheet='edumed', options=None, flags=None, verbose=None):