Mercurial > libervia-web
annotate libervia/pages/lists/edit/page_meta.py @ 1466:cff720e26089
pages (blog/view): activate pagination when a single item is shown:
`previous_page_url` and `next_page_url` are set when `item_id` is used. For now, they are
both activated even if there is no item before or after, as it would request to make extra
request to check it. This may be improved in 0.9 by using internal cache.
fix 399
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 30 Sep 2021 17:04:22 +0200 |
parents | a84383c659b4 |
children | b46fec21ceb9 |
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): |
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 | 30 data.get("service", ""), |
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 | 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 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
54 {}, |
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 | 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 | 72 if wid.type == "xhtmlbox": |
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 | 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 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 @defer.inlineCallbacks |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 def on_data_post(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
84 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
85 node = data["node"] |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
86 item_id = data["item_id"] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
88 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
|
89 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
91 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
|
92 except (KeyError, IndexError): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 pass |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 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
|
95 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
96 # 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
|
97 body = yield self.host.bridgeCall( |
1216 | 98 "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
|
99 False, profile) |
1216 | 100 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
|
101 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
|
102 |
1216 | 103 extra = {'update': True} |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
104 yield self.host.bridgeCall( |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
1378
diff
changeset
|
105 "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
|
106 data_format.serialise(extra), profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
107 ) |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
108 # 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
|
109 data["post_redirect_page"] = ( |
1378
e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents:
1302
diff
changeset
|
110 self.getPageByName("lists"), |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
111 service.full(), |
1216 | 112 node or "@", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
113 ) |