annotate src/pages/tickets/disco/page_meta.py @ 1107:2066d4fd9036

browser: fixed XMLUI Panel and Dialog
author Goffi <goffi@goffi.org>
date Sun, 03 Jun 2018 14:04:05 +0200
parents 296bda6b7ed0
children cdd389ef97bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.words.protocols.jabber import jid
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 log = getLogger('pages/ticket')
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 """ticket handling pages"""
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 name = u'tickets_disco'
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 access = C.PAGES_ACCESS_PUBLIC
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 template = u"ticket/discover.html"
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 def prepare_render(self, request):
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 tickets_trackers_config = self.host.options['tickets_trackers_json']
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 if tickets_trackers_config:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 trackers = request.template_data['tickets_trackers'] = []
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 try:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 for tracker_data in tickets_trackers_config:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 service = tracker_data[u'service']
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 node = tracker_data[u'node']
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 name = tracker_data[u'name']
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 url = self.getPageByName(u'tickets').getURL(service, node)
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 trackers.append({u'name': name, u'url': url})
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except KeyError as e:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log.warning(u"Missing field in tickets_trackers_json: {msg}".format(msg=e))
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 except Exception as e:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 log.warning(u"Can't decode tickets trackers: {msg}".format(msg=e))
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def on_data_post(self, request):
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 jid_str = self.getPostedData(request, u'jid')
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 try:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 jid_ = jid.JID(jid_str)
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 except RuntimeError:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self.pageError(request, C.HTTP_BAD_REQUEST)
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 # for now we just use default node
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 url = self.getPageByName(u'tickets').getURL(jid_.full(), u'@')
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.HTTPRedirect(request, url)