comparison libervia/pages/lists/view_item/page_meta.py @ 1483:595e7fef41f3

merge bookmark @
author Goffi <goffi@goffi.org>
date Fri, 12 Nov 2021 17:48:30 +0100
parents 907f519faaf0 837ae0c4b858
children 3a34d78f2717
comparison
equal deleted inserted replaced
1454:fc91b78b71db 1483:595e7fef41f3
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 from twisted.words.protocols.jabber import jid 3 from twisted.words.protocols.jabber import jid
4 from sat.core.i18n import _ 4 from sat.core.i18n import _, D_
5 from sat.tools.common import template_xmlui 5 from sat.tools.common import template_xmlui
6 from sat.tools.common import uri 6 from sat.tools.common import uri
7 from sat.tools.common import data_format 7 from sat.tools.common import data_format
8 from sat.core.log import getLogger 8 from sat.core.log import getLogger
9 from sat_frontends.bridge.bridge_frontend import BridgeException 9 from sat_frontends.bridge.bridge_frontend import BridgeException
24 data = self.getRData(request) 24 data = self.getRData(request)
25 if data["item_id"] is None: 25 if data["item_id"] is None:
26 log.warning(_("no list item id specified")) 26 log.warning(_("no list item id specified"))
27 self.pageError(request, C.HTTP_BAD_REQUEST) 27 self.pageError(request, C.HTTP_BAD_REQUEST)
28 28
29
30 def add_breadcrumb(self, request, breadcrumbs):
31 data = self.getRData(request)
32 list_url = self.getPageByName("lists").getURL(data["service"].full(),
33 data.get("node") or "@")
34 breadcrumbs.append({
35 "label": D_("List"),
36 "url": list_url
37 })
38 breadcrumbs.append({
39 "label": D_("Item"),
40 })
41
42
29 async def prepare_render(self, request): 43 async def prepare_render(self, request):
30 data = self.getRData(request) 44 data = self.getRData(request)
31 template_data = request.template_data 45 template_data = request.template_data
32 session = self.host.getSessionData(request, session_iface.ISATSession) 46 session = self.host.getSessionData(request, session_iface.ISATSession)
33 service, node, item_id = ( 47 service, node, item_id = (
34 data.get("service", ""), 48 data.get("service", ""),
35 data.get("node", ""), 49 data.get("node", ""),
36 data["item_id"], 50 data["item_id"],
37 ) 51 )
52 namespace = node or self.host.ns_map["tickets"]
53 node = await self.host.bridgeCall("psSchemaSubmittedNodeGet", namespace)
54
38 profile = self.getProfile(request) 55 profile = self.getProfile(request)
39
40 if profile is None: 56 if profile is None:
41 profile = C.SERVICE_PROFILE 57 profile = C.SERVICE_PROFILE
42 58
43 list_raw = await self.host.bridgeCall( 59 list_raw = await self.host.bridgeCall(
44 "listGet", 60 "listGet",
48 [item_id], 64 [item_id],
49 "", 65 "",
50 {"labels_as_list": C.BOOL_TRUE}, 66 {"labels_as_list": C.BOOL_TRUE},
51 profile, 67 profile,
52 ) 68 )
53 list_items, metadata = data_format.deserialise(list_raw, type_check=list) 69 list_items, __ = data_format.deserialise(list_raw, type_check=list)
54 list_item = [template_xmlui.create(self.host, x) for x in list_items][0] 70 list_item = [template_xmlui.create(self.host, x) for x in list_items][0]
55 template_data["item"] = list_item 71 template_data["item"] = list_item
56 try: 72 try:
57 comments_uri = list_item.widgets["comments_uri"].value 73 comments_uri = list_item.widgets["comments_uri"].value
58 except KeyError: 74 except KeyError:
89 # the node owner 105 # the node owner
90 publisher = jid.JID(list_item.widgets["publisher"].value) 106 publisher = jid.JID(list_item.widgets["publisher"].value)
91 is_publisher = publisher.userhostJID() == session.jid.userhostJID() 107 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
92 affiliation = None 108 affiliation = None
93 if not is_publisher: 109 if not is_publisher:
94 node = node or self.host.ns_map["tickets"]
95 affiliation = await self.host.getAffiliation(request, service, node) 110 affiliation = await self.host.getAffiliation(request, service, node)
96 if is_publisher or affiliation == "owner": 111 if is_publisher or affiliation == "owner":
97 self.exposeToScripts( 112 self.exposeToScripts(
98 request, 113 request,
99 pubsub_service = service.full(), 114 pubsub_service = service.full(),
108 item_id, 123 item_id,
109 ) 124 )
110 125
111 # we add xmpp: URI 126 # we add xmpp: URI
112 uri_args = {'path': service.full()} 127 uri_args = {'path': service.full()}
113 uri_args['node'] = node or self.host.ns_map["tickets"] 128 uri_args['node'] = node
114 if item_id: 129 if item_id:
115 uri_args['item'] = item_id 130 uri_args['item'] = item_id
116 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args) 131 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args)
117 132
118 133