annotate libervia/web/pages/lists/edit/page_meta.py @ 1543:f00497c00e38

pages (chat): fix `own_jid` exposure: `own_jid` is a `JID` instance, and must be casted to str to be exposed.
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2023 12:05:48 +0200
parents eb00d593801d
children
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
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
4 from libervia.web.server.constants import Const as C
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
5 from libervia.backend.core.i18n import _
1096
01538d8a77be merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
7 from libervia.backend.tools.common import template_xmlui
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
8 from libervia.backend.tools.common import data_format
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
9 from libervia.backend.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):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
19 self.get_path_args(request, ["service", "node", "item_id"], service="jid", node="@")
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
20 data = self.get_r_data(request)
1387
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"))
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
23 self.page_error(request, C.HTTP_BAD_REQUEST)
1096
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):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
27 data = self.get_r_data(request)
1096
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 )
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
34 profile = self.get_profile(request)
1096
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 )
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
47 list_raw = yield self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
48 "list_get",
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"
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
74 wid.value = yield self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
75 "syntax_convert", 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):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
82 data = self.get_r_data(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"]
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
86 posted_data = self.get_all_posted_data(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"]:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
88 self.page_error(request, C.HTTP_BAD_REQUEST)
1096
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
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
93 profile = self.get_profile(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
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
96 body = await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
97 "syntax_convert", 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}
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
103 await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
104 "list_set", 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"] = (
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1501
diff changeset
108 self.get_page_by_name("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