Mercurial > libervia-web
comparison libervia/pages/merge-requests/view/page_meta.py @ 1216:b2d067339de3
python 3 port:
/!\ Python 3.6+ is now needed to use libervia
/!\ instability may occur and features may not be working anymore, this will improve with time
/!\ TxJSONRPC dependency has been removed
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog,
JSON RPC related code).
Adapted code to work without `html` and `themes` dirs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:12:31 +0200 |
parents | 29eb15062416 |
children | f511f8fbbf8a |
comparison
equal
deleted
inserted
replaced
1215:f14ab8a25e8b | 1216:b2d067339de3 |
---|---|
1 #!/usr/bin/env python2.7 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 from libervia.server.constants import Const as C | 4 from libervia.server.constants import Const as C |
5 from sat.core.i18n import _ | 5 from sat.core.i18n import _ |
6 from libervia.server.utils import SubPage | 6 from libervia.server.utils import SubPage |
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_objects |
13 from sat.core.log import getLogger | 13 from sat.core.log import getLogger |
14 | 14 |
15 name = u"merge-requests_view" | 15 name = "merge-requests_view" |
16 access = C.PAGES_ACCESS_PUBLIC | 16 access = C.PAGES_ACCESS_PUBLIC |
17 template = u"merge-request/item.html" | 17 template = "merge-request/item.html" |
18 log = getLogger(__name__) | 18 log = getLogger(__name__) |
19 | 19 |
20 | 20 |
21 def parse_url(self, request): | 21 def parse_url(self, request): |
22 try: | 22 try: |
23 item_id = self.nextPath(request) | 23 item_id = self.nextPath(request) |
24 except IndexError: | 24 except IndexError: |
25 log.warning(_(u"no ticket id specified")) | 25 log.warning(_("no ticket id specified")) |
26 self.pageError(request, C.HTTP_BAD_REQUEST) | 26 self.pageError(request, C.HTTP_BAD_REQUEST) |
27 | 27 |
28 data = self.getRData(request) | 28 data = self.getRData(request) |
29 data[u"ticket_id"] = item_id | 29 data["ticket_id"] = item_id |
30 | 30 |
31 | 31 |
32 @defer.inlineCallbacks | 32 @defer.inlineCallbacks |
33 def prepare_render(self, request): | 33 def prepare_render(self, request): |
34 data = self.getRData(request) | 34 data = self.getRData(request) |
35 template_data = request.template_data | 35 template_data = request.template_data |
36 session = self.host.getSessionData(request, session_iface.ISATSession) | 36 session = self.host.getSessionData(request, session_iface.ISATSession) |
37 service, node, ticket_id = ( | 37 service, node, ticket_id = ( |
38 data.get(u"service", u""), | 38 data.get("service", ""), |
39 data.get(u"node", u""), | 39 data.get("node", ""), |
40 data[u"ticket_id"], | 40 data["ticket_id"], |
41 ) | 41 ) |
42 profile = self.getProfile(request) | 42 profile = self.getProfile(request) |
43 | 43 |
44 if profile is None: | 44 if profile is None: |
45 profile = C.SERVICE_PROFILE | 45 profile = C.SERVICE_PROFILE |
46 | 46 |
47 tickets, metadata, parsed_tickets = yield self.host.bridgeCall( | 47 tickets, metadata, parsed_tickets = yield self.host.bridgeCall( |
48 "mergeRequestsGet", | 48 "mergeRequestsGet", |
49 service.full() if service else u"", | 49 service.full() if service else "", |
50 node, | 50 node, |
51 C.NO_LIMIT, | 51 C.NO_LIMIT, |
52 [ticket_id], | 52 [ticket_id], |
53 "", | 53 "", |
54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}, | 54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}, |
55 profile, | 55 profile, |
56 ) | 56 ) |
57 ticket = template_xmlui.create(self.host, tickets[0], ignore=["request_data", "type"]) | 57 ticket = template_xmlui.create(self.host, tickets[0], ignore=["request_data", "type"]) |
58 template_data[u"item"] = ticket | 58 template_data["item"] = ticket |
59 template_data["patches"] = parsed_tickets[0] | 59 template_data["patches"] = parsed_tickets[0] |
60 comments_uri = ticket.widgets["comments_uri"].value | 60 comments_uri = ticket.widgets["comments_uri"].value |
61 if comments_uri: | 61 if comments_uri: |
62 uri_data = uri.parseXMPPUri(comments_uri) | 62 uri_data = uri.parseXMPPUri(comments_uri) |
63 template_data["comments_node"] = comments_node = uri_data["node"] | 63 template_data["comments_node"] = comments_node = uri_data["node"] |
64 template_data["comments_service"] = comments_service = uri_data["path"] | 64 template_data["comments_service"] = comments_service = uri_data["path"] |
65 comments = yield self.host.bridgeCall( | 65 comments = yield self.host.bridgeCall( |
66 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile | 66 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile |
67 ) | 67 ) |
68 | 68 |
69 template_data[u"comments"] = data_objects.BlogItems(comments) | 69 template_data["comments"] = data_objects.BlogItems(comments) |
70 template_data[u"login_url"] = self.getPageRedirectURL(request) | 70 template_data["login_url"] = self.getPageRedirectURL(request) |
71 | 71 |
72 if session.connected: | 72 if session.connected: |
73 # we set edition URL only if user is the publisher or the node owner | 73 # we set edition URL only if user is the publisher or the node owner |
74 publisher = jid.JID(ticket.widgets["publisher"].value) | 74 publisher = jid.JID(ticket.widgets["publisher"].value) |
75 is_publisher = publisher.userhostJID() == session.jid.userhostJID() | 75 is_publisher = publisher.userhostJID() == session.jid.userhostJID() |
76 affiliation = None | 76 affiliation = None |
77 if not is_publisher: | 77 if not is_publisher: |
78 node = node or self.host.ns_map["merge_requests"] | 78 node = node or self.host.ns_map["merge_requests"] |
79 affiliation = yield self.host.getAffiliation(request, service, node) | 79 affiliation = yield self.host.getAffiliation(request, service, node) |
80 if is_publisher or affiliation == "owner": | 80 if is_publisher or affiliation == "owner": |
81 template_data[u"url_ticket_edit"] = self.getURLByPath( | 81 template_data["url_ticket_edit"] = self.getURLByPath( |
82 SubPage("merge-requests"), | 82 SubPage("merge-requests"), |
83 service.full(), | 83 service.full(), |
84 node or u"@", | 84 node or "@", |
85 SubPage("merge-requests_edit"), | 85 SubPage("merge-requests_edit"), |
86 ticket_id, | 86 ticket_id, |
87 ) | 87 ) |
88 | 88 |
89 | 89 |
90 @defer.inlineCallbacks | 90 @defer.inlineCallbacks |
91 def on_data_post(self, request): | 91 def on_data_post(self, request): |
92 type_ = self.getPostedData(request, u"type") | 92 type_ = self.getPostedData(request, "type") |
93 if type_ == u"comment": | 93 if type_ == "comment": |
94 blog_page = self.getPageByName(u"blog_view") | 94 blog_page = self.getPageByName("blog_view") |
95 yield blog_page.on_data_post(self, request) | 95 yield blog_page.on_data_post(self, request) |
96 else: | 96 else: |
97 log.warning(_(u"Unhandled data type: {}").format(type_)) | 97 log.warning(_("Unhandled data type: {}").format(type_)) |