1078
|
1 #!/usr/bin/env python2.7 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 from libervia.server.constants import Const as C |
|
5 from twisted.words.protocols.jabber import jid |
|
6 from sat.core.log import getLogger |
|
7 log = getLogger('pages/ticket') |
|
8 """ticket handling pages""" |
|
9 |
|
10 name = u'tickets_disco' |
|
11 access = C.PAGES_ACCESS_PUBLIC |
|
12 template = u"ticket/discover.html" |
|
13 |
|
14 |
|
15 def prepare_render(self, request): |
|
16 tickets_trackers_config = self.host.options['tickets_trackers_json'] |
|
17 if tickets_trackers_config: |
|
18 trackers = request.template_data['tickets_trackers'] = [] |
|
19 try: |
|
20 for tracker_data in tickets_trackers_config: |
|
21 service = tracker_data[u'service'] |
|
22 node = tracker_data[u'node'] |
|
23 name = tracker_data[u'name'] |
|
24 url = self.getPageByName(u'tickets').getURL(service, node) |
|
25 trackers.append({u'name': name, u'url': url}) |
|
26 except KeyError as e: |
|
27 log.warning(u"Missing field in tickets_trackers_json: {msg}".format(msg=e)) |
|
28 except Exception as e: |
|
29 log.warning(u"Can't decode tickets trackers: {msg}".format(msg=e)) |
|
30 |
|
31 def on_data_post(self, request): |
|
32 jid_str = self.getPostedData(request, u'jid') |
|
33 try: |
|
34 jid_ = jid.JID(jid_str) |
|
35 except RuntimeError: |
|
36 self.pageError(request, C.HTTP_BAD_REQUEST) |
|
37 # for now we just use default node |
|
38 url = self.getPageByName(u'tickets').getURL(jid_.full(), u'@') |
|
39 self.HTTPRedirect(request, url) |