comparison src/pages/tickets/view/page_meta.py @ 967:4d1dcf97740f

pages (tickets): tickets first draft: following pages are available: tickets/[service]/[node]: display list of all tickets ([node] can be "@" for default node) .../new: create a ticket .../view: view a single ticket and its comments, and allow to publish a new comment if use is logged in.
author Goffi <goffi@goffi.org>
date Sun, 05 Nov 2017 22:11:23 +0100
parents
children 75166ac3e0cc
comparison
equal deleted inserted replaced
966:12c149171199 967:4d1dcf97740f
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 access = C.PAGES_ACCESS_PUBLIC
15 template = u"ticket/item.html"
16
17
18 def parse_url(self, request):
19 try:
20 item_id = self.nextPath(request)
21 except IndexError:
22 log.warning(_(u"no ticket id specified"))
23 self.pageError(request, C.HTTP_BAD_REQUEST)
24
25 data = self.getRData(request)
26 data[u'ticket_id'] = item_id
27
28 @defer.inlineCallbacks
29 def prepare_render(self, request):
30 data = self.getRData(request)
31 template_data = request.template_data
32 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id']
33 profile = self.getProfile(request)
34
35 if profile is None:
36 profile = C.SERVICE_PROFILE
37 else:
38 template_data['profile'] = profile
39
40 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [ticket_id], '', {}, profile)
41 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0]
42 template_data[u'item'] = ticket
43 comments_uri = ticket.widgets['comments_uri'].value
44 if comments_uri:
45 uri_data = uri.parseXMPPUri(comments_uri)
46 template_data['comments_node'] = comments_node = uri_data['node']
47 template_data['comments_service'] = comments_service = uri_data['path']
48 comments = yield self.host.bridge.mbGet(comments_service,
49 comments_node,
50 C.NO_LIMIT,
51 [],
52 {},
53 profile)
54
55 template_data[u'comments'] = data_objects.BlogItems(comments)
56 template_data[u'login_url'] = self.getPageRedirectURL(request)
57
58 @defer.inlineCallbacks
59 def on_data_post(self, request):
60 type_ = self.getPostedData(request, u'type')
61 if type_ == u'comment':
62 blog_page = self.getPageByName(u'blog')
63 yield blog_page.on_data_post(self, request)
64 else:
65 log.warning(_(u"Unhandled data type: {}").format(type_))