annotate libervia/pages/merge-requests/disco/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/merge-requests/disco/page_meta.py@cdd389ef97bc
children 29eb15062416
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.words.protocols.jabber import jid
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
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: 1081
diff changeset
7
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
8 log = getLogger("pages/ticket")
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 """ticket handling pages"""
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
11 name = u"merge-requests_disco"
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 access = C.PAGES_ACCESS_PUBLIC
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 template = u"merge-request/discover.html"
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
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: 1081
diff changeset
17 mr_handlers_config = self.host.options["mr_handlers_json"]
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 if mr_handlers_config:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
19 handlers = request.template_data["mr_handlers"] = []
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 try:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 for handler_data in mr_handlers_config:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
22 service = handler_data[u"service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
23 node = handler_data[u"node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
24 name = handler_data[u"name"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
25 url = self.getPageByName(u"merge-requests").getURL(service, node)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
26 handlers.append({u"name": name, u"url": url})
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 except KeyError as e:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 log.warning(u"Missing field in mr_handlers_json: {msg}".format(msg=e))
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 except Exception as e:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log.warning(u"Can't decode mr handlers: {msg}".format(msg=e))
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
32
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
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: 1081
diff changeset
34 jid_str = self.getPostedData(request, u"jid")
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1081
diff changeset
36 jid_ = jid.JID(jid_str)
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except RuntimeError:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.pageError(request, C.HTTP_BAD_REQUEST)
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
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: 1081
diff changeset
40 url = self.getPageByName(u"merge-requests").getURL(jid_.full(), u"@")
1081
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.HTTPRedirect(request, url)