Mercurial > libervia-web
annotate libervia/pages/tickets/new/page_meta.py @ 1216:b2d067339de3
python 3 port:
/!\ Python 3.6+ is now needed to use libervia
/!\ instability may occur and features may not be working anymore, this will improve with time
/!\ TxJSONRPC dependency has been removed
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog,
JSON RPC related code).
Adapted code to work without `html` and `themes` dirs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:12:31 +0200 |
parents | bed008b65d7c |
children | f511f8fbbf8a |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
967 | 2 # -*- coding: utf-8 -*- |
3 | |
4 from libervia.server.constants import Const as C | |
5 from twisted.internet import defer | |
6 from sat.tools.common import template_xmlui | |
7 from sat.core.log import getLogger | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
8 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1143
diff
changeset
|
9 log = getLogger(__name__) |
967 | 10 """ticket handling pages""" |
11 | |
1216 | 12 name = "tickets_new" |
967 | 13 access = C.PAGES_ACCESS_PROFILE |
1216 | 14 template = "ticket/create.html" |
967 | 15 |
16 | |
17 @defer.inlineCallbacks | |
18 def prepare_render(self, request): | |
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 | 21 service, node = data.get("service", ""), data.get("node", "") |
967 | 22 profile = self.getProfile(request) |
1098
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1088
diff
changeset
|
23 schema = yield self.host.bridgeCall("ticketsSchemaGet", 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 | 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 | 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 | 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 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
44 # same as for tickets_edit, we have to convert for now |
1216 | 45 wid = xmlui_obj.widgets['body'] |
46 if wid.type == "xhtmlbox": | |
47 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
|
48 wid.value = yield self.host.bridgeCall( |
1216 | 49 "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
|
50 False, profile) |
1216 | 51 template_data["new_ticket_xmlui"] = xmlui_obj |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
52 |
967 | 53 |
54 @defer.inlineCallbacks | |
55 def on_data_post(self, request): | |
56 data = self.getRData(request) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
57 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
58 node = data["node"] |
967 | 59 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
60 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
|
61 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
|
62 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
63 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
|
64 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
|
65 pass |
967 | 66 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
|
67 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
68 # 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
|
69 body = yield self.host.bridgeCall( |
1216 | 70 "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
|
71 False, profile) |
1216 | 72 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
|
73 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
|
74 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
75 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
76 yield self.host.bridgeCall( |
1216 | 77 "ticketSet", service.full(), node, posted_data, "", "", "", profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
78 ) |
967 | 79 # 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
|
80 data["post_redirect_page"] = ( |
1216 | 81 self.getPageByName("tickets"), |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
82 service.full(), |
1216 | 83 node or "@", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
84 ) |