Mercurial > libervia-web
annotate libervia/pages/lists/view/page_meta.py @ 1470:837ae0c4b858
pages (lists/view_item): use uppercase for firt letter of Item breadcrumb
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Oct 2021 16:30:05 +0200 |
parents | 4ccf42d8aab7 |
children | d62df81440c6 915c7c2f1729 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
967 | 3 from sat.tools.common import template_xmlui |
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 | 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 | 11 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
12 name = "lists" |
967 | 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 | 15 |
16 | |
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 | 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 | 23 if node == "@": |
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 | 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 | 32 data = self.getRData(request) |
33 template_data = request.template_data | |
1216 | 34 service, node = data["service"], data["node"] |
967 | 35 profile = self.getProfile(request) or C.SERVICE_PROFILE |
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 |
1389
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
39 try: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
40 lists_types = self.getPageData(request, "lists_types") |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
41 if lists_types is None: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
42 lists_types = {} |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
43 self.setPageData(request, "lists_types", lists_types) |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
44 list_type = lists_types[(service, node)] |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
45 except KeyError: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
46 ns_tickets_type = self.host.ns_map["tickets_type"] |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
47 schema_raw = await self.host.bridgeCall( |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
48 "psSchemaDictGet", |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
49 service.full(), |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
50 node or self.host.ns_map["tickets"], |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
51 profile |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
52 ) |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
53 schema = data_format.deserialise(schema_raw) |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
54 try: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
55 list_type_field = next( |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
56 f for f in schema["fields"] if f["type"] == "hidden" |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
57 and f.get("name") == ns_tickets_type |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
58 ) |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
59 except StopIteration: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
60 list_type = lists_types[(service, node)] = None |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
61 else: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
62 if list_type_field.get("value") is None: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
63 list_type = None |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
64 else: |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
65 list_type = list_type_field["value"].lower().strip() |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
66 lists_types[(service, node)] = list_type |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
67 |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
68 data["list_type"] = template_data["list_type"] = list_type |
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
69 |
1142
003597f895a0
pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
70 extra = self.getPubsubExtra(request) |
1216 | 71 extra["labels_as_list"] = C.BOOL_TRUE |
1377
46ce79eac754
pages(tickets): add Full-Text Search
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
72 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
|
73 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
74 list_raw = await self.host.bridgeCall( |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
75 "listGet", |
1216 | 76 service.full() if service else "", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
77 node, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
78 C.NO_LIMIT, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
79 [], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
80 "", |
1142
003597f895a0
pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
81 extra, |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
82 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
83 ) |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
84 if profile != C.SERVICE_PROFILE: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
85 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
86 affiliations = await self.host.bridgeCall( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
87 "psNodeAffiliationsGet", |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
88 service.full() if service else "", |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
89 node, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
90 profile |
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 except BridgeException as e: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
93 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
|
94 template_data["owner"] = False |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
95 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
96 is_owner = affiliations.get(self.getJid(request).userhost()) == 'owner' |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
97 template_data["owner"] = is_owner |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
98 if is_owner: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
99 self.exposeToScripts( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
100 request, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
101 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
|
102 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
103 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
104 template_data["owner"] = False |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
105 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
106 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
|
107 template_data["list_items"] = [ |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1377
diff
changeset
|
108 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
|
109 ] |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
110 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
|
111 template_data["on_list_item_click"] = data_objects.OnClick( |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
112 url=f"{view_url}/{{item.id}}" |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
113 ) |
1142
003597f895a0
pages (tickets): use the new getPubsubExtra and setPagination methods to handle pagination
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
114 self.setPagination(request, metadata) |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
115 self.exposeToScripts( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
116 request, |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
117 lists_ns=self.host.ns_map["tickets"], |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
118 pubsub_service=service.full(), |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
119 pubsub_node=node, |
1389
ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
120 list_type=list_type, |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
121 ) |
1395
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
122 |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
123 |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
124 async def on_data_post(self, request): |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
125 data = self.getRData(request) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
126 profile = self.getProfile(request) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
127 service = data["service"] |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
128 node = data["node"] |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
129 list_type = self.getPostedData(request, ("type",)) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
130 if list_type == "grocery": |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
131 name, quantity = self.getPostedData(request, ("name", "quantity")) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
132 if not name: |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
133 self.pageError(request, C.HTTP_BAD_REQUEST) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
134 item_data = { |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
135 "name": [name], |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
136 } |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
137 if quantity: |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
138 item_data["quantity"] = [quantity] |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
139 await self.host.bridgeCall( |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
140 "listSet", service.full(), node, item_data, "", "", "", profile |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
141 ) |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
142 return C.POST_NO_CONFIRM |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
143 else: |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
144 raise NotImplementedError( |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
145 f"Can't use quick list item set for list of type {list_type!r}" |
4ccf42d8aab7
browser (lists/view): `grocery` list specialised behaviour:
Goffi <goffi@goffi.org>
parents:
1389
diff
changeset
|
146 ) |