changeset 1024:2ae3b6291456

pages (common/blog): handle tags filtering using "/tag/[tag]" in path
author Goffi <goffi@goffi.org>
date Sun, 21 Jan 2018 20:23:33 +0100
parents 2cb60ef2a76f
children 36e5945d064c
files src/pages/common/blog/page_meta.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/pages/common/blog/page_meta.py	Sun Jan 21 20:21:46 2018 +0100
+++ b/src/pages/common/blog/page_meta.py	Sun Jan 21 20:23:33 2018 +0100
@@ -59,7 +59,12 @@
     else:
         if filter_kw == u'id':
             try:
-                data['item'] = self.nextPath(request)
+                data[u'item'] = self.nextPath(request)
+            except IndexError:
+                self.pageError(request, C.HTTP_BAD_REQUEST)
+        elif filter_kw == u'tag':
+            try:
+                data[u'tag'] = self.nextPath(request)
             except IndexError:
                 self.pageError(request, C.HTTP_BAD_REQUEST)
         else:
@@ -139,6 +144,9 @@
             extra[u'rsm_after'] = params[u'after']
         elif u'before' in params:
             extra[u'rsm_before'] = params[u'before']
+        tag = data.get('tag')
+        if tag:
+            extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag
 
     blog_data, items = yield getBlogData(self, request, service, node, item_id, extra, profile)
     template_data = request.template_data
@@ -169,7 +177,14 @@
 
     blog_view = self.getPageByName(u'blog_view')
     template_data[u'items'] = data[u'items'] = items
-    template_data[u'items_http_uri'] = {item.id: self.host.getExtBaseURL(request, blog_view.getURL(service.full(), node or '@', u'id', item.id)) for item in items}
+    template_data[u'item_http_uri'] = items_http_uri = {}
+    template_data[u'tags_http_uri'] = tags_http_uri = {}
+    for item in items:
+        service_s = service.full()
+        items_http_uri[item.id] = self.host.getExtBaseURL(request, blog_view.getURL(service_s, node or '@', u'id', item.id))
+        for tag in item.tags:
+            if tag not in tags_http_uri:
+                tags_http_uri[tag] = self.host.getExtBaseURL(request, blog_view.getURL(service_s, node or '@', u'tag', tag))
     template_data[u'allow_commenting'] = data.get(u'allow_commenting', False)