+ @classmethod
+ def publish(cls, infile):
+ from librarian.parser import WLDocument
+ from django.core.files.base import ContentFile
+ xml = infile.get_string()
+ wldoc = WLDocument.from_string(xml)
+
+ try:
+ lessons = [Lesson.objects.get(slug=part.slug)
+ for part in wldoc.book_info.parts]
+ except Lesson.DoesNotExist, e:
+ raise cls.IncompleteError(part.slug)
+
+ slug = wldoc.book_info.url.slug
+ try:
+ section = cls.objects.get(slug=slug)
+ except cls.DoesNotExist:
+ section = cls(slug=slug, order=0)
+
+ # Save XML file
+ section.xml_file.save('%s.xml' % slug, ContentFile(xml), save=False)
+ section.title = wldoc.book_info.title
+ section.save()
+
+ section.lesson_set.all().update(section=None)
+ for i, lesson in enumerate(lessons):
+ lesson.section = section
+ lesson.order = i
+ lesson.save()
+
+ return section
+
+ def syntetic_lesson(self, level):