changeset 1057:50ba8947a6e8

common/blog: "service" and "node" are now set in template_data
author Goffi <goffi@goffi.org>
date Tue, 30 Jan 2018 08:04:33 +0100
parents 47c354ca66a3
children 2290b6ec3991
files src/pages/common/blog/page_meta.py
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/pages/common/blog/page_meta.py	Tue Jan 30 08:01:27 2018 +0100
+++ b/src/pages/common/blog/page_meta.py	Tue Jan 30 08:04:33 2018 +0100
@@ -6,12 +6,12 @@
 from sat.tools.common import data_objects
 from libervia.server import session_iface
 from sat.core.i18n import _
-from sat.core.log import getLogger
 from sat.tools.common.template import safe
 from libervia.server import utils
 import unicodedata
 import re
 import cgi
+from sat.core.log import getLogger
 log = getLogger('pages/common/blog')
 
 """generic blog (with service/node provided)"""
@@ -24,6 +24,7 @@
 TEXT_WORD_MIN_LENGHT = 4
 URL_LIMIT_MARK = 90  # if canonical URL is longer than that, text will not be appended
 
+
 def microblog_uri(self, uri_data):
     args = [uri_data[u'path'], uri_data[u'node']]
     if u'item' in uri_data:
@@ -151,6 +152,7 @@
     if profile is None:
         profile = C.SERVICE_PROFILE
 
+    ## pagination/filtering parameters
     params = self.getAllPostedData(request, multiple=False)
     if item_id:
         extra = {}
@@ -164,8 +166,17 @@
         if tag:
             extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag
 
+    ## main data ##
+    # we get data from backend/XMPP here
     blog_data, items = yield getBlogData(self, request, service, node, item_id, extra, profile)
+
+    ## navigation ##
+    # no let's fill service, node and pagination URLs
     template_data = request.template_data
+    if u'service' not in template_data:
+        template_data[u'service'] = service
+    if u'node' not in template_data:
+        template_data[u'node'] = node
     target_profile = template_data.get(u'target_profile')
 
     if items:
@@ -188,11 +199,17 @@
             last_id = items[-1].id
             template_data['older_url'] = self.getParamURL(request, after=last_id)
 
+    ## identities ##
+    # identities are use to show nice nickname or avatars
     identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities
 
+    ## Comments ##
+    # if comments are requested, we need to take them
     if show_comments:
         yield appendComments(self, items, identities, profile)
 
+    ## URLs ##
+    # We will fill items_http_uri and tags_http_uri in template_data with suitable urls
     # if we know the profile, we use it instead of service + blog (nicer url)
     if target_profile is None:
         blog_base_url_item = self.getPageByName(u'blog_view').getURL(service.full(), node or u'@', u'id')
@@ -214,13 +231,15 @@
         template_data[u'items'].items.reverse()
     template_data[u'items_http_uri'] = items_http_uri = {}
     template_data[u'tags_http_uri'] = tags_http_uri = {}
+
+
     for item in items:
         blog_canonical_url = u'/'.join([blog_base_url_item, utils.quote(item.id)])
         if len(blog_canonical_url) > URL_LIMIT_MARK:
             blog_url = blog_canonical_url
         else:
             # we add text from title or body at the end of URL
-            # to make it more readable
+            # to make it more human readable
             text = item.title or item.content
             # we change special chars to ascii one, trick found at https://stackoverflow.com/a/3194567
             text = unicodedata.normalize('NFD', text).encode('ascii', 'ignore')
@@ -241,6 +260,8 @@
             if tag not in tags_http_uri:
                 tag_url = u'/'.join([blog_base_url_tag, utils.quote(tag)])
                 tags_http_uri[tag] = self.host.getExtBaseURL(request, tag_url)
+
+    # if True, page should display a comment box
     template_data[u'allow_commenting'] = data.get(u'allow_commenting', False)