Mercurial > libervia-web
annotate src/pages/tickets/new/page_meta.py @ 1114:1957d02df281
doc (README): removed version from README
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Jul 2018 08:27:17 +0200 |
parents | cdd389ef97bc |
children |
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 |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
9 log = getLogger("pages/ticket") |
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 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
43 template_data[u"new_ticket_xmlui"] = xmlui_obj |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
44 |
967 | 45 |
46 @defer.inlineCallbacks | |
47 def on_data_post(self, request): | |
48 data = self.getRData(request) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
49 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
50 node = data["node"] |
967 | 51 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
52 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
|
53 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
|
54 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
55 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
|
56 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
|
57 pass |
967 | 58 profile = self.getProfile(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
59 yield self.host.bridgeCall( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
60 "ticketSet", service.full(), node, posted_data, u"", u"", {}, profile |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
61 ) |
967 | 62 # 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
|
63 data["post_redirect_page"] = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
64 self.getPageByName(u"tickets"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
65 service.full(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
66 node or u"@", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
67 ) |