From: Radek Czajka Date: Wed, 13 Feb 2013 13:59:12 +0000 (+0100) Subject: slowniczek + metody X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/c1f370d46a0e1d1c8d99e5d67fd9553e10c10158?ds=sidebyside;hp=ca7ebe153aa3986421f5c161f08c674b4eaaf141 slowniczek + metody --- diff --git a/catalogue/models.py b/catalogue/models.py index b42a463..f05688d 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -144,12 +144,12 @@ class Lesson(models.Model): def build_html(self, infile=None): from librarian.parser import WLDocument - from .publish import HtmlFormat + from .publish import HtmlFormat, OrmDocProvider if infile is None: - wldoc = WLDocument.from_file(self.xml_file.path) + wldoc = WLDocument.from_file(self.xml_file.path, provider=OrmDocProvider) else: - wldoc = WLDocument(infile) + wldoc = WLDocument(infile, provider=OrmDocProvider()) html = HtmlFormat(wldoc).build() self.html_file.save("%s.html" % self.slug, File(open(html.get_filename()))) diff --git a/catalogue/publish.py b/catalogue/publish.py index 023e8bd..bf215a6 100755 --- a/catalogue/publish.py +++ b/catalogue/publish.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 from django.core.files import File +from librarian import DocProvider, IOFile from librarian.pyhtml import EduModuleFormat from .models import Lesson, Attachment @@ -29,7 +30,11 @@ class HtmlFormat(EduModuleFormat): att = lesson.attachment_set.create(slug=slug, ext=fmt) att.file.save(att_name, File(att_file.get_file())) return att.file.url - - else: return att.file.url + + +class OrmDocProvider(DocProvider): + def by_slug(self, slug): + """Should return a file-like object with a WL document XML.""" + return IOFile.from_filename(Lesson.objects.get(slug=slug).xml_file.path) diff --git a/catalogue/templates/catalogue/section_list.html b/catalogue/templates/catalogue/section_list.html index 6317688..e5ee91e 100755 --- a/catalogue/templates/catalogue/section_list.html +++ b/catalogue/templates/catalogue/section_list.html @@ -20,9 +20,9 @@

Zebrane z wszystkich działów

diff --git a/catalogue/views.py b/catalogue/views.py index 2f511ef..7108b2b 100644 --- a/catalogue/views.py +++ b/catalogue/views.py @@ -1,13 +1,14 @@ import os.path from django.conf import settings from django.views.generic import DetailView, ListView -from .models import Section +from .models import Lesson, Section class SectionView(ListView): model = Section def get_context_data(self, **kwargs): context = super(SectionView, self).get_context_data(**kwargs) + context['appendix'] = Lesson.objects.filter(type='appendix') context['package_url'] = os.path.join(settings.MEDIA_URL, settings.CATALOGUE_PACKAGE) context['package_student_url'] = os.path.join(settings.MEDIA_URL, settings.CATALOGUE_PACKAGE_STUDENT) return context