comparison src/pages/merge-requests/view/page_meta.py @ 991:6ce9647011b3

pages(merge-requests): merge requests new, view and list pages implementations.
author Goffi <goffi@goffi.org>
date Fri, 01 Dec 2017 01:08:25 +0100
parents
children b92b06f023cb
comparison
equal deleted inserted replaced
990:6daa59d44ee2 991:6ce9647011b3
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 twisted.internet import defer
7 from sat.tools.common import template_xmlui
8 from sat.tools.common import uri
9 from sat.tools.common import data_objects
10 from sat.core.log import getLogger
11 log = getLogger('pages/tickets/view')
12 """ticket handling pages"""
13
14 name = u"merge-requests_view"
15 access = C.PAGES_ACCESS_PUBLIC
16 template = u"merge-request/item.html"
17
18
19 def parse_url(self, request):
20 try:
21 item_id = self.nextPath(request)
22 except IndexError:
23 log.warning(_(u"no ticket id specified"))
24 self.pageError(request, C.HTTP_BAD_REQUEST)
25
26 data = self.getRData(request)
27 data[u'ticket_id'] = item_id
28
29 @defer.inlineCallbacks
30 def prepare_render(self, request):
31 data = self.getRData(request)
32 template_data = request.template_data
33 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id']
34 profile = self.getProfile(request)
35
36 if profile is None:
37 profile = C.SERVICE_PROFILE
38 else:
39 template_data['profile'] = profile
40
41 tickets, metadata, parsed_tickets = yield self.host.bridge.mergeRequestsGet(service.full() if service else u'',
42 node,
43 C.NO_LIMIT,
44 [ticket_id],
45 '',
46 {'parse': C.BOOL_TRUE},
47 profile)
48 ticket = template_xmlui.create(self.host, tickets[0], ignore=['publisher', 'request_data', 'type'])
49 template_data[u'item'] = ticket
50 template_data['patches'] = parsed_tickets[0]
51 comments_uri = ticket.widgets['comments_uri'].value
52 if comments_uri:
53 uri_data = uri.parseXMPPUri(comments_uri)
54 template_data['comments_node'] = comments_node = uri_data['node']
55 template_data['comments_service'] = comments_service = uri_data['path']
56 comments = yield self.host.bridge.mbGet(comments_service,
57 comments_node,
58 C.NO_LIMIT,
59 [],
60 {},
61 profile)
62
63 template_data[u'comments'] = data_objects.BlogItems(comments)
64 template_data[u'login_url'] = self.getPageRedirectURL(request)
65
66 @defer.inlineCallbacks
67 def on_data_post(self, request):
68 type_ = self.getPostedData(request, u'type')
69 if type_ == u'comment':
70 blog_page = self.getPageByName(u'blog')
71 yield blog_page.on_data_post(self, request)
72 else:
73 log.warning(_(u"Unhandled data type: {}").format(type_))