annotate libervia/pages/lists/view/page_meta.py @ 1387:a84383c659b4

lists: creation, invitation, item deletion: this big patch includes: - reorganisation of pages for consistency, discovery is now the main list page, and list overview is now in `view` while item view is moved to `view_item` - lists from lists of interest are now shown in discovery page - list deletion from discory page - list can now be created, using templates now available from backend - invitation manager can now be used from list overview - list item can now be deleted from `view_item`
author Goffi <goffi@goffi.org>
date Sat, 20 Feb 2021 14:07:22 +0100
parents libervia/pages/lists/page_meta.py@e3e303a30a74
children ac4173fff71d
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
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from sat.tools.common import template_xmlui
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.tools.common import data_objects
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
5 from sat.tools.common import data_format
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
7 from sat_frontends.bridge.bridge_frontend import BridgeException
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
8 from libervia.server.constants import Const as C
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
9
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1142
diff changeset
10 log = getLogger(__name__)
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
12 name = "lists"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PUBLIC
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
14 template = "list/overview.html"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 def parse_url(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
18 self.getPathArgs(request, ["service", "node"], service="jid")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
19 data = self.getRData(request)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
20 service, node = data["service"], data["node"]
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
21 if node is None:
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
22 self.HTTPRedirect(request, self.getPageByName("lists_disco").url)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
23 if node == "@":
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
24 node = data["node"] = ""
973
2e75dc986e03 pages (tickets): URLs for list and new are set in the template for the whole subhierarchy
Goffi <goffi@goffi.org>
parents: 967
diff changeset
25 template_data = request.template_data
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
26 template_data["url_list_items"] = self.getURL(service.full(), node or "@")
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
27 template_data["url_list_new"] = self.getPageByName("list_new").getURL(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
28 service.full(), node or "@")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
29
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
31 async def prepare_render(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 data = self.getRData(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 template_data = request.template_data
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
34 service, node = data["service"], data["node"]
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 profile = self.getProfile(request) or C.SERVICE_PROFILE
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
37 self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short="tickets")
1021
b39c527f208c pages (tickets): check cache in prepare_render instead of parse_url
Goffi <goffi@goffi.org>
parents: 1007
diff changeset
38
1142
003597f895a0 pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
39 extra = self.getPubsubExtra(request)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
40 extra["labels_as_list"] = C.BOOL_TRUE
1377
46ce79eac754 pages(tickets): add Full-Text Search
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
41 self.handleSearch(request, extra)
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
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
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,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
48 [],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
49 "",
1142
003597f895a0 pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
50 extra,
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 )
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
53 if profile != C.SERVICE_PROFILE:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
54 try:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
55 affiliations = await self.host.bridgeCall(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
56 "psNodeAffiliationsGet",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
57 service.full() if service else "",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
58 node,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
59 profile
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
60 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
61 except BridgeException as e:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
62 log.warning(f"Can't get affiliations for node {node!r} at {service}: {e}")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
63 template_data["owner"] = False
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
64 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
65 is_owner = affiliations.get(self.getJid(request).userhost()) == 'owner'
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
66 template_data["owner"] = is_owner
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
67 if is_owner:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
68 self.exposeToScripts(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
69 request,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
70 affiliations={str(e): str(a) for e, a in affiliations.items()}
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
71 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
72 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
73 template_data["owner"] = False
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
74
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
75 list_items, metadata = data_format.deserialise(list_raw, type_check=list)
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
76 template_data["list_items"] = [
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
77 template_xmlui.create(self.host, x) for x in list_items
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
78 ]
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
79 view_url = self.getPageByName('list_view').getURL(service.full(), node or '@')
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1377
diff changeset
80 template_data["on_list_item_click"] = data_objects.OnClick(
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
81 url=f"{view_url}/{{item.id}}"
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
82 )
1142
003597f895a0 pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
83 self.setPagination(request, metadata)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
84 self.exposeToScripts(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
85 request,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
86 lists_ns=self.host.ns_map["tickets"],
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
87 pubsub_service=service.full(),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
88 pubsub_node=node,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
89 )