annotate libervia/pages/merge-requests/edit/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 7bd47d32da87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
3
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools.common import template_xmlui
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
9
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
10 """merge-requests edition"""
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
11
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
12 name = u"merge-requests_edit"
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = u"merge-request/edit.html"
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
15 log = getLogger("pages/" + name)
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
16
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
17
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
18 def parse_url(self, request):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
19 try:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
20 item_id = self.nextPath(request)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
21 except IndexError:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log.warning(_(u"no ticket id specified"))
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
23 self.pageError(request, C.HTTP_BAD_REQUEST)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
24
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
25 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
26 data[u"ticket_id"] = item_id
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
27
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
28
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
29 @defer.inlineCallbacks
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def prepare_render(self, request):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
31 data = self.getRData(request)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
32 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
33 service, node, ticket_id = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
34 data.get(u"service", u""),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
35 data.get(u"node", u""),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
36 data[u"ticket_id"],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
37 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
38 profile = self.getProfile(request)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
39
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
40 ignore = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
41 "publisher",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
42 "author",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
43 "author_jid",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
44 "author_email",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
45 "created",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
46 "updated",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
47 "comments_uri",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
48 "request_data",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
49 "type",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
50 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
51 tickets = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
52 "mergeRequestsGet",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
53 service.full() if service else u"",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
54 node,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
55 C.NO_LIMIT,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
56 [ticket_id],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
57 "",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
58 {},
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
59 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
60 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
61 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0]
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
62
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
63 try:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # small trick to get a one line text input instead of the big textarea
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
65 ticket.widgets[u"labels"].type = u"string"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
66 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
67 u"\n", ", "
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
68 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
69 except KeyError:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
70 pass
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
71 template_data[u"new_ticket_xmlui"] = ticket
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
72
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
73
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
74 @defer.inlineCallbacks
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def on_data_post(self, request):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
76 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
77 service = data["service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
78 node = data["node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
79 ticket_id = data["ticket_id"]
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
80 posted_data = self.getAllPostedData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
81 if not posted_data["title"] or not posted_data["body"]:
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.pageError(request, C.HTTP_BAD_REQUEST)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
83 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
84 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")]
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
85 except (KeyError, IndexError):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
86 pass
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
87 profile = self.getProfile(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
88 yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
89 "mergeRequestSet",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
90 service.full(),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
91 node,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
92 u"",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
93 u"auto",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
94 posted_data,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
95 u"",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
96 ticket_id,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
97 {"update": C.BOOL_TRUE},
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
98 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
99 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
100 # we don't want to redirect to edit page on success, but to tickets list
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
101 data["post_redirect_page"] = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
102 self.getPageByName(u"merge-requests"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
103 service.full(),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
104 node or u"@",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
105 )