slowniczek + metody
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 13 Feb 2013 13:59:12 +0000 (14:59 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 13 Feb 2013 13:59:12 +0000 (14:59 +0100)
catalogue/models.py
catalogue/publish.py
catalogue/templates/catalogue/section_list.html
catalogue/views.py

index b42a463..f05688d 100644 (file)
@@ -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())))
index 023e8bd..bf215a6 100755 (executable)
@@ -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)
index 6317688..e5ee91e 100755 (executable)
@@ -20,9 +20,9 @@
     <section class="section-minor">
         <h1>Zebrane z wszystkich działów</h1>
         <ul class="link-list">
-            <li><a href="">Słowniczek</a></li>
-            <li><a href="">Czytelnia</a></li>
-            <li><a href="">Używane metody edukacyjne</a></li>
+            {% for lesson in appendix %}
+                <li><a href="{{ lesson.get_absolute_url }}">{{ lesson }}</a></li>
+            {% endfor %}
         </ul>
     </section>
 </aside>
index 2f511ef..7108b2b 100644 (file)
@@ -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