Mercurial > libervia-web
annotate libervia/pages/lists/edit/page_meta.py @ 1384:b61509c47cac
tasks (brython): fixed Brython scripts during dev mode reload
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Feb 2021 13:56:08 +0100 |
parents | e3e303a30a74 |
children | a84383c659b4 |
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:
1192
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 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1143
diff
changeset
|
11 log = getLogger(__name__) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
13 name = "list_edit" |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 access = C.PAGES_ACCESS_PROFILE |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
15 template = "list/edit.html" |
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: |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
22 log.warning(_("no list item id specified")) |
1096
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) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
26 data["list_item_id"] = item_id |
1113
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 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
33 service, node, list_item_id = ( |
1216 | 34 data.get("service", ""), |
35 data.get("node", ""), | |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
36 data["list_item_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 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
40 # we don't ignore "author" below to keep it when a list item is edited |
1192
7b05ebc46141
pages (tickets/edit): don't ignore "author" anymore, to keep it when owner/admin modify a ticket
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
41 # by node owner/admin and "consistent publisher" is activated |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
42 ignore = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
43 "publisher", |
1195
5e67c2564779
pages (tickets/edit): "author" can be ignored again now that updating has been fixed
Goffi <goffi@goffi.org>
parents:
1194
diff
changeset
|
44 "author", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
45 "author_jid", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
46 "author_email", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
47 "created", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
48 "updated", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
49 "comments_uri", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
50 ) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
51 list_raw = yield self.host.bridgeCall( |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
52 "listGet", |
1216 | 53 service.full() if service else "", |
1113
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, |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
56 [list_item_id], |
1113
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 ) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
61 list_items, metadata = data_format.deserialise(list_raw, type_check=list) |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
62 list_item = [template_xmlui.create(self.host, x, ignore=ignore) for x in list_items][0] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 try: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 # small trick to get a one line text input instead of the big textarea |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
66 list_item.widgets["labels"].type = "string" |
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
67 list_item.widgets["labels"].value = list_item.widgets["labels"].value.replace( |
1216 | 68 "\n", ", " |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
69 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 except KeyError: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 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
|
72 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
73 # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
74 # to a text friendly syntax using markdown |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
75 wid = list_item.widgets['body'] |
1216 | 76 if wid.type == "xhtmlbox": |
77 wid.type = "textbox" | |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
78 wid.value = yield 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 |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
82 template_data["new_list_item_xmlui"] = list_item |
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 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 @defer.inlineCallbacks |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def on_data_post(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
88 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
89 node = data["node"] |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
90 list_item_id = data["list_item_id"] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
92 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
|
93 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
95 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
|
96 except (KeyError, IndexError): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 pass |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 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
|
99 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
100 # we convert back body to XHTML |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
101 body = yield self.host.bridgeCall( |
1216 | 102 "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
|
103 False, profile) |
1216 | 104 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
|
105 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
|
106 |
1216 | 107 extra = {'update': True} |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
108 yield self.host.bridgeCall( |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
109 "listSet", service.full(), node, posted_data, "", list_item_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:
1192
diff
changeset
|
110 data_format.serialise(extra), profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
111 ) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
112 # we don't want to redirect to edit page on success, but to list overview |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
113 data["post_redirect_page"] = ( |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
114 self.getPageByName("lists"), |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
115 service.full(), |
1216 | 116 node or "@", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
117 ) |