Mercurial > libervia-web
comparison libervia/pages/merge-requests/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 | e3e303a30a74 |
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 name = "merge-requests_view" | 15 name = "merge-requests_view" |
16 access = C.PAGES_ACCESS_PUBLIC | 16 access = C.PAGES_ACCESS_PUBLIC |
17 template = "merge-request/item.html" | 17 template = "merge-request/item.html" |
27 | 27 |
28 data = self.getRData(request) | 28 data = self.getRData(request) |
29 data["ticket_id"] = item_id | 29 data["ticket_id"] = item_id |
30 | 30 |
31 | 31 |
32 @defer.inlineCallbacks | 32 async def prepare_render(self, request): |
33 def prepare_render(self, request): | |
34 data = self.getRData(request) | 33 data = self.getRData(request) |
35 template_data = request.template_data | 34 template_data = request.template_data |
36 session = self.host.getSessionData(request, session_iface.ISATSession) | 35 session = self.host.getSessionData(request, session_iface.ISATSession) |
37 service, node, ticket_id = ( | 36 service, node, ticket_id = ( |
38 data.get("service", ""), | 37 data.get("service", ""), |
42 profile = self.getProfile(request) | 41 profile = self.getProfile(request) |
43 | 42 |
44 if profile is None: | 43 if profile is None: |
45 profile = C.SERVICE_PROFILE | 44 profile = C.SERVICE_PROFILE |
46 | 45 |
47 tickets, metadata, parsed_tickets = yield self.host.bridgeCall( | 46 merge_requests = data_format.deserialise( |
48 "mergeRequestsGet", | 47 await self.host.bridgeCall( |
49 service.full() if service else "", | 48 "mergeRequestsGet", |
50 node, | 49 service.full() if service else "", |
51 C.NO_LIMIT, | 50 node, |
52 [ticket_id], | 51 C.NO_LIMIT, |
53 "", | 52 [ticket_id], |
54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}, | 53 "", |
55 profile, | 54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}, |
55 profile, | |
56 ) | |
56 ) | 57 ) |
57 ticket = template_xmlui.create(self.host, tickets[0], ignore=["request_data", "type"]) | 58 ticket = template_xmlui.create( |
59 self.host, merge_requests['items'][0], ignore=["request_data", "type"] | |
60 ) | |
58 template_data["item"] = ticket | 61 template_data["item"] = ticket |
59 template_data["patches"] = parsed_tickets[0] | 62 template_data["patches"] = merge_requests['items_patches'][0] |
60 comments_uri = ticket.widgets["comments_uri"].value | 63 comments_uri = ticket.widgets["comments_uri"].value |
61 if comments_uri: | 64 if comments_uri: |
62 uri_data = uri.parseXMPPUri(comments_uri) | 65 uri_data = uri.parseXMPPUri(comments_uri) |
63 template_data["comments_node"] = comments_node = uri_data["node"] | 66 template_data["comments_node"] = comments_node = uri_data["node"] |
64 template_data["comments_service"] = comments_service = uri_data["path"] | 67 template_data["comments_service"] = comments_service = uri_data["path"] |
65 comments = yield self.host.bridgeCall( | 68 template_data["comments"] = data_format.deserialise(await self.host.bridgeCall( |
66 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile | 69 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile |
67 ) | 70 )) |
68 | 71 |
69 template_data["comments"] = data_objects.BlogItems(comments) | |
70 template_data["login_url"] = self.getPageRedirectURL(request) | 72 template_data["login_url"] = self.getPageRedirectURL(request) |
71 | 73 |
72 if session.connected: | 74 if session.connected: |
73 # we set edition URL only if user is the publisher or the node owner | 75 # we set edition URL only if user is the publisher or the node owner |
74 publisher = jid.JID(ticket.widgets["publisher"].value) | 76 publisher = jid.JID(ticket.widgets["publisher"].value) |
75 is_publisher = publisher.userhostJID() == session.jid.userhostJID() | 77 is_publisher = publisher.userhostJID() == session.jid.userhostJID() |
76 affiliation = None | 78 affiliation = None |
77 if not is_publisher: | 79 if not is_publisher: |
78 node = node or self.host.ns_map["merge_requests"] | 80 node = node or self.host.ns_map["merge_requests"] |
79 affiliation = yield self.host.getAffiliation(request, service, node) | 81 affiliation = await self.host.getAffiliation(request, service, node) |
80 if is_publisher or affiliation == "owner": | 82 if is_publisher or affiliation == "owner": |
81 template_data["url_ticket_edit"] = self.getURLByPath( | 83 template_data["url_ticket_edit"] = self.getURLByPath( |
82 SubPage("merge-requests"), | 84 SubPage("merge-requests"), |
83 service.full(), | 85 service.full(), |
84 node or "@", | 86 node or "@", |
85 SubPage("merge-requests_edit"), | 87 SubPage("merge-requests_edit"), |
86 ticket_id, | 88 ticket_id, |
87 ) | 89 ) |
88 | 90 |
89 | 91 |
90 @defer.inlineCallbacks | 92 async def on_data_post(self, request): |
91 def on_data_post(self, request): | |
92 type_ = self.getPostedData(request, "type") | 93 type_ = self.getPostedData(request, "type") |
93 if type_ == "comment": | 94 if type_ == "comment": |
94 blog_page = self.getPageByName("blog_view") | 95 blog_page = self.getPageByName("blog_view") |
95 yield blog_page.on_data_post(self, request) | 96 await blog_page.on_data_post(self, request) |
96 else: | 97 else: |
97 log.warning(_("Unhandled data type: {}").format(type_)) | 98 log.warning(_("Unhandled data type: {}").format(type_)) |