comparison libervia/web/pages/files/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/files/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.web.server.constants import Const as C
5 from twisted.words.protocols.jabber import jid
6 from libervia.backend.core.log import getLogger
7
8 log = getLogger(__name__)
9 """files handling pages"""
10
11 name = "files"
12 access = C.PAGES_ACCESS_PROFILE
13 template = "file/discover.html"
14
15
16 async def prepare_render(self, request):
17 profile = self.get_profile(request)
18 template_data = request.template_data
19 namespace = self.host.ns_map["fis"]
20 entities_services, entities_own, entities_roster = await self.host.bridge_call(
21 "disco_find_by_features", [namespace], [], False, True, True, True, False, profile
22 )
23 tpl_service_entities = template_data["disco_service_entities"] = {}
24 tpl_own_entities = template_data["disco_own_entities"] = {}
25 tpl_roster_entities = template_data["disco_roster_entities"] = {}
26 entities_url = template_data["entities_url"] = {}
27
28 # we store identities in dict of dict using category and type as keys
29 # this way it's easier to test category in the template
30 for tpl_entities, entities_map in (
31 (tpl_service_entities, entities_services),
32 (tpl_own_entities, entities_own),
33 (tpl_roster_entities, entities_roster),
34 ):
35 for entity_str, entity_ids in entities_map.items():
36 entity_jid = jid.JID(entity_str)
37 tpl_entities[entity_jid] = identities = {}
38 for cat, type_, name in entity_ids:
39 identities.setdefault(cat, {}).setdefault(type_, []).append(name)
40 entities_url[entity_jid] = self.get_page_by_name("files_list").get_url(
41 entity_jid.full()
42 )
43
44
45 def on_data_post(self, request):
46 jid_str = self.get_posted_data(request, "jid")
47 try:
48 jid_ = jid.JID(jid_str)
49 except RuntimeError:
50 self.page_error(request, C.HTTP_BAD_REQUEST)
51 url = self.get_page_by_name("files_list").get_url(jid_.full())
52 self.http_redirect(request, url)