# HG changeset patch # User Goffi # Date 1556260947 -7200 # Node ID 469d0de8da0ec651371aeb1581beb7e6aee0cbce # Parent 4648a333b33f307bb4a31d6b6f646f8745b162c9 pages (blog, u): added atom feed link in "links" template data. diff -r 4648a333b33f -r 469d0de8da0e libervia/pages/blog/view/page_meta.py --- a/libervia/pages/blog/view/page_meta.py Fri Apr 12 14:12:53 2019 +0200 +++ b/libervia/pages/blog/view/page_meta.py Fri Apr 26 08:42:27 2019 +0200 @@ -13,6 +13,7 @@ from sat.tools.common import uri from sat.tools.common import data_format from libervia.server import utils +from libervia.server.utils import SubPage from sat.core.log import getLogger log = getLogger(__name__) @@ -57,19 +58,20 @@ self.pageError(request, C.HTTP_BAD_REQUEST) try: - data['node'] = self.nextPath(request) + node = self.nextPath(request) except IndexError: - data['node'] = u'' - else: - if data['node'] == u'@': - data['node'] = u'' + node = u'@' + data['node'] = u'' if node == u'@' else node try: filter_kw = data['filter_keyword'] = self.nextPath(request) except IndexError: - pass + filter_kw = u'@' else: - if filter_kw == u'id': + if filter_kw == u'@': + # No filter, this is used when a subpage is needed, notably Atom feed + pass + elif filter_kw == u'id': try: data[u'item'] = self.nextPath(request) except IndexError: @@ -86,9 +88,25 @@ self.pageError(request, C.HTTP_BAD_REQUEST) else: # invalid filter keyword - log.warning(_(u"invalid filter keyword: {filter_kw}").format(filter_kw=filter_kw)) + log.warning(_(u"invalid filter keyword: {filter_kw}").format( + filter_kw=filter_kw)) self.pageError(request, C.HTTP_BAD_REQUEST) + # if URL is parsed here, we'll have atom.xml available and we need to + # add the link to the page + atom_url = self.getURLByPath( + SubPage(u'blog_view'), + service, + node, + filter_kw, + SubPage(u'blog_feed_atom'), + ) + request.template_data.setdefault(u'links', []).append({ + u"href": atom_url, + u"type": "application/atom+xml", + u"rel": "alternate", + u"title": "{service}'s blog".format(service=service)}) + @defer.inlineCallbacks def appendComments(self, blog_items, identities, profile): diff -r 4648a333b33f -r 469d0de8da0e libervia/pages/u/atom.xml/page_meta.py --- a/libervia/pages/u/atom.xml/page_meta.py Fri Apr 12 14:12:53 2019 +0200 +++ b/libervia/pages/u/atom.xml/page_meta.py Fri Apr 26 08:42:27 2019 +0200 @@ -1,3 +1,4 @@ #!/usr/bin/env python2.7 # -*- coding: utf-8 -*- redirect = u"blog_feed_atom" +name = u"user_blog_feed_atom" diff -r 4648a333b33f -r 469d0de8da0e libervia/pages/u/page_meta.py --- a/libervia/pages/u/page_meta.py Fri Apr 12 14:12:53 2019 +0200 +++ b/libervia/pages/u/page_meta.py Fri Apr 26 08:42:27 2019 +0200 @@ -30,6 +30,15 @@ target_jid = jid.JID(target_jid) data[u"service"] = target_jid + # if URL is parsed here, we'll have atom.xml available and we need to + # add the link to the page + atom_url = self.getSubPageURL(request, u'user_blog_feed_atom') + request.template_data.setdefault(u'links', []).append({ + u"href": atom_url, + u"type": "application/atom+xml", + u"rel": "alternate", + u"title": "{target_profile}'s blog".format(target_profile=target_profile)}) + @defer.inlineCallbacks def prepare_render(self, request): diff -r 4648a333b33f -r 469d0de8da0e libervia/server/pages.py --- a/libervia/server/pages.py Fri Apr 12 14:12:53 2019 +0200 +++ b/libervia/server/pages.py Fri Apr 26 08:42:27 2019 +0200 @@ -635,9 +635,8 @@ ) def getURLByNames(self, named_path): - """retrieve URL from pages names and arguments + """Retrieve URL from pages names and arguments - @param request(server.Request): request linked to the session @param named_path(list[tuple[unicode, list[unicode]]]): path to the page as a list of tuples of 2 items: - first item is page name @@ -661,11 +660,10 @@ return self.host.checkRedirection(self.vhost_root, u"/".join(path)) def getURLByPath(self, *args): - """generate URL by path + """Generate URL by path this method as a similar effect as getURLByNames, but it is more readable by using SubPage to get pages instead of using tuples - @param request(server.Request): request linked to the session @param *args: path element: - if unicode, will be used as argument - if util.SubPage instance, must be the name of a subpage