Mercurial > libervia-web
annotate libervia/pages/merge-requests/edit/page_meta.py @ 1347:48e2a8b07c0b
browser: async version of bridge
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 05 Sep 2020 21:59:11 +0200 |
parents | 04e7dd6b6f4d |
children | e3e303a30a74 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1096
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 |
1194
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
8 from sat.tools.common import data_format |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from sat.core.log import getLogger |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
10 |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 """merge-requests edition""" |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
1216 | 13 name = "merge-requests_edit" |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 access = C.PAGES_ACCESS_PROFILE |
1216 | 15 template = "merge-request/edit.html" |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1143
diff
changeset
|
16 log = getLogger(__name__) |
1096
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 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 def parse_url(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 try: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 item_id = self.nextPath(request) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 except IndexError: |
1216 | 23 log.warning(_("no ticket id specified")) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 data = self.getRData(request) |
1216 | 27 data["ticket_id"] = item_id |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
28 |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
30 async def prepare_render(self, request): |
1096
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 = ( |
1216 | 34 data.get("service", ""), |
35 data.get("node", ""), | |
36 data["ticket_id"], | |
1113
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 ) |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
51 merge_requests = data_format.deserialise( |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
52 await self.host.bridgeCall( |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
53 "mergeRequestsGet", |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
54 service.full() if service else "", |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
55 node, |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
56 C.NO_LIMIT, |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
57 [ticket_id], |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
58 "", |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
59 {}, |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
60 profile, |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
61 ) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
62 ) |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
63 ticket = template_xmlui.create(self.host, merge_requests['items'][0], ignore=ignore) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 try: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 # small trick to get a one line text input instead of the big textarea |
1216 | 67 ticket.widgets["labels"].type = "string" |
68 ticket.widgets["labels"].value = ticket.widgets["labels"].value.replace( | |
69 "\n", ", " | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
70 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 except KeyError: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 pass |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
73 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
74 # same as tickets_edit |
1216 | 75 wid = ticket.widgets['body'] |
76 if wid.type == "xhtmlbox": | |
77 wid.type = "textbox" | |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
78 wid.value = await self.host.bridgeCall( |
1216 | 79 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown", |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
80 False, profile) |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
81 |
1216 | 82 template_data["new_ticket_xmlui"] = ticket |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
83 |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
85 async def on_data_post(self, request): |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
87 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
88 node = data["node"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
89 ticket_id = data["ticket_id"] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
91 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
|
92 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
94 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
|
95 except (KeyError, IndexError): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 pass |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 profile = self.getProfile(request) |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
98 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
99 # we convert back body to XHTML |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
100 body = await self.host.bridgeCall( |
1216 | 101 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML, |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
102 False, profile) |
1216 | 103 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
104 body=body)] |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
105 |
1216 | 106 extra = {'update': True} |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
107 await self.host.bridgeCall( |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
108 "mergeRequestSet", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
109 service.full(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
110 node, |
1216 | 111 "", |
112 "auto", | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
113 posted_data, |
1216 | 114 "", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
115 ticket_id, |
1194
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
116 data_format.serialise(extra), |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
117 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
118 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 # 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
|
120 data["post_redirect_page"] = ( |
1216 | 121 self.getPageByName("merge-requests"), |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
122 service.full(), |
1216 | 123 node or "@", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
124 ) |