annotate libervia/pages/lists/view_item/page_meta.py @ 1483:595e7fef41f3

merge bookmark @
author Goffi <goffi@goffi.org>
date Fri, 12 Nov 2021 17:48:30 +0100
parents 907f519faaf0 837ae0c4b858
children 3a34d78f2717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
3 from twisted.words.protocols.jabber import jid
1468
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
4 from sat.core.i18n import _, D_
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
1468
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
29
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
30 def add_breadcrumb(self, request, breadcrumbs):
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
31 data = self.getRData(request)
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
32 list_url = self.getPageByName("lists").getURL(data["service"].full(),
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
33 data.get("node") or "@")
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
34 breadcrumbs.append({
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
35 "label": D_("List"),
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
36 "url": list_url
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
37 })
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
38 breadcrumbs.append({
1470
837ae0c4b858 pages (lists/view_item): use uppercase for firt letter of Item breadcrumb
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
39 "label": D_("Item"),
1468
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
40 })
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
41
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
42
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
43 async def prepare_render(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 data = self.getRData(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 template_data = request.template_data
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
46 session = self.host.getSessionData(request, session_iface.ISATSession)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
47 service, node, item_id = (
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
48 data.get("service", ""),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
49 data.get("node", ""),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
50 data["item_id"],
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
51 )
1461
8ac062d2ff8b pages(lists/view_item): fix node used:
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
52 namespace = node or self.host.ns_map["tickets"]
8ac062d2ff8b pages(lists/view_item): fix node used:
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
53 node = await self.host.bridgeCall("psSchemaSubmittedNodeGet", namespace)
8ac062d2ff8b pages(lists/view_item): fix node used:
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
54
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
55 profile = self.getProfile(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
56 if profile is None:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
57 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
58
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
59 list_raw = await self.host.bridgeCall(
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
60 "listGet",
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
61 service.full() if service else "",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
62 node,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
63 C.NO_LIMIT,
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
64 [item_id],
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
65 "",
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
66 {"labels_as_list": C.BOOL_TRUE},
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
67 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
68 )
1468
e85ef5f3515e pages (lists/view_item): add current list to breadcrumbs
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
69 list_items, __ = data_format.deserialise(list_raw, type_check=list)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
70 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
71 template_data["item"] = list_item
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
72 try:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
73 comments_uri = list_item.widgets["comments_uri"].value
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
74 except KeyError:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
75 pass
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
76 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
77 if comments_uri:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
78 uri_data = uri.parseXMPPUri(comments_uri)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
79 template_data["comments_node"] = comments_node = uri_data["node"]
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
80 template_data["comments_service"] = comments_service = uri_data["path"]
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
81 try:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
82 comments = data_format.deserialise(await self.host.bridgeCall(
1447
907f519faaf0 pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
83 "mbGet", comments_service, comments_node, C.NO_LIMIT, [],
907f519faaf0 pages: pubsub's `extra` is now serialised, following backend change
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
84 data_format.serialise({}), profile
1387
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 except BridgeException as e:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
87 if e.classname == 'NotFound' or e.condition == 'item-not-found':
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
88 log.warning(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
89 _("Can't find comment node at [{service}] {node!r}")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
90 .format(service=comments_service, node=comments_node)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
91 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
92 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
93 raise e
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
94 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
95 template_data["comments"] = comments
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
96 template_data["login_url"] = self.getPageRedirectURL(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
97 self.exposeToScripts(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
98 request,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
99 comments_node=comments_node,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
100 comments_service=comments_service,
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
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
103 if session.connected:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
104 # 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
105 # the node owner
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
106 publisher = jid.JID(list_item.widgets["publisher"].value)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
107 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
108 affiliation = None
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
109 if not is_publisher:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
110 affiliation = await self.host.getAffiliation(request, service, node)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
111 if is_publisher or affiliation == "owner":
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
112 self.exposeToScripts(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
113 request,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
114 pubsub_service = service.full(),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
115 pubsub_node = node,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
116 pubsub_item = item_id,
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 template_data["can_modify"] = True
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
119 template_data["url_list_item_edit"] = self.getURLByPath(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
120 SubPage("list_edit"),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
121 service.full(),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
122 node or "@",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
123 item_id,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
124 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
125
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
126 # we add xmpp: URI
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
127 uri_args = {'path': service.full()}
1461
8ac062d2ff8b pages(lists/view_item): fix node used:
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
128 uri_args['node'] = node
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
129 if item_id:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
130 uri_args['item'] = item_id
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
131 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
132
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
133
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
134 async def on_data_post(self, request):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
135 type_ = self.getPostedData(request, "type")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
136 if type_ == "comment":
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
137 blog_page = self.getPageByName("blog_view")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
138 await blog_page.on_data_post(self, request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
139 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
140 log.warning(_("Unhandled data type: {}").format(type_))