Mercurial > libervia-web
comparison src/pages/merge-requests/edit/page_meta.py @ 1096:01538d8a77be
merge-requests, tickets: new "edit" pages
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Jun 2018 13:04:57 +0200 |
parents | |
children | 01e95ec9df9e |
comparison
equal
deleted
inserted
replaced
1095:7d5633ccbaf2 | 1096:01538d8a77be |
---|---|
1 #!/usr/bin/env python2.7 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 from libervia.server.constants import Const as C | |
5 from sat.core.i18n import _ | |
6 from twisted.internet import defer | |
7 from sat.tools.common import template_xmlui | |
8 from sat.core.log import getLogger | |
9 """merge-requests edition""" | |
10 | |
11 name = u'merge-requests_edit' | |
12 access = C.PAGES_ACCESS_PROFILE | |
13 template = u"merge-request/edit.html" | |
14 log = getLogger('pages/' + name) | |
15 | |
16 | |
17 def parse_url(self, request): | |
18 try: | |
19 item_id = self.nextPath(request) | |
20 except IndexError: | |
21 log.warning(_(u"no ticket id specified")) | |
22 self.pageError(request, C.HTTP_BAD_REQUEST) | |
23 | |
24 data = self.getRData(request) | |
25 data[u'ticket_id'] = item_id | |
26 | |
27 @defer.inlineCallbacks | |
28 def prepare_render(self, request): | |
29 data = self.getRData(request) | |
30 template_data = request.template_data | |
31 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id'] | |
32 profile = self.getProfile(request) | |
33 | |
34 | |
35 ignore = ('publisher', 'author', 'author_jid', 'author_email', 'created', 'updated', 'comments_uri', 'request_data', 'type') | |
36 tickets = yield self.host.bridge.mergeRequestsGet(service.full() if service else u'', node, C.NO_LIMIT, [ticket_id], '', {}, profile) | |
37 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0] | |
38 | |
39 try: | |
40 # small trick to get a one line text input instead of the big textarea | |
41 ticket.widgets[u'labels'].type = u'string' | |
42 ticket.widgets[u'labels'].value = ticket.widgets[u'labels'].value.replace(u'\n', ', ') | |
43 except KeyError: | |
44 pass | |
45 template_data[u'new_ticket_xmlui'] = ticket | |
46 | |
47 @defer.inlineCallbacks | |
48 def on_data_post(self, request): | |
49 data = self.getRData(request) | |
50 service = data['service'] | |
51 node = data['node'] | |
52 ticket_id = data['ticket_id'] | |
53 posted_data = self.getAllPostedData(request) | |
54 if not posted_data['title'] or not posted_data['body']: | |
55 self.pageError(request, C.HTTP_BAD_REQUEST) | |
56 try: | |
57 posted_data['labels'] = [l.strip() for l in posted_data['labels'][0].split(',')] | |
58 except (KeyError, IndexError): | |
59 pass | |
60 profile = self.getProfile(request) | |
61 yield self.host.bridge.mergeRequestSet(service.full(), | |
62 node, | |
63 u'', | |
64 u'auto', | |
65 posted_data, | |
66 u'', | |
67 ticket_id, | |
68 {'update': C.BOOL_TRUE}, | |
69 profile) | |
70 # we don't want to redirect to edit page on success, but to tickets list | |
71 data['post_redirect_page'] = (self.getPageByName(u'merge-requests'), | |
72 service.full(), | |
73 node or u'@') |