annotate libervia/pages/tickets/disco/page_meta.py @ 1128:6414fd795df4

server, pages: multi-sites refactoring: Libervia is now handling external sites (i.e. other sites than Libervia official site). The external site are declared in sites_path_public_dict (in [DEFAULT] section) which is read by template engine, then they are linked to virtual host with vhosts_dict (linking host name to site name) in [libervia] section. Sites are only instanced once, so adding an alias is just a matter of mapping the alias host name in vhosts_dict with the same site name. menu_json and url_redirections_dict can now accept keys named after site name, which will be linked to the data for the site. Data for default site can still be keyed at first level. Libervia official pages are added to external site (if pages are not overriden), allowing to call pages of the framework and to have facilities like login handling. Deprecated url_redirections_profile option has been removed.
author Goffi <goffi@goffi.org>
date Fri, 14 Sep 2018 21:41:28 +0200
parents 28e3eb3bb217
children 29eb15062416
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
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
7
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
8 log = getLogger("pages/ticket")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 """ticket handling pages"""
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
11 name = u"tickets_disco"
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 access = C.PAGES_ACCESS_PUBLIC
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 template = u"ticket/discover.html"
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
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 def prepare_render(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
17 tickets_trackers_config = self.host.options["tickets_trackers_json"]
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 if tickets_trackers_config:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
19 trackers = request.template_data["tickets_trackers"] = []
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 try:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 for tracker_data in tickets_trackers_config:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
22 service = tracker_data[u"service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
23 node = tracker_data[u"node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
24 name = tracker_data[u"name"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
25 url = self.getPageByName(u"tickets").getURL(service, node)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
26 trackers.append({u"name": name, u"url": url})
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 except KeyError as e:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 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
29 except Exception as e:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log.warning(u"Can't decode tickets trackers: {msg}".format(msg=e))
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
32
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def on_data_post(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
34 jid_str = self.getPostedData(request, u"jid")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
36 jid_ = jid.JID(jid_str)
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except RuntimeError:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.pageError(request, C.HTTP_BAD_REQUEST)
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 # for now we just use default node
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
40 url = self.getPageByName(u"tickets").getURL(jid_.full(), u"@")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.HTTPRedirect(request, url)