comparison 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
comparison
equal deleted inserted replaced
1386:83be300d17e3 1387:a84383c659b4
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 from libervia.server.constants import Const as C 3 from libervia.server.constants import Const as C
4 from sat.tools.common import template_xmlui 4 from twisted.words.protocols.jabber import jid
5 from sat.tools.common import data_objects 5 from sat.core.i18n import _
6 from sat.core.log import getLogger
6 from sat.tools.common import data_format 7 from sat.tools.common import data_format
7 from sat.core.log import getLogger
8 8
9 log = getLogger(__name__) 9 log = getLogger(__name__)
10 10
11 name = "lists" 11 name = "lists_disco"
12 access = C.PAGES_ACCESS_PUBLIC 12 access = C.PAGES_ACCESS_PUBLIC
13 template = "list/overview.html" 13 template = "list/discover.html"
14
15 async def prepare_render(self, request):
16 profile = self.getProfile(request)
17 template_data = request.template_data
18 template_data["url_list_create"] = self.getPageByName("list_create").url
19 lists_directory_config = self.host.options["lists_directory_json"]
20 lists_directory = request.template_data["lists_directory"] = []
21
22 if lists_directory_config:
23 try:
24 for list_data in lists_directory_config:
25 service = list_data["service"]
26 node = list_data["node"]
27 name = list_data["name"]
28 url = self.getPageByName("lists").getURL(service, node)
29 lists_directory.append({"name": name, "url": url})
30 except KeyError as e:
31 log.warning("Missing field in lists_directory_json: {msg}".format(msg=e))
32 except Exception as e:
33 log.warning("Can't decode lists directory: {msg}".format(msg=e))
34
35 if profile is not None:
36 try:
37 lists_list_raw = await self.host.bridgeCall("listsList", "", "", profile)
38 except Exception as e:
39 log.warning(
40 _("Can't get list of registered lists for {profile}: {reason}")
41 .format(profile=profile, reason=e)
42 )
43 else:
44 lists_list = data_format.deserialise(lists_list_raw, type_check=list)
45 for list_data in lists_list:
46 service = list_data["service"]
47 node = list_data["node"]
48 list_data["url"] = self.getPageByName("lists").getURL(service, node)
49 lists_directory.append(list_data)
50
51 icons_names = set()
52 for list_data in lists_directory:
53 try:
54 icons_names.add(list_data['icon_name'])
55 except KeyError:
56 pass
57 if icons_names:
58 template_data["icons_names"] = icons_names
14 59
15 60
16 def parse_url(self, request): 61 def on_data_post(self, request):
17 self.getPathArgs(request, ["service", "node"], service="jid") 62 jid_str = self.getPostedData(request, "jid")
18 data = self.getRData(request) 63 try:
19 service, node = data["service"], data["node"] 64 jid_ = jid.JID(jid_str)
20 if node is None: 65 except RuntimeError:
21 self.pageRedirect("lists_disco", request) 66 self.pageError(request, C.HTTP_BAD_REQUEST)
22 if node == "@": 67 # for now we just use default node
23 node = data["node"] = "" 68 url = self.getPageByName("lists").getURL(jid_.full(), "@")
24 template_data = request.template_data 69 self.HTTPRedirect(request, url)
25 template_data["url_list_items"] = self.getURL(service.full(), node or "@")
26 template_data["url_list_new"] = self.getSubPageURL(request, "list_new")
27
28
29 async def prepare_render(self, request):
30 data = self.getRData(request)
31 template_data = request.template_data
32 service, node = data["service"], data["node"]
33 profile = self.getProfile(request) or C.SERVICE_PROFILE
34
35 self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short="tickets")
36
37 extra = self.getPubsubExtra(request)
38 extra["labels_as_list"] = C.BOOL_TRUE
39 self.handleSearch(request, extra)
40
41 list_raw = await self.host.bridgeCall(
42 "listGet",
43 service.full() if service else "",
44 node,
45 C.NO_LIMIT,
46 [],
47 "",
48 extra,
49 profile,
50 )
51 list_items, metadata = data_format.deserialise(list_raw, type_check=list)
52 template_data["list_items"] = [
53 template_xmlui.create(self.host, x) for x in list_items
54 ]
55 template_data["on_list_item_click"] = data_objects.OnClick(
56 url=self.getSubPageURL(request, "list_view") + "/{item.id}"
57 )
58 self.setPagination(request, metadata)