Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
1080:2c2b8c08e6c9 | 1081:ed67265205c4 |
---|---|
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'merge-requests_disco' | |
11 access = C.PAGES_ACCESS_PUBLIC | |
12 template = u"merge-request/discover.html" | |
13 | |
14 | |
15 def prepare_render(self, request): | |
16 mr_handlers_config = self.host.options['mr_handlers_json'] | |
17 if mr_handlers_config: | |
18 handlers = request.template_data['mr_handlers'] = [] | |
19 try: | |
20 for handler_data in mr_handlers_config: | |
21 service = handler_data[u'service'] | |
22 node = handler_data[u'node'] | |
23 name = handler_data[u'name'] | |
24 url = self.getPageByName(u'merge-requests').getURL(service, node) | |
25 handlers.append({u'name': name, u'url': url}) | |
26 except KeyError as e: | |
27 log.warning(u"Missing field in mr_handlers_json: {msg}".format(msg=e)) | |
28 except Exception as e: | |
29 log.warning(u"Can't decode mr handlers: {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'merge-requests').getURL(jid_.full(), u'@') | |
39 self.HTTPRedirect(request, url) |