Mercurial > libervia-web
comparison libervia/pages/lists/view/page_meta.py @ 1378:e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
"lists" is more generic, and tickets is actually a specific kind of list.
/!\ "tickets_trackers_json" option has been renamed to "lists_directory_json".
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 28 Jan 2021 18:51:44 +0100 |
parents | libervia/pages/tickets/view/page_meta.py@04e7dd6b6f4d |
children |
comparison
equal
deleted
inserted
replaced
1377:46ce79eac754 | 1378:e3e303a30a74 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 from libervia.server.constants import Const as C | |
5 from sat.core.i18n import _ | |
6 from libervia.server.utils import SubPage | |
7 from libervia.server import session_iface | |
8 from twisted.words.protocols.jabber import jid | |
9 from sat.tools.common import template_xmlui | |
10 from sat.tools.common import uri | |
11 from sat.tools.common import data_format | |
12 from sat.core.log import getLogger | |
13 | |
14 log = getLogger(__name__) | |
15 | |
16 | |
17 name = "list_view" | |
18 access = C.PAGES_ACCESS_PUBLIC | |
19 template = "list/item.html" | |
20 | |
21 | |
22 def parse_url(self, request): | |
23 try: | |
24 item_id = self.nextPath(request) | |
25 except IndexError: | |
26 log.warning(_("no list item id specified")) | |
27 self.pageError(request, C.HTTP_BAD_REQUEST) | |
28 | |
29 data = self.getRData(request) | |
30 data["list_item_id"] = item_id | |
31 | |
32 | |
33 async def prepare_render(self, request): | |
34 data = self.getRData(request) | |
35 template_data = request.template_data | |
36 session = self.host.getSessionData(request, session_iface.ISATSession) | |
37 service, node, list_item_id = ( | |
38 data.get("service", ""), | |
39 data.get("node", ""), | |
40 data["list_item_id"], | |
41 ) | |
42 profile = self.getProfile(request) | |
43 | |
44 if profile is None: | |
45 profile = C.SERVICE_PROFILE | |
46 | |
47 list_raw = await self.host.bridgeCall( | |
48 "listGet", | |
49 service.full() if service else "", | |
50 node, | |
51 C.NO_LIMIT, | |
52 [list_item_id], | |
53 "", | |
54 {"labels_as_list": C.BOOL_TRUE}, | |
55 profile, | |
56 ) | |
57 list_items, metadata = data_format.deserialise(list_raw, type_check=list) | |
58 list_item = [template_xmlui.create(self.host, x) for x in list_items][0] | |
59 template_data["item"] = list_item | |
60 comments_uri = list_item.widgets["comments_uri"].value | |
61 if comments_uri: | |
62 uri_data = uri.parseXMPPUri(comments_uri) | |
63 template_data["comments_node"] = comments_node = uri_data["node"] | |
64 template_data["comments_service"] = comments_service = uri_data["path"] | |
65 comments = data_format.deserialise(await self.host.bridgeCall( | |
66 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile | |
67 )) | |
68 | |
69 template_data["comments"] = comments | |
70 template_data["login_url"] = self.getPageRedirectURL(request) | |
71 | |
72 if session.connected: | |
73 # we set edition URL only if user is the publisher or the node owner | |
74 publisher = jid.JID(list_item.widgets["publisher"].value) | |
75 is_publisher = publisher.userhostJID() == session.jid.userhostJID() | |
76 affiliation = None | |
77 if not is_publisher: | |
78 node = node or self.host.ns_map["tickets"] | |
79 affiliation = await self.host.getAffiliation(request, service, node) | |
80 if is_publisher or affiliation == "owner": | |
81 template_data["url_list_item_edit"] = self.getURLByPath( | |
82 SubPage("lists"), | |
83 service.full(), | |
84 node or "@", | |
85 SubPage("list_edit"), | |
86 list_item_id, | |
87 ) | |
88 | |
89 # we add xmpp: URI | |
90 uri_args = {'path': service.full()} | |
91 uri_args['node'] = node or self.host.ns_map["tickets"] | |
92 if list_item_id: | |
93 uri_args['item'] = list_item_id | |
94 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args) | |
95 | |
96 | |
97 async def on_data_post(self, request): | |
98 type_ = self.getPostedData(request, "type") | |
99 if type_ == "comment": | |
100 blog_page = self.getPageByName("blog_view") | |
101 await blog_page.on_data_post(self, request) | |
102 else: | |
103 log.warning(_("Unhandled data type: {}").format(type_)) |