annotate libervia/pages/tickets/new/page_meta.py @ 1376:1b94a5ab155f

pages (blog/view): Full-Text Search is used when `search` query argument is present the new `LiberviaPage.handleSearch` method implements FTS in PubSub based features.
author Goffi <goffi@goffi.org>
date Fri, 11 Dec 2020 17:35:06 +0100
parents 04e7dd6b6f4d
children
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 twisted.internet import defer
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.tools.common import template_xmlui
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
7
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1143
diff changeset
8 log = getLogger(__name__)
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 """ticket handling pages"""
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
11 name = "tickets_new"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 access = C.PAGES_ACCESS_PROFILE
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
13 template = "ticket/create.html"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
16 async def prepare_render(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 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
18 template_data = request.template_data
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
19 service, node = data.get("service", ""), data.get("node", "")
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 profile = self.getProfile(request)
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
21 schema = await self.host.bridgeCall("ticketsSchemaGet", service.full(), node, profile)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
22 data["schema"] = schema
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 # following fields are handled in backend
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
24 ignore = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
25 "author",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
26 "author_jid",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
27 "author_email",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
28 "created",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
29 "updated",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
30 "comments_uri",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
31 "status",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
32 "milestone",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
33 "priority",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
34 )
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 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
36 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
37 # 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
38 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
39 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
40 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
41
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
42 # same as for tickets_edit, we have to convert for now
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
43 wid = xmlui_obj.widgets['body']
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
44 if wid.type == "xhtmlbox":
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
45 wid.type = "textbox"
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
46 wid.value = await self.host.bridgeCall(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
47 "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
48 False, profile)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
49 template_data["new_ticket_xmlui"] = xmlui_obj
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
50
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
52 async def on_data_post(self, request):
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
54 service = data["service"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
55 node = data["node"]
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 posted_data = self.getAllPostedData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
57 if not posted_data["title"] or not posted_data["body"]:
970
bc28b9068f91 page(tickets/new): refuse request if title is not set
Goffi <goffi@goffi.org>
parents: 969
diff changeset
58 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
59 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
60 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
61 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
62 pass
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 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
64
7bd47d32da87 pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
65 # we convert back body to XHTML
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
66 body = await self.host.bridgeCall(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
67 "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
68 False, profile)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
69 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
70 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
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
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
73 await self.host.bridgeCall(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
74 "ticketSet", service.full(), node, posted_data, "", "", "", profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
75 )
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 # we don't want to redirect to creation page on success, but to tickets list
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
77 data["post_redirect_page"] = (
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
78 self.getPageByName("tickets"),
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
79 service.full(),
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1194
diff changeset
80 node or "@",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
81 )