Mercurial > libervia-web
annotate libervia/pages/lists/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/disco/page_meta.py@e3e303a30a74 |
children | 68ffd60a58a5 |
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) |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
29 lists_directory.append({"name": name, "url": url}) |
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) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
49 lists_directory.append(list_data) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
50 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
51 icons_names = set() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
52 for list_data in lists_directory: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
53 try: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
54 icons_names.add(list_data['icon_name']) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
55 except KeyError: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
56 pass |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
57 if icons_names: |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
58 template_data["icons_names"] = icons_names |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
59 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
60 |
1078 | 61 def on_data_post(self, request): |
1216 | 62 jid_str = self.getPostedData(request, "jid") |
1078 | 63 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
64 jid_ = jid.JID(jid_str) |
1078 | 65 except RuntimeError: |
66 self.pageError(request, C.HTTP_BAD_REQUEST) | |
67 # for now we just use default node | |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
68 url = self.getPageByName("lists").getURL(jid_.full(), "@") |
1078 | 69 self.HTTPRedirect(request, url) |