page breadcrumb
authorTero Marttila <terom@paivola.fi>
Sun, 14 Sep 2014 01:07:54 +0300
changeset 198 66cf32a10222
parent 197 11a6d8fea463
child 199 9fd827df377f
page breadcrumb
qmsk_www_pages/pages.py
qmsk_www_pages/templates/pages/page.html
qmsk_www_pages/views.py
--- a/qmsk_www_pages/pages.py	Sun Sep 14 00:59:07 2014 +0300
+++ b/qmsk_www_pages/pages.py	Sun Sep 14 01:07:54 2014 +0300
@@ -79,16 +79,29 @@
         if not page_type:
             return None
 
-        return page_type(page_path, page_name)
+        return page_type(
+            path    = page_path,
+            name    = page_name,
+            parents = parts,
+        )
 
-    def __init__ (self, path, name, encoding=ENCODING):
+    def __init__ (self, path, name, parents, encoding=ENCODING):
         self.path = path
         self.name = name
+        self.parents = parents
         self.encoding = encoding
 
     def open (self):
         return codecs.open(self.path, encoding=self.encoding)
 
+    def breadcrumb (self):
+        path = []
+
+        for parent in self.parents + [ self.name ]:
+            path.append(parent)
+
+            yield '/'.join(path), parent
+
     def render (self, request):
         raise NotImplementedError()
 
--- a/qmsk_www_pages/templates/pages/page.html	Sun Sep 14 00:59:07 2014 +0300
+++ b/qmsk_www_pages/templates/pages/page.html	Sun Sep 14 01:07:54 2014 +0300
@@ -10,6 +10,13 @@
             </h1>
         </div>
         <hr />
+        <div class="page-breadcrumb">
+            <ol class="breadcrumb">
+                {% for page, name in page_breadcrumb %}
+                <li><a href="{% url 'page' page %}">{{ name }}</a></li>
+                {% endfor %}
+            </ol>
+        </div>
         <div class="row">
             <div class="col-sm-2 pages-tree">
                 <ul class="nav">
--- a/qmsk_www_pages/views.py	Sun Sep 14 00:59:07 2014 +0300
+++ b/qmsk_www_pages/views.py	Sun Sep 14 01:07:54 2014 +0300
@@ -11,6 +11,7 @@
         raise Http404
 
     return render(request, 'pages/page.html', dict(
-            page_name   = page.name,
-            page_html   = page.render(request),
+            page_name       = page.name,
+            page_breadcrumb = page.breadcrumb(),
+            page_html       = page.render(request),
     ))