Mercurial > libervia-web
annotate libervia/web/pages/blog/view/page_meta.py @ 1611:b695b98851fc
pages (events/new): use coroutines.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Jun 2024 23:09:49 +0200 |
parents | eb00d593801d |
children |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1229
acec8e9185db
pages: replaced deprecated `cgi.escape` by `html.escape`
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
3 import html |
1493
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
4 from typing import Any, Dict, Optional |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
5 |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
6 from libervia.backend.core.i18n import D_, _ |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
7 from libervia.backend.core.log import getLogger |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
8 from libervia.backend.tools.common import uri |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
9 from libervia.backend.tools.common import data_format |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
10 from libervia.backend.tools.common import regex |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
11 from libervia.backend.tools.common.template import safe |
1493
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
12 from twisted.web import server |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
13 from twisted.words.protocols.jabber import jid |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
14 |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
15 from libervia.web.server import utils |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
16 from libervia.web.server.constants import Const as C |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
17 from libervia.web.server.utils import SubPage |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
18 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
19 log = getLogger(__name__) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 """generic blog (with service/node provided)""" |
1216 | 22 name = 'blog_view' |
23 template = "blog/articles.html" | |
24 uri_handlers = {('pubsub', 'microblog'): 'microblog_uri'} | |
1077
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 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
|
27 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 def microblog_uri(self, uri_data): |
1216 | 30 args = [uri_data['path'], uri_data['node']] |
31 if 'item' in uri_data: | |
32 args.extend(['id', uri_data['item']]) | |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
33 return self.get_url(*args) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 def parse_url(self, request): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 """URL is /[service]/[node]/[filter_keyword]/[item]|[other] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 if [node] is '@', default namespace is used |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 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
|
40 keyword can be one of: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 id: next value is a item id |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 tag: next value is a blog tag |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 """ |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
44 data = self.get_r_data(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
47 service = self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 except IndexError: |
1216 | 49 data['service'] = '' |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 try: |
1216 | 52 data["service"] = jid.JID(service) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 except Exception: |
1216 | 54 log.warning(_("bad service entered: {}").format(service)) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
55 self.page_error(request, C.HTTP_BAD_REQUEST) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
58 node = self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 except IndexError: |
1216 | 60 node = '@' |
61 data['node'] = '' if node == '@' else node | |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
64 filter_kw = data['filter_keyword'] = self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 except IndexError: |
1216 | 66 filter_kw = '@' |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 else: |
1216 | 68 if filter_kw == '@': |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
69 # 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
|
70 pass |
1216 | 71 elif filter_kw == 'id': |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
73 data['item'] = self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 except IndexError: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
75 self.page_error(request, C.HTTP_BAD_REQUEST) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 # 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
|
77 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
78 self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 except IndexError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 pass |
1216 | 81 elif filter_kw == 'tag': |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
83 data['tag'] = self.next_path(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 except IndexError: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
85 self.page_error(request, C.HTTP_BAD_REQUEST) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 # invalid filter keyword |
1216 | 88 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
|
89 filter_kw=filter_kw)) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
90 self.page_error(request, C.HTTP_BAD_REQUEST) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
92 # 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
|
93 # add the link to the page |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
94 atom_url = self.get_url_by_path( |
1216 | 95 SubPage('blog_view'), |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
96 service, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
97 node, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
98 filter_kw, |
1216 | 99 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
|
100 ) |
1216 | 101 request.template_data['atom_url'] = atom_url |
102 request.template_data.setdefault('links', []).append({ | |
103 "href": atom_url, | |
104 "type": "application/atom+xml", | |
105 "rel": "alternate", | |
106 "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
|
107 |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
1419
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
109 def add_breadcrumb(self, request, breadcrumbs): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
110 data = self.get_r_data(request) |
1419
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
111 breadcrumbs.append({ |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
112 "label": D_("Feed"), |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
113 "url": self.get_url(data["service"].full(), data.get("node", "@")) |
1419
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
114 }) |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
115 if "item" in data: |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
116 breadcrumbs.append({ |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
117 "label": D_("Post"), |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
118 }) |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
119 |
6fc41f000d24
pages (blog/view, u, files/list): custom breadcrumbs:
Goffi <goffi@goffi.org>
parents:
1406
diff
changeset
|
120 |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
121 async def append_comments( |
1493
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
122 self, |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
123 request: server.Request, |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
124 blog_items: dict, |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
125 profile: str, |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
126 _seen: Optional[set] = None |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
127 ) -> None: |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
128 """Recursively download and append comments of items |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
129 |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
130 @param blog_items: items data |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
131 @param profile: Libervia profile |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
132 @param _seen: used to avoid infinite recursion. For internal use only |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
133 """ |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
134 if _seen is None: |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
135 _seen = set() |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
136 await self.fill_missing_identities( |
1322
a0954b6610aa
pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
137 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
|
138 extra: Dict[str, Any] = {C.KEY_ORDER_BY: C.ORDER_BY_CREATION} |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
139 if not self.use_cache(request): |
1491
3002ea1d6ae9
pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents:
1483
diff
changeset
|
140 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
|
141 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
|
142 for comment_data in blog_item['comments']: |
1216 | 143 service = comment_data['service'] |
144 node = comment_data['node'] | |
1493
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
145 service_node = (service, node) |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
146 if service_node in _seen: |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
147 log.warning( |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
148 f"Items from {node!r} at {service} have already been retrieved, " |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
149 "there is a recursion at this service" |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
150 ) |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
151 comment_data["items"] = [] |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
152 continue |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
153 else: |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
154 _seen.add(service_node) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
156 comments_data = await self.host.bridge_call('mb_get', |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 service, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 node, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 C.NO_LIMIT, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 [], |
1447
907f519faaf0
pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
161 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
|
162 extra |
1447
907f519faaf0
pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
163 ), |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 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
|
166 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
|
167 _("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
|
168 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
|
169 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
|
170 msg=e)) |
1403
1357d04107d1
pages (blog/view): set empty comments when comments node is missing
Goffi <goffi@goffi.org>
parents:
1376
diff
changeset
|
171 comment_data['items'] = [] |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 continue |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
174 comments = data_format.deserialise(comments_data) |
1493
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
175 if comments is None: |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
176 log.error(f"Comments should not be None: {comment_data}") |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
177 comment_data["items"] = [] |
1702b8c821c4
pages (blog/view): avoid infinite recursion when comment nodes are making a loop
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
178 continue |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
179 comment_data['items'] = comments['items'] |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
180 await append_comments(self, request, comments, profile, _seen=_seen) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
182 async def get_blog_items( |
1466
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
183 self, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
184 request: server.Request, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
185 service: jid.JID, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
186 node: str, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
187 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
|
188 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
|
189 profile: str |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
190 ) -> dict: |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 items_id = [item_id] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 items_id = [] |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
196 if not self.use_cache(request): |
1491
3002ea1d6ae9
pages (blog/view): don't use backend cache when "no cache" is requested
Goffi <goffi@goffi.org>
parents:
1483
diff
changeset
|
197 extra[C.KEY_USE_CACHE] = False |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
198 blog_data = await self.host.bridge_call('mb_get', |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 service.userhost(), |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 node, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 C.NO_LIMIT, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 items_id, |
1447
907f519faaf0
pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
203 data_format.serialise(extra), |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 except Exception as e: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 # FIXME: need a better way to test errors in bridge errback |
1216 | 207 if "forbidden" in str(e): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
208 self.page_error(request, 401) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 else: |
1216 | 210 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
|
211 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
|
212 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
|
213 else: |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
214 blog_data = data_format.deserialise(blog_data) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
1322
a0954b6610aa
pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
216 return blog_data |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 |
1322
a0954b6610aa
pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
218 async def prepare_render(self, request): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
219 data = self.get_r_data(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
|
220 template_data = request.template_data |
1216 | 221 page_max = data.get("page_max", 10) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 # 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 ) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
229 profile = self.get_profile(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 if profile is None: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 profile = C.SERVICE_PROFILE |
1133
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
232 profile_connected = False |
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
233 else: |
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
234 profile_connected = True |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 ## pagination/filtering parameters |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 extra = {} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 else: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
240 extra = self.get_pubsub_extra(request, page_max=page_max) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 tag = data.get('tag') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 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
|
243 extra[f'mam_filter_{C.MAM_FILTER_CATEGORY}'] = tag |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
244 self.handle_search(request, extra) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 ## main data ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 # we get data from backend/XMPP here |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
248 blog_items = await get_blog_items(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
|
249 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 ## navigation ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 # no let's fill service, node and pagination URLs |
1216 | 252 if 'service' not in template_data: |
253 template_data['service'] = service | |
254 if 'node' not in template_data: | |
255 template_data['node'] = node | |
256 target_profile = template_data.get('target_profile') | |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
258 if blog_items: |
1466
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
259 if item_id: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
260 template_data["previous_page_url"] = self.get_url( |
1466
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
261 service.full(), |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
262 node, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
263 before=item_id, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
264 page_max=1 |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
265 ) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
266 template_data["next_page_url"] = self.get_url( |
1466
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
267 service.full(), |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
268 node, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
269 after=item_id, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
270 page_max=1 |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
271 ) |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
272 blog_items["rsm"] = { |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
273 "last": item_id, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
274 "first": item_id, |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
275 } |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
276 blog_items["complete"] = False |
cff720e26089
pages (blog/view): activate pagination when a single item is shown:
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
277 else: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
278 self.set_pagination(request, blog_items) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 # 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
|
282 # we must return an error |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
283 self.page_error(request, C.HTTP_NOT_FOUND) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 ## identities ## |
1133
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
286 # identities are used to show nice nickname or avatars |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
287 await self.fill_missing_identities(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
|
288 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 ## Comments ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 # 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
|
291 if show_comments: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
292 await append_comments(self, request, blog_items, profile) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 ## URLs ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 # 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
|
296 # 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
|
297 if target_profile is None: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
298 blog_base_url_item = self.get_page_by_name('blog_view').get_url(service.full(), node or '@', 'id') |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
299 blog_base_url_tag = self.get_page_by_name('blog_view').get_url(service.full(), node or '@', 'tag') |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 else: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
301 blog_base_url_item = self.get_url_by_names([('user', [target_profile]), ('user_blog', ['id'])]) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
302 blog_base_url_tag = self.get_url_by_names([('user', [target_profile]), ('user_blog', ['tag'])]) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 # we also set the background image if specified by user |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
304 bg_img = await self.host.bridge_call('param_get_a_async', '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
|
305 if bg_img: |
1216 | 306 template_data['dynamic_style'] = safe(""" |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 :root { |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 --bg-img: url("%s"); |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 } |
1229
acec8e9185db
pages: replaced deprecated `cgi.escape` by `html.escape`
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
310 """ % html.escape(bg_img, True)) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
312 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
|
313 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
|
314 template_data['blog_items'].items.reverse() |
1216 | 315 template_data['items_http_uri'] = items_http_uri = {} |
316 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
|
317 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
319 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
|
320 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
|
321 if len(blog_canonical_url) > URL_LIMIT_MARK: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 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
|
323 elif '-' not in item['id']: |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 # 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
|
325 # 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
|
326 # 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
|
327 # 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
|
328 # 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
|
329 # user friendly item IDs are more common. |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
330 text = regex.url_friendly_text(item.get('title', item['content'])) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 if text: |
1216 | 332 blog_url = blog_canonical_url + '/' + text |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 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
|
335 else: |
cffa3ae4d0aa
pages (blog/view): move URL friendly code to backend tools:
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
336 blog_url = blog_canonical_url |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
338 items_http_uri[item['id']] = self.host.get_ext_base_url(request, blog_url) |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
339 for tag in item['tags']: |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 if tag not in tags_http_uri: |
1216 | 341 tag_url = '/'.join([blog_base_url_tag, utils.quote(tag)]) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
342 tags_http_uri[tag] = self.host.get_ext_base_url(request, tag_url) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 # if True, page should display a comment box |
1216 | 345 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
|
346 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 # last but not least, we add a xmpp: link to the node |
1216 | 348 uri_args = {'path': service.full()} |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 if node: |
1216 | 350 uri_args['node'] = node |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 if item_id: |
1216 | 352 uri_args['item'] = item_id |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
353 template_data['xmpp_uri'] = uri.build_xmpp_uri( |
1478
10ccad665d57
pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents:
1466
diff
changeset
|
354 'pubsub', subtype='microblog', **uri_args |
10ccad665d57
pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents:
1466
diff
changeset
|
355 ) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 |
1322
a0954b6610aa
pages: identities are not using `data_objects` anymore:
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
358 async def on_data_post(self, request): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
359 profile = self.get_profile(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 if profile is None: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
361 self.page_error(request, C.HTTP_FORBIDDEN) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
362 type_ = self.get_posted_data(request, 'type') |
1216 | 363 if type_ == 'comment': |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
364 service, node, body = self.get_posted_data(request, ('service', 'node', 'body')) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 if not body: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
367 self.page_error(request, C.HTTP_BAD_REQUEST) |
1478
10ccad665d57
pages (blog/view): use rich content for comments
Goffi <goffi@goffi.org>
parents:
1466
diff
changeset
|
368 comment_data = {"content_rich": body} |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
370 await self.host.bridge_call('mb_send', |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
371 service, |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
372 node, |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
373 data_format.serialise(comment_data), |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
374 profile) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 except Exception as e: |
1216 | 376 if "forbidden" in str(e): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
377 self.page_error(request, 401) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 raise e |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 else: |
1216 | 381 log.warning(_("Unhandled data type: {}").format(type_)) |