Mercurial > libervia-web
comparison libervia/pages/tickets/view/page_meta.py @ 1302:04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Jul 2020 09:08:47 +0200 |
parents | f511f8fbbf8a |
children |
comparison
equal
deleted
inserted
replaced
1301:ff44f822bfdd | 1302:04e7dd6b6f4d |
---|---|
7 from libervia.server import session_iface | 7 from libervia.server import session_iface |
8 from twisted.internet import defer | 8 from twisted.internet import defer |
9 from twisted.words.protocols.jabber import jid | 9 from twisted.words.protocols.jabber import jid |
10 from sat.tools.common import template_xmlui | 10 from sat.tools.common import template_xmlui |
11 from sat.tools.common import uri | 11 from sat.tools.common import uri |
12 from sat.tools.common import data_objects | 12 from sat.tools.common import data_format |
13 from sat.core.log import getLogger | 13 from sat.core.log import getLogger |
14 | 14 |
15 log = getLogger(__name__) | 15 log = getLogger(__name__) |
16 """ticket handling pages""" | 16 """ticket handling pages""" |
17 | 17 |
29 | 29 |
30 data = self.getRData(request) | 30 data = self.getRData(request) |
31 data["ticket_id"] = item_id | 31 data["ticket_id"] = item_id |
32 | 32 |
33 | 33 |
34 @defer.inlineCallbacks | 34 async def prepare_render(self, request): |
35 def prepare_render(self, request): | |
36 data = self.getRData(request) | 35 data = self.getRData(request) |
37 template_data = request.template_data | 36 template_data = request.template_data |
38 session = self.host.getSessionData(request, session_iface.ISATSession) | 37 session = self.host.getSessionData(request, session_iface.ISATSession) |
39 service, node, ticket_id = ( | 38 service, node, ticket_id = ( |
40 data.get("service", ""), | 39 data.get("service", ""), |
44 profile = self.getProfile(request) | 43 profile = self.getProfile(request) |
45 | 44 |
46 if profile is None: | 45 if profile is None: |
47 profile = C.SERVICE_PROFILE | 46 profile = C.SERVICE_PROFILE |
48 | 47 |
49 tickets = yield self.host.bridgeCall( | 48 tickets_raw = await self.host.bridgeCall( |
50 "ticketsGet", | 49 "ticketsGet", |
51 service.full() if service else "", | 50 service.full() if service else "", |
52 node, | 51 node, |
53 C.NO_LIMIT, | 52 C.NO_LIMIT, |
54 [ticket_id], | 53 [ticket_id], |
55 "", | 54 "", |
56 {"labels_as_list": C.BOOL_TRUE}, | 55 {"labels_as_list": C.BOOL_TRUE}, |
57 profile, | 56 profile, |
58 ) | 57 ) |
59 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0] | 58 tickets, metadata = data_format.deserialise(tickets_raw, type_check=list) |
59 ticket = [template_xmlui.create(self.host, x) for x in tickets][0] | |
60 template_data["item"] = ticket | 60 template_data["item"] = ticket |
61 comments_uri = ticket.widgets["comments_uri"].value | 61 comments_uri = ticket.widgets["comments_uri"].value |
62 if comments_uri: | 62 if comments_uri: |
63 uri_data = uri.parseXMPPUri(comments_uri) | 63 uri_data = uri.parseXMPPUri(comments_uri) |
64 template_data["comments_node"] = comments_node = uri_data["node"] | 64 template_data["comments_node"] = comments_node = uri_data["node"] |
65 template_data["comments_service"] = comments_service = uri_data["path"] | 65 template_data["comments_service"] = comments_service = uri_data["path"] |
66 comments = yield self.host.bridgeCall( | 66 comments = data_format.deserialise(await self.host.bridgeCall( |
67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile | 67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile |
68 ) | 68 )) |
69 | 69 |
70 template_data["comments"] = data_objects.BlogItems(comments) | 70 template_data["comments"] = comments |
71 template_data["login_url"] = self.getPageRedirectURL(request) | 71 template_data["login_url"] = self.getPageRedirectURL(request) |
72 | 72 |
73 if session.connected: | 73 if session.connected: |
74 # we set edition URL only if user is the publisher or the node owner | 74 # we set edition URL only if user is the publisher or the node owner |
75 publisher = jid.JID(ticket.widgets["publisher"].value) | 75 publisher = jid.JID(ticket.widgets["publisher"].value) |
76 is_publisher = publisher.userhostJID() == session.jid.userhostJID() | 76 is_publisher = publisher.userhostJID() == session.jid.userhostJID() |
77 affiliation = None | 77 affiliation = None |
78 if not is_publisher: | 78 if not is_publisher: |
79 node = node or self.host.ns_map["tickets"] | 79 node = node or self.host.ns_map["tickets"] |
80 affiliation = yield self.host.getAffiliation(request, service, node) | 80 affiliation = await self.host.getAffiliation(request, service, node) |
81 if is_publisher or affiliation == "owner": | 81 if is_publisher or affiliation == "owner": |
82 template_data["url_ticket_edit"] = self.getURLByPath( | 82 template_data["url_ticket_edit"] = self.getURLByPath( |
83 SubPage("tickets"), | 83 SubPage("tickets"), |
84 service.full(), | 84 service.full(), |
85 node or "@", | 85 node or "@", |