annotate libervia/pages/lists/new/page_meta.py @ 1433:1a5410981c45

pages: get last page by default with RSM: When `max_items` is not used, Pubsub (and thus RSM) is actually returning results in chronological order. As most of time we want latest items first, `getPubsubExtra` now set `before` to get last page by default (the one with most recent items).
author Goffi <goffi@goffi.org>
date Sun, 06 Jun 2021 19:40:07 +0200
parents a84383c659b4
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: 1194
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.tools.common import template_xmlui
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
6
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1143
diff changeset
7 log = getLogger(__name__)
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
8
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
10 name = "list_new"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 access = C.PAGES_ACCESS_PROFILE
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
12 template = "list/create_item.html"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
15 def parse_url(self, request):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
16 self.getPathArgs(request, ["service", "node"], service="jid", node="@")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
17
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
18 async def prepare_render(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 data = self.getRData(request)
973
2e75dc986e03 pages (tickets): URLs for list and new are set in the template for the whole subhierarchy
Goffi <goffi@goffi.org>
parents: 971
diff changeset
20 template_data = request.template_data
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
21 service, node = data.get("service", ""), data.get("node", "")
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 profile = self.getProfile(request)
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
23 schema = await self.host.bridgeCall("listSchemaGet", service.full(), node, profile)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
24 data["schema"] = schema
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 # following fields are handled in backend
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
26 ignore = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
27 "author",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
28 "author_jid",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
29 "author_email",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
30 "created",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
31 "updated",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
32 "comments_uri",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
33 "status",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
34 "milestone",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
35 "priority",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
36 )
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 xmlui_obj = template_xmlui.create(self.host, schema, ignore=ignore)
971
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
38 try:
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
39 # small trick to get a one line text input instead of the big textarea
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
40 xmlui_obj.widgets["labels"].type = "string"
971
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
41 except KeyError:
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
42 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
43
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
44 try:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
45 wid = xmlui_obj.widgets['body']
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
46 except KeyError:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
47 pass
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
48 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
49 if wid.type == "xhtmlbox":
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
50 # same as for list_edit, we have to convert for now
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
51 wid.type = "textbox"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
52 wid.value = await self.host.bridgeCall(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
53 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
54 False, profile)
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
55 template_data["new_list_item_xmlui"] = xmlui_obj
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
56
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
58 async def on_data_post(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
60 service = data["service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
61 node = data["node"]
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 posted_data = self.getAllPostedData(request)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
63 if (("title" in posted_data and not posted_data["title"])
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
64 or ("body" in posted_data and not posted_data["body"])):
970
bc28b9068f91 page(tickets/new): refuse request if title is not set
Goffi <goffi@goffi.org>
parents: 969
diff changeset
65 self.pageError(request, C.HTTP_BAD_REQUEST)
971
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
66 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
67 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")]
971
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
68 except (KeyError, IndexError):
6e966ef8d69f page(tickets/new): use string instead of textbox for labels, and use comma to split them
Goffi <goffi@goffi.org>
parents: 970
diff changeset
69 pass
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 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
71
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
72 # we convert back body to XHTML
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
73 if "body" in posted_data:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
74 body = await self.host.bridgeCall(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
75 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
76 False, profile)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
77 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
78 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
79
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
80
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
81 await self.host.bridgeCall(
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
82 "listSet", service.full(), node, posted_data, "", "", "", profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
83 )
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
84 # we don't want to redirect to creation page on success, but to list overview
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
85 data["post_redirect_page"] = (
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1302
diff changeset
86 self.getPageByName("lists"),
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
87 service.full(),
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
88 node or "@",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
89 )