annotate src/pages/merge-requests/disco/page_meta.py @ 1081:ed67265205c4

pages (merge-requests): added a discovery page similar to tickets one: new "mr_handlers_json" option allows to add well known merge-requests handlers in configuration.
author Goffi <goffi@goffi.org>
date Tue, 27 Mar 2018 08:40:12 +0200
parents
children cdd389ef97bc
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
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 log = getLogger('pages/ticket')
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 """ticket handling pages"""
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 name = u'merge-requests_disco'
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 access = C.PAGES_ACCESS_PUBLIC
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 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
13
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 def prepare_render(self, request):
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 mr_handlers_config = self.host.options['mr_handlers_json']
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 if mr_handlers_config:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 handlers = request.template_data['mr_handlers'] = []
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 try:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 for handler_data in mr_handlers_config:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 service = handler_data[u'service']
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 node = handler_data[u'node']
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 name = handler_data[u'name']
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 url = self.getPageByName(u'merge-requests').getURL(service, node)
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 handlers.append({u'name': name, u'url': url})
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except KeyError as e:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 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
28 except Exception as e:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 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
30
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def on_data_post(self, request):
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 jid_str = self.getPostedData(request, u'jid')
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 try:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 jid_ = jid.JID(jid_str)
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 except RuntimeError:
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 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
37 # for now we just use default node
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 url = self.getPageByName(u'merge-requests').getURL(jid_.full(), u'@')
ed67265205c4 pages (merge-requests): added a discovery page similar to tickets one:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.HTTPRedirect(request, url)