Mercurial > libervia-web
annotate libervia/pages/lists/page_meta.py @ 1407:5a132b85e1ac
browser (invitation): fix an indentation issue which was breaking invitations
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 16 Apr 2021 18:45:44 +0200 |
parents | 68ffd60a58a5 |
children | d6bcb0cf92d2 |
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 | |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
5 from sat.core.i18n import _ |
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" |
1078 | 12 access = C.PAGES_ACCESS_PUBLIC |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
13 template = "list/discover.html" |
1078 | 14 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
15 async def prepare_render(self, request): |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
16 profile = self.getProfile(request) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
17 template_data = request.template_data |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
18 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
|
19 lists_directory_config = self.host.options["lists_directory_json"] |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
20 lists_directory = request.template_data["lists_directory"] = [] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
21 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
22 if lists_directory_config: |
1078 | 23 try: |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
24 for list_data in lists_directory_config: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
25 service = list_data["service"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
26 node = list_data["node"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
27 name = list_data["name"] |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
28 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
|
29 lists_directory.append({"name": name, "url": url, "from_config": True}) |
1078 | 30 except KeyError as e: |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
31 log.warning("Missing field in lists_directory_json: {msg}".format(msg=e)) |
1078 | 32 except Exception as e: |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
33 log.warning("Can't decode lists directory: {msg}".format(msg=e)) |
1078 | 34 |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
35 if profile is not None: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
36 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
37 lists_list_raw = await self.host.bridgeCall("listsList", "", "", profile) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
38 except Exception as e: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
39 log.warning( |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
40 _("Can't get list of registered lists for {profile}: {reason}") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
41 .format(profile=profile, reason=e) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
42 ) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
43 else: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
44 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
|
45 for list_data in lists_list: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
46 service = list_data["service"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
47 node = list_data["node"] |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
48 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
|
49 list_data["from_config"] = False |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
50 lists_directory.append(list_data) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
51 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
52 icons_names = set() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
53 for list_data in lists_directory: |
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 icons_names.add(list_data['icon_name']) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
56 except KeyError: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
57 pass |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
58 if icons_names: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
59 template_data["icons_names"] = icons_names |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
60 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
61 |
1078 | 62 def on_data_post(self, request): |
1216 | 63 jid_str = self.getPostedData(request, "jid") |
1078 | 64 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
65 jid_ = jid.JID(jid_str) |
1078 | 66 except RuntimeError: |
67 self.pageError(request, C.HTTP_BAD_REQUEST) | |
68 # for now we just use default node | |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
69 url = self.getPageByName("lists").getURL(jid_.full(), "@") |
1078 | 70 self.HTTPRedirect(request, url) |