changeset 880:ccbad50e1426

blog, themes(default): added <link> element referencing xmpp: uri of the item
author Goffi <goffi@goffi.org>
date Wed, 09 Mar 2016 17:56:19 +0100
parents 2e0e9cf9efb4
children 6bdee34fa2f4
files src/server/blog.py themes/default/static_blog.html
diffstat 2 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/blog.py	Wed Mar 09 17:33:00 2016 +0100
+++ b/src/server/blog.py	Wed Mar 09 17:56:19 2016 +0100
@@ -559,7 +559,16 @@
         avatar = os.path.normpath('/{}'.format(getOption('avatar')))
         title = getOption(C.STATIC_BLOG_PARAM_TITLE) or user
         query_data = urllib.urlencode(getDefaultQueryData(request)).decode('utf-8')
+
+        xmpp_uri = metadata['uri']
+        if len(items) == 1:
+            # FIXME: that's really not a good way to get item id
+            #        this must be changed after static blog refactorisation
+            item_id = items[0][0]['id']
+            xmpp_uri+=u";item={}".format(urllib.quote(item_id))
+
         data = {'url_base': base_url,
+                'xmpp_uri': xmpp_uri,
                 'url_query': u'?{}'.format(query_data) if query_data else '' ,
                 'keywords': getOption(C.STATIC_BLOG_PARAM_KEYWORDS),
                 'description': getOption(C.STATIC_BLOG_PARAM_DESCRIPTION),
@@ -591,14 +600,17 @@
 
 class NavigationLinks(object):
 
-    def __init__(self, request, items, rsm_data, base_url):
+    def __init__(self, request, items, metadata, base_url):
         """Build the navigation links.
 
         @param items (list): list of items
-        @param rsm_data (dict): rsm data
+        @param metadata (dict): rsm data
         @param base_url (unicode): the base URL for this user's blog
         @return: dict
         """
+        # FIXME: this code must be refactorized, it is fragile
+        #        and difficult to maintain
+
         # query data which must be present in all links
         default_query_data = getDefaultQueryData(request)
 
@@ -617,7 +629,7 @@
 
             if key.startswith('later_message'):
                 try:
-                    index = int(rsm_data['rsm_index'])
+                    index = int(metadata['rsm_index'])
                 except (KeyError, ValueError):
                     pass
                 else:
@@ -626,13 +638,13 @@
                         setattr(self, key, '')
                         continue
                 try:
-                    query_data['before'] = rsm_data['rsm_first'].encode('utf-8')
+                    query_data['before'] = metadata['rsm_first'].encode('utf-8')
                 except KeyError:
                     pass
             else:
                 try:
-                    index = int(rsm_data['rsm_index'])
-                    count = int(rsm_data.get('rsm_count'))
+                    index = int(metadata['rsm_index'])
+                    count = int(metadata.get('rsm_count'))
                 except (KeyError, ValueError):
                     # XXX: if we don't have index or count, we can't know if we
                     #      are on the last page or not
@@ -644,7 +656,7 @@
                         setattr(self, key, '')
                         continue
                 try:
-                    query_data['after'] = rsm_data['rsm_last'].encode('utf-8')
+                    query_data['after'] = metadata['rsm_last'].encode('utf-8')
                 except KeyError:
                     pass
 
--- a/themes/default/static_blog.html	Wed Mar 09 17:33:00 2016 +0100
+++ b/themes/default/static_blog.html	Wed Mar 09 17:56:19 2016 +0100
@@ -87,6 +87,7 @@
         <meta name="keywords" content="{{keywords}}" />
         <meta name="description" content="{{description}}" />
         <link rel="alternate" type="application/atom+xml" href="{{url_base}}/atom.xml{{url_query}}" />
+        <link rel="alternate" type="application/xmpp+xml" href="{{xmpp_uri}}" />
         <link rel='stylesheet' type="text/css" href='{{styles}}/blog.css' />
         <link rel="icon" type="image/png" href="{{favicon}}" />