annotate libervia/pages/lists/edit/page_meta.py @ 1501:5cc6734093a6

pages (lists/edit): fix serialisation on `listGet` call
author Goffi <goffi@goffi.org>
date Thu, 06 Oct 2022 17:26:31 +0200
parents b46fec21ceb9
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
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):
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
19 self.getPathArgs(request, ["service", "node", "item_id"], service="jid", node="@")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
20 data = self.getRData(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
21 if data["item_id"] is None:
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 @defer.inlineCallbacks
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
26 def prepare_render(self, request):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
27 data = self.getRData(request)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
28 template_data = request.template_data
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
29 service, node, item_id = (
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
30 data.get("service", ""),
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
31 data.get("node", ""),
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
32 data["item_id"],
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
33 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
34 profile = self.getProfile(request)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
35
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
36 # 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
37 # 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
38 ignore = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
39 "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
40 "author",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
41 "author_jid",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
42 "author_email",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
43 "created",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
44 "updated",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
45 "comments_uri",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
46 )
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
47 list_raw = yield self.host.bridgeCall(
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
48 "listGet",
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
49 service.full() if service else "",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
50 node,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
51 C.NO_LIMIT,
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
52 [item_id],
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
53 "",
1501
5cc6734093a6 pages (lists/edit): fix serialisation on `listGet` call
Goffi <goffi@goffi.org>
parents: 1469
diff changeset
54 data_format.serialise({}),
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
55 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
56 )
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
57 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
58 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
59
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
60 try:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
61 # 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
62 list_item.widgets["labels"].type = "string"
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
63 list_item.widgets["labels"].value = list_item.widgets["labels"].value.replace(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
64 "\n", ", "
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
65 )
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
66 except KeyError:
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
67 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
68
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
69 # 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
70 # to a text friendly syntax using markdown
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
71 wid = list_item.widgets['body']
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
72 if wid.type == "xhtmlbox":
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
73 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
74 wid.value = yield self.host.bridgeCall(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
75 "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
76 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
77
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
78 template_data["new_list_item_xmlui"] = list_item
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
79
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
80
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
81 async def on_data_post(self, request):
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
82 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
83 service = data["service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
84 node = data["node"]
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
85 item_id = data["item_id"]
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
86 posted_data = self.getAllPostedData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
87 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
88 self.pageError(request, C.HTTP_BAD_REQUEST)
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
89 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
90 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
91 except (KeyError, IndexError):
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
92 pass
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
93 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
94
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
95 # we convert back body to XHTML
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
96 body = await self.host.bridgeCall(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
97 "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
98 False, profile)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
99 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
100 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
101
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
102 extra = {'update': True}
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
103 await self.host.bridgeCall(
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
104 "listSet", service.full(), node, posted_data, "", 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
105 data_format.serialise(extra), profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
106 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
107 data["post_redirect_page"] = (
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
108 self.getPageByName("list_view"),
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
109 service.full(),
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1195
diff changeset
110 node or "@",
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
111 item_id
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
112 )
1469
b46fec21ceb9 pages (lists/edit): redirect to item instead of list and don't show confirm message
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
113 return C.POST_NO_CONFIRM