Mercurial > libervia-web
annotate libervia/pages/tickets/new/page_meta.py @ 1146:76d75423ef53
server: tasks manager first draft:
A new task manager will check /tasks directory of website to scripts to execute before launching the site. This allows to generate docs, scripts, or do anything else useful.
Generated files are put in in sat local dir, in cache, and are accessible from the website using the new "build_dir" variable.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Jan 2019 08:58:41 +0100 |
parents | 29eb15062416 |
children | bed008b65d7c |
rev | line source |
---|---|
967 | 1 #!/usr/bin/env python2.7 |
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 | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
12 name = u"tickets_new" |
967 | 13 access = C.PAGES_ACCESS_PROFILE |
14 template = u"ticket/create.html" | |
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 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
21 service, node = data.get(u"service", u""), data.get(u"node", u"") |
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 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
40 xmlui_obj.widgets[u"labels"].type = u"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 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
45 wid = xmlui_obj.widgets[u'body'] |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
46 if wid.type == u"xhtmlbox": |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
47 wid.type = u"textbox" |
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( |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
49 u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown", |
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) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
51 template_data[u"new_ticket_xmlui"] = xmlui_obj |
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( |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
70 u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML, |
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) |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
72 posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, |
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( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
77 "ticketSet", service.full(), node, posted_data, u"", u"", {}, profile |
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"] = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
81 self.getPageByName(u"tickets"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
82 service.full(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
83 node or u"@", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
84 ) |