comparison libervia/pages/blog/view/page_meta.py @ 1171:469d0de8da0e

pages (blog, u): added atom feed link in "links" template data.
author Goffi <goffi@goffi.org>
date Fri, 26 Apr 2019 08:42:27 +0200
parents 3048bd137aaf
children 0f37b65fe7c2
comparison
equal deleted inserted replaced
1170:4648a333b33f 1171:469d0de8da0e
11 from sat.core.i18n import _ 11 from sat.core.i18n import _
12 from sat.tools.common.template import safe 12 from sat.tools.common.template import safe
13 from sat.tools.common import uri 13 from sat.tools.common import uri
14 from sat.tools.common import data_format 14 from sat.tools.common import data_format
15 from libervia.server import utils 15 from libervia.server import utils
16 from libervia.server.utils import SubPage
16 from sat.core.log import getLogger 17 from sat.core.log import getLogger
17 18
18 log = getLogger(__name__) 19 log = getLogger(__name__)
19 20
20 """generic blog (with service/node provided)""" 21 """generic blog (with service/node provided)"""
55 except Exception: 56 except Exception:
56 log.warning(_(u"bad service entered: {}").format(service)) 57 log.warning(_(u"bad service entered: {}").format(service))
57 self.pageError(request, C.HTTP_BAD_REQUEST) 58 self.pageError(request, C.HTTP_BAD_REQUEST)
58 59
59 try: 60 try:
60 data['node'] = self.nextPath(request) 61 node = self.nextPath(request)
61 except IndexError: 62 except IndexError:
62 data['node'] = u'' 63 node = u'@'
63 else: 64 data['node'] = u'' if node == u'@' else node
64 if data['node'] == u'@':
65 data['node'] = u''
66 65
67 try: 66 try:
68 filter_kw = data['filter_keyword'] = self.nextPath(request) 67 filter_kw = data['filter_keyword'] = self.nextPath(request)
69 except IndexError: 68 except IndexError:
70 pass 69 filter_kw = u'@'
71 else: 70 else:
72 if filter_kw == u'id': 71 if filter_kw == u'@':
72 # No filter, this is used when a subpage is needed, notably Atom feed
73 pass
74 elif filter_kw == u'id':
73 try: 75 try:
74 data[u'item'] = self.nextPath(request) 76 data[u'item'] = self.nextPath(request)
75 except IndexError: 77 except IndexError:
76 self.pageError(request, C.HTTP_BAD_REQUEST) 78 self.pageError(request, C.HTTP_BAD_REQUEST)
77 # we get one more argument in case text has been added to have a nice URL 79 # we get one more argument in case text has been added to have a nice URL
84 data[u'tag'] = self.nextPath(request) 86 data[u'tag'] = self.nextPath(request)
85 except IndexError: 87 except IndexError:
86 self.pageError(request, C.HTTP_BAD_REQUEST) 88 self.pageError(request, C.HTTP_BAD_REQUEST)
87 else: 89 else:
88 # invalid filter keyword 90 # invalid filter keyword
89 log.warning(_(u"invalid filter keyword: {filter_kw}").format(filter_kw=filter_kw)) 91 log.warning(_(u"invalid filter keyword: {filter_kw}").format(
92 filter_kw=filter_kw))
90 self.pageError(request, C.HTTP_BAD_REQUEST) 93 self.pageError(request, C.HTTP_BAD_REQUEST)
94
95 # if URL is parsed here, we'll have atom.xml available and we need to
96 # add the link to the page
97 atom_url = self.getURLByPath(
98 SubPage(u'blog_view'),
99 service,
100 node,
101 filter_kw,
102 SubPage(u'blog_feed_atom'),
103 )
104 request.template_data.setdefault(u'links', []).append({
105 u"href": atom_url,
106 u"type": "application/atom+xml",
107 u"rel": "alternate",
108 u"title": "{service}'s blog".format(service=service)})
91 109
92 110
93 @defer.inlineCallbacks 111 @defer.inlineCallbacks
94 def appendComments(self, blog_items, identities, profile): 112 def appendComments(self, blog_items, identities, profile):
95 for blog_item in blog_items: 113 for blog_item in blog_items: