comparison libervia/pages/merge-requests/view/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/merge-requests/view/page_meta.py@cdd389ef97bc
children 29eb15062416
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
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.internet import defer
9 from twisted.words.protocols.jabber import jid
10 from sat.tools.common import template_xmlui
11 from sat.tools.common import uri
12 from sat.tools.common import data_objects
13 from sat.core.log import getLogger
14
15 name = u"merge-requests_view"
16 access = C.PAGES_ACCESS_PUBLIC
17 template = u"merge-request/item.html"
18 log = getLogger(u"pages/" + name)
19
20
21 def parse_url(self, request):
22 try:
23 item_id = self.nextPath(request)
24 except IndexError:
25 log.warning(_(u"no ticket id specified"))
26 self.pageError(request, C.HTTP_BAD_REQUEST)
27
28 data = self.getRData(request)
29 data[u"ticket_id"] = item_id
30
31
32 @defer.inlineCallbacks
33 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, ticket_id = (
38 data.get(u"service", u""),
39 data.get(u"node", u""),
40 data[u"ticket_id"],
41 )
42 profile = self.getProfile(request)
43
44 if profile is None:
45 profile = C.SERVICE_PROFILE
46
47 tickets, metadata, parsed_tickets = yield self.host.bridgeCall(
48 "mergeRequestsGet",
49 service.full() if service else u"",
50 node,
51 C.NO_LIMIT,
52 [ticket_id],
53 "",
54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE},
55 profile,
56 )
57 ticket = template_xmlui.create(self.host, tickets[0], ignore=["request_data", "type"])
58 template_data[u"item"] = ticket
59 template_data["patches"] = parsed_tickets[0]
60 comments_uri = ticket.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 = yield self.host.bridgeCall(
66 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile
67 )
68
69 template_data[u"comments"] = data_objects.BlogItems(comments)
70 template_data[u"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(ticket.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["merge_requests"]
79 affiliation = yield self.host.getAffiliation(request, service, node)
80 if is_publisher or affiliation == "owner":
81 template_data[u"url_ticket_edit"] = self.getURLByPath(
82 SubPage("merge-requests"),
83 service.full(),
84 node or u"@",
85 SubPage("merge-requests_edit"),
86 ticket_id,
87 )
88
89
90 @defer.inlineCallbacks
91 def on_data_post(self, request):
92 type_ = self.getPostedData(request, u"type")
93 if type_ == u"comment":
94 blog_page = self.getPageByName(u"blog_view")
95 yield blog_page.on_data_post(self, request)
96 else:
97 log.warning(_(u"Unhandled data type: {}").format(type_))