annotate libervia/pages/blog/view/page_meta.py @ 1491:3002ea1d6ae9

pages (blog/view): don't use backend cache when "no cache" is requested
author Goffi <goffi@goffi.org>
date Wed, 26 Jan 2022 10:24:46 +0100
parents 595e7fef41f3
children 1702b8c821c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1229
diff changeset
2
1229
acec8e9185db pages: replaced deprecated `cgi.escape` by `html.escape`
Goffi <goffi@goffi.org>
parents: 1219
diff changeset
3 import html
1491
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
4 from typing import Dict, Any
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from libervia.server.constants import Const as C
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.words.protocols.jabber import jid
1466
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
7 from twisted.web import server
1419
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
8 from sat.core.i18n import _, D_
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from sat.tools.common.template import safe
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from sat.tools.common import uri
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
11 from sat.tools.common import data_format
1406
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
12 from sat.tools.common import regex
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
13 from sat.core.log import getLogger
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 from libervia.server import utils
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
15 from libervia.server.utils import SubPage
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
16
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
17 log = getLogger(__name__)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 """generic blog (with service/node provided)"""
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
20 name = 'blog_view'
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
21 template = "blog/articles.html"
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
22 uri_handlers = {('pubsub', 'microblog'): 'microblog_uri'}
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 URL_LIMIT_MARK = 90 # if canonical URL is longer than that, text will not be appended
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 def microblog_uri(self, uri_data):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
28 args = [uri_data['path'], uri_data['node']]
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
29 if 'item' in uri_data:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
30 args.extend(['id', uri_data['item']])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 return self.getURL(*args)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def parse_url(self, request):
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 """URL is /[service]/[node]/[filter_keyword]/[item]|[other]
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 if [node] is '@', default namespace is used
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 if a value is unset, default one will be used
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 keyword can be one of:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 id: next value is a item id
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 tag: next value is a blog tag
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 data = self.getRData(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 try:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 service = self.nextPath(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 except IndexError:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
47 data['service'] = ''
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 try:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
50 data["service"] = jid.JID(service)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 except Exception:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
52 log.warning(_("bad service entered: {}").format(service))
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.pageError(request, C.HTTP_BAD_REQUEST)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 try:
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
56 node = self.nextPath(request)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 except IndexError:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
58 node = '@'
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
59 data['node'] = '' if node == '@' else node
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 try:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 filter_kw = data['filter_keyword'] = self.nextPath(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 except IndexError:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
64 filter_kw = '@'
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
66 if filter_kw == '@':
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
67 # No filter, this is used when a subpage is needed, notably Atom feed
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
68 pass
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
69 elif filter_kw == 'id':
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 try:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
71 data['item'] = self.nextPath(request)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 except IndexError:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.pageError(request, C.HTTP_BAD_REQUEST)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 # we get one more argument in case text has been added to have a nice URL
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 try:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.nextPath(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 except IndexError:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 pass
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
79 elif filter_kw == 'tag':
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 try:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
81 data['tag'] = self.nextPath(request)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 except IndexError:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.pageError(request, C.HTTP_BAD_REQUEST)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 # invalid filter keyword
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
86 log.warning(_("invalid filter keyword: {filter_kw}").format(
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
87 filter_kw=filter_kw))
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.pageError(request, C.HTTP_BAD_REQUEST)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
90 # if URL is parsed here, we'll have atom.xml available and we need to
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
91 # add the link to the page
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
92 atom_url = self.getURLByPath(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
93 SubPage('blog_view'),
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
94 service,
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
95 node,
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
96 filter_kw,
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
97 SubPage('blog_feed_atom'),
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
98 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
99 request.template_data['atom_url'] = atom_url
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
100 request.template_data.setdefault('links', []).append({
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
101 "href": atom_url,
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
102 "type": "application/atom+xml",
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
103 "rel": "alternate",
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
104 "title": "{service}'s blog".format(service=service)})
1171
469d0de8da0e pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents: 1156
diff changeset
105
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
1419
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
107 def add_breadcrumb(self, request, breadcrumbs):
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
108 data = self.getRData(request)
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
109 breadcrumbs.append({
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
110 "label": D_("Feed"),
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
111 "url": self.getURL(data["service"].full(), data.get("node", "@"))
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
112 })
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
113 if "item" in data:
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
114 breadcrumbs.append({
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
115 "label": D_("Post"),
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
116 })
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
117
6fc41f000d24 pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents: 1406
diff changeset
118
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
119 async def appendComments(self, request, blog_items, profile):
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
120 await self.fillMissingIdentities(
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
121 request, [i['author_jid'] for i in blog_items['items']])
1491
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
122 extra: Dict[str, Any] = {C.KEY_ORDER_BY: C.ORDER_BY_CREATION}
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
123 if not self.useCache(request):
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
124 extra[C.KEY_USE_CACHE] = False
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
125 for blog_item in blog_items['items']:
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
126 for comment_data in blog_item['comments']:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
127 service = comment_data['service']
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
128 node = comment_data['node']
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 try:
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
130 comments_data = await self.host.bridgeCall('mbGet',
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 service,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 node,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 C.NO_LIMIT,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 [],
1447
907f519faaf0 pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
135 data_format.serialise(
1491
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
136 extra
1447
907f519faaf0 pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
137 ),
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 profile)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 except Exception as e:
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
140 log.warning(
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
141 _("Can't get comments at {node} (service: {service}): {msg}").format(
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
142 service=service,
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
143 node=node,
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
144 msg=e))
1403
1357d04107d1 pages (blog/view): set empty comments when comments node is missing
Goffi <goffi@goffi.org>
parents: 1376
diff changeset
145 comment_data['items'] = []
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 continue
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
147
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
148 comments = data_format.deserialise(comments_data)
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
149 comment_data['items'] = comments['items']
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
150 await appendComments(self, request, comments, profile)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
151
1466
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
152 async def getBlogItems(
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
153 self,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
154 request: server.Request,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
155 service: jid.JID,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
156 node: str,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
157 item_id,
1491
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
158 extra: Dict[str, Any],
1466
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
159 profile: str
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
160 ) -> dict:
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 try:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 if item_id:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 items_id = [item_id]
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 items_id = []
1491
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
166 if not self.useCache(request):
3002ea1d6ae9 pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents: 1483
diff changeset
167 extra[C.KEY_USE_CACHE] = False
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
168 blog_data = await self.host.bridgeCall('mbGet',
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 service.userhost(),
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 node,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 C.NO_LIMIT,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 items_id,
1447
907f519faaf0 pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
173 data_format.serialise(extra),
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 profile)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 except Exception as e:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 # FIXME: need a better way to test errors in bridge errback
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
177 if "forbidden" in str(e):
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.pageError(request, 401)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
180 log.warning(_("can't retrieve blog for [{service}]: {msg}".format(
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 service = service.userhost(), msg=e)))
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
182 blog_data = {"items": []}
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
183 else:
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
184 blog_data = data_format.deserialise(blog_data)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
185
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
186 return blog_data
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
187
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
188 async def prepare_render(self, request):
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 data = self.getRData(request)
1376
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
190 template_data = request.template_data
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
191 page_max = data.get("page_max", 10)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 # if the comments are not explicitly hidden, we show them
1376
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
193 service, node, item_id, show_comments = (
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
194 data.get('service', ''),
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
195 data.get('node', ''),
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
196 data.get('item'),
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
197 data.get('show_comments', True)
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
198 )
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 profile = self.getProfile(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if profile is None:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 profile = C.SERVICE_PROFILE
1133
122dd136d1ab pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
202 profile_connected = False
122dd136d1ab pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
203 else:
122dd136d1ab pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
204 profile_connected = True
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
205
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 ## pagination/filtering parameters
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 if item_id:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 extra = {}
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 else:
1141
02fc28aac2b6 pages: move pagination core from blog to LiberviaPage so it can be reused:
Goffi <goffi@goffi.org>
parents: 1140
diff changeset
210 extra = self.getPubsubExtra(request, page_max=page_max)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 tag = data.get('tag')
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 if tag:
1376
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
213 extra[f'mam_filter_{C.MAM_FILTER_CATEGORY}'] = tag
1b94a5ab155f pages (blog/view): Full-Text Search is used when `search` query argument is present
Goffi <goffi@goffi.org>
parents: 1322
diff changeset
214 self.handleSearch(request, extra)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
215
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 ## main data ##
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 # we get data from backend/XMPP here
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
218 blog_items = await getBlogItems(self, request, service, node, item_id, extra, profile)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
219
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 ## navigation ##
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 # no let's fill service, node and pagination URLs
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
222 if 'service' not in template_data:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
223 template_data['service'] = service
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
224 if 'node' not in template_data:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
225 template_data['node'] = node
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
226 target_profile = template_data.get('target_profile')
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
227
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
228 if blog_items:
1466
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
229 if item_id:
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
230 template_data["previous_page_url"] = self.getURL(
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
231 service.full(),
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
232 node,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
233 before=item_id,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
234 page_max=1
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
235 )
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
236 template_data["next_page_url"] = self.getURL(
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
237 service.full(),
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
238 node,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
239 after=item_id,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
240 page_max=1
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
241 )
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
242 blog_items["rsm"] = {
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
243 "last": item_id,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
244 "first": item_id,
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
245 }
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
246 blog_items["complete"] = False
cff720e26089 pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
247 else:
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
248 self.setPagination(request, blog_items)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 if item_id:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 # if item id has been specified in URL and it's not found,
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 # we must return an error
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 self.pageError(request, C.HTTP_NOT_FOUND)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
254
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 ## identities ##
1133
122dd136d1ab pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
256 # identities are used to show nice nickname or avatars
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
257 await self.fillMissingIdentities(request, [i['author_jid'] for i in blog_items['items']])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 ## Comments ##
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 # if comments are requested, we need to take them
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 if show_comments:
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
262 await appendComments(self, request, blog_items, profile)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
263
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 ## URLs ##
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 # We will fill items_http_uri and tags_http_uri in template_data with suitable urls
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 # if we know the profile, we use it instead of service + blog (nicer url)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 if target_profile is None:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
268 blog_base_url_item = self.getPageByName('blog_view').getURL(service.full(), node or '@', 'id')
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
269 blog_base_url_tag = self.getPageByName('blog_view').getURL(service.full(), node or '@', 'tag')
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
271 blog_base_url_item = self.getURLByNames([('user', [target_profile]), ('user_blog', ['id'])])
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
272 blog_base_url_tag = self.getURLByNames([('user', [target_profile]), ('user_blog', ['tag'])])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 # we also set the background image if specified by user
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
274 bg_img = await self.host.bridgeCall('asyncGetParamA', 'Background', 'Blog page', 'value', -1, template_data['target_profile'])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 if bg_img:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
276 template_data['dynamic_style'] = safe("""
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 :root {
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 --bg-img: url("%s");
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 }
1229
acec8e9185db pages: replaced deprecated `cgi.escape` by `html.escape`
Goffi <goffi@goffi.org>
parents: 1219
diff changeset
280 """ % html.escape(bg_img, True))
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
281
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
282 template_data['blog_items'] = data['blog_items'] = blog_items
1219
0f0c36992f3c pages (blog/view, forums/view): fixed encoding of request.args following Python3 port
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
283 if request.args.get(b'reverse') == ['1']:
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
284 template_data['blog_items'].items.reverse()
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
285 template_data['items_http_uri'] = items_http_uri = {}
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
286 template_data['tags_http_uri'] = tags_http_uri = {}
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
287
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
288
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
289 for item in blog_items['items']:
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
290 blog_canonical_url = '/'.join([blog_base_url_item, utils.quote(item['id'])])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 if len(blog_canonical_url) > URL_LIMIT_MARK:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 blog_url = blog_canonical_url
1406
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
293 elif '-' not in item['id']:
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 # we add text from title or body at the end of URL
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 # to make it more human readable
1406
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
296 # we do it only if there is no "-", as a "-" probably means that
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
297 # item's id is already user friendly.
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
298 # TODO: to be removed, this is only kept for a transition period until
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
299 # user friendly item IDs are more common.
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
300 text = regex.urlFriendlyText(item.get('title', item['content']))
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 if text:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
302 blog_url = blog_canonical_url + '/' + text
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 blog_url = blog_canonical_url
1406
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
305 else:
cffa3ae4d0aa pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
306 blog_url = blog_canonical_url
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
307
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
308 items_http_uri[item['id']] = self.host.getExtBaseURL(request, blog_url)
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
309 for tag in item['tags']:
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 if tag not in tags_http_uri:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
311 tag_url = '/'.join([blog_base_url_tag, utils.quote(tag)])
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 tags_http_uri[tag] = self.host.getExtBaseURL(request, tag_url)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
313
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 # if True, page should display a comment box
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
315 template_data['allow_commenting'] = data.get('allow_commenting', profile_connected)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
316
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 # last but not least, we add a xmpp: link to the node
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
318 uri_args = {'path': service.full()}
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 if node:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
320 uri_args['node'] = node
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 if item_id:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
322 uri_args['item'] = item_id
1478
10ccad665d57 pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents: 1466
diff changeset
323 template_data['xmpp_uri'] = uri.buildXMPPUri(
10ccad665d57 pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents: 1466
diff changeset
324 'pubsub', subtype='microblog', **uri_args
10ccad665d57 pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents: 1466
diff changeset
325 )
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
326
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
327
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
328 async def on_data_post(self, request):
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 profile = self.getProfile(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 if profile is None:
1173
0f37b65fe7c2 server: replaced wrong usage of C.HTTP_UNAUTHORIZED by C.HTTP_FORBIDDEN
Goffi <goffi@goffi.org>
parents: 1171
diff changeset
331 self.pageError(request, C.HTTP_FORBIDDEN)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
332 type_ = self.getPostedData(request, 'type')
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
333 if type_ == 'comment':
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
334 service, node, body = self.getPostedData(request, ('service', 'node', 'body'))
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
335
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 if not body:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 self.pageError(request, C.HTTP_BAD_REQUEST)
1478
10ccad665d57 pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents: 1466
diff changeset
338 comment_data = {"content_rich": body}
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 try:
1322
a0954b6610aa pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
340 await self.host.bridgeCall('mbSend',
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
341 service,
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
342 node,
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
343 data_format.serialise(comment_data),
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
344 profile)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 except Exception as e:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
346 if "forbidden" in str(e):
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 self.pageError(request, 401)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 else:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 raise e
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1207
diff changeset
351 log.warning(_("Unhandled data type: {}").format(type_))