Mercurial > libervia-web
annotate libervia/pages/lists/page_meta.py @ 1463:2c8449885272
pages: query parameters can now be specified using keyword arguments in `getURL:`
rel: 399
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 30 Sep 2021 16:57:54 +0200 |
parents | d6bcb0cf92d2 |
children | 106bae41f5c8 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1078 | 3 from libervia.server.constants import Const as C |
4 from twisted.words.protocols.jabber import jid | |
1418 | 5 from sat.core.i18n import _, D_ |
1078 | 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.tools.common import data_format |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
8 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
9 log = getLogger(__name__) |
1078 | 10 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
11 name = "lists_disco" |
1418 | 12 label = D_("Lists Discovery") |
1078 | 13 access = C.PAGES_ACCESS_PUBLIC |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
14 template = "list/discover.html" |
1078 | 15 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
16 async def prepare_render(self, request): |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
17 profile = self.getProfile(request) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
18 template_data = request.template_data |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
19 template_data["url_list_create"] = self.getPageByName("list_create").url |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
20 lists_directory_config = self.host.options["lists_directory_json"] |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
21 lists_directory = request.template_data["lists_directory"] = [] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
22 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
23 if lists_directory_config: |
1078 | 24 try: |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
25 for list_data in lists_directory_config: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
26 service = list_data["service"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
27 node = list_data["node"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
28 name = list_data["name"] |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
29 url = self.getPageByName("lists").getURL(service, node) |
1388
68ffd60a58a5
pages (lists): specify when item is coming from config
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
30 lists_directory.append({"name": name, "url": url, "from_config": True}) |
1078 | 31 except KeyError as e: |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
32 log.warning("Missing field in lists_directory_json: {msg}".format(msg=e)) |
1078 | 33 except Exception as e: |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
34 log.warning("Can't decode lists directory: {msg}".format(msg=e)) |
1078 | 35 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
36 if profile is not None: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
37 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
38 lists_list_raw = await self.host.bridgeCall("listsList", "", "", profile) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
39 except Exception as e: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
40 log.warning( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
41 _("Can't get list of registered lists for {profile}: {reason}") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
42 .format(profile=profile, reason=e) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
43 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
44 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
45 lists_list = data_format.deserialise(lists_list_raw, type_check=list) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
46 for list_data in lists_list: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
47 service = list_data["service"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
48 node = list_data["node"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
49 list_data["url"] = self.getPageByName("lists").getURL(service, node) |
1388
68ffd60a58a5
pages (lists): specify when item is coming from config
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
50 list_data["from_config"] = False |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
51 lists_directory.append(list_data) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
52 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
53 icons_names = set() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
54 for list_data in lists_directory: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
55 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
56 icons_names.add(list_data['icon_name']) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
57 except KeyError: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
58 pass |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
59 if icons_names: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
60 template_data["icons_names"] = icons_names |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
61 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
62 |
1078 | 63 def on_data_post(self, request): |
1216 | 64 jid_str = self.getPostedData(request, "jid") |
1078 | 65 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
66 jid_ = jid.JID(jid_str) |
1078 | 67 except RuntimeError: |
68 self.pageError(request, C.HTTP_BAD_REQUEST) | |
69 # for now we just use default node | |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
70 url = self.getPageByName("lists").getURL(jid_.full(), "@") |
1078 | 71 self.HTTPRedirect(request, url) |