Mercurial > libervia-web
annotate libervia/pages/lists/view_item/page_meta.py @ 1427:eaf36fffcbdb
pages (forums): better breadcrumbs
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 19:05:16 +0200 |
parents | a84383c659b4 |
children | 907f519faaf0 8ac062d2ff8b |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
3 from twisted.words.protocols.jabber import jid |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
4 from sat.core.i18n import _ |
967 | 5 from sat.tools.common import template_xmlui |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
6 from sat.tools.common import uri |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
7 from sat.tools.common import data_format |
967 | 8 from sat.core.log import getLogger |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
9 from sat_frontends.bridge.bridge_frontend import BridgeException |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
10 from libervia.server.constants import Const as C |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
11 from libervia.server.utils import SubPage |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
12 from libervia.server import session_iface |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
13 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1142
diff
changeset
|
14 log = getLogger(__name__) |
967 | 15 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
16 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
17 name = "list_view" |
967 | 18 access = C.PAGES_ACCESS_PUBLIC |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
19 template = "list/item.html" |
967 | 20 |
21 | |
22 def parse_url(self, request): | |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
23 self.getPathArgs(request, ["service", "node", "item_id"], service="jid", node="@") |
1078
296bda6b7ed0
pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
1043
diff
changeset
|
24 data = self.getRData(request) |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
25 if data["item_id"] is None: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
26 log.warning(_("no list item id specified")) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
27 self.pageError(request, C.HTTP_BAD_REQUEST) |
967 | 28 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
29 async def prepare_render(self, request): |
967 | 30 data = self.getRData(request) |
31 template_data = request.template_data | |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
32 session = self.host.getSessionData(request, session_iface.ISATSession) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
33 service, node, item_id = ( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
34 data.get("service", ""), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
35 data.get("node", ""), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
36 data["item_id"], |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
37 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
38 profile = self.getProfile(request) |
967 | 39 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
40 if profile is None: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
41 profile = C.SERVICE_PROFILE |
1142
003597f895a0
pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
42 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
43 list_raw = await self.host.bridgeCall( |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
44 "listGet", |
1216 | 45 service.full() if service else "", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
46 node, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
47 C.NO_LIMIT, |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
48 [item_id], |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
49 "", |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
50 {"labels_as_list": C.BOOL_TRUE}, |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
51 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
52 ) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
53 list_items, metadata = data_format.deserialise(list_raw, type_check=list) |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
54 list_item = [template_xmlui.create(self.host, x) for x in list_items][0] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
55 template_data["item"] = list_item |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
56 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
57 comments_uri = list_item.widgets["comments_uri"].value |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
58 except KeyError: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
59 pass |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
60 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
61 if comments_uri: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
62 uri_data = uri.parseXMPPUri(comments_uri) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
63 template_data["comments_node"] = comments_node = uri_data["node"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
64 template_data["comments_service"] = comments_service = uri_data["path"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
65 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
66 comments = data_format.deserialise(await self.host.bridgeCall( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
68 )) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
69 except BridgeException as e: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
70 if e.classname == 'NotFound' or e.condition == 'item-not-found': |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
71 log.warning( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
72 _("Can't find comment node at [{service}] {node!r}") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
73 .format(service=comments_service, node=comments_node) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
74 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
75 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
76 raise e |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
77 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
78 template_data["comments"] = comments |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
79 template_data["login_url"] = self.getPageRedirectURL(request) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
80 self.exposeToScripts( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
81 request, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
82 comments_node=comments_node, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
83 comments_service=comments_service, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
84 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
85 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
86 if session.connected: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
87 # we activate modification action (edit, delete) only if user is the publisher or |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
88 # the node owner |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
89 publisher = jid.JID(list_item.widgets["publisher"].value) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
90 is_publisher = publisher.userhostJID() == session.jid.userhostJID() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
91 affiliation = None |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
92 if not is_publisher: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
93 node = node or self.host.ns_map["tickets"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
94 affiliation = await self.host.getAffiliation(request, service, node) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
95 if is_publisher or affiliation == "owner": |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
96 self.exposeToScripts( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
97 request, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
98 pubsub_service = service.full(), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
99 pubsub_node = node, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
100 pubsub_item = item_id, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
101 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
102 template_data["can_modify"] = True |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
103 template_data["url_list_item_edit"] = self.getURLByPath( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
104 SubPage("list_edit"), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
105 service.full(), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
106 node or "@", |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
107 item_id, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
108 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
109 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
110 # we add xmpp: URI |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
111 uri_args = {'path': service.full()} |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
112 uri_args['node'] = node or self.host.ns_map["tickets"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
113 if item_id: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
114 uri_args['item'] = item_id |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
115 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
116 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
117 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
118 async def on_data_post(self, request): |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
119 type_ = self.getPostedData(request, "type") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
120 if type_ == "comment": |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
121 blog_page = self.getPageByName("blog_view") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
122 await blog_page.on_data_post(self, request) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
123 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
124 log.warning(_("Unhandled data type: {}").format(type_)) |