Mercurial > libervia-web
comparison libervia/pages/tickets/new/page_meta.py @ 1302:04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Jul 2020 09:08:47 +0200 |
parents | f511f8fbbf8a |
children |
comparison
equal
deleted
inserted
replaced
1301:ff44f822bfdd | 1302:04e7dd6b6f4d |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | |
3 | 2 |
4 from libervia.server.constants import Const as C | 3 from libervia.server.constants import Const as C |
5 from twisted.internet import defer | 4 from twisted.internet import defer |
6 from sat.tools.common import template_xmlui | 5 from sat.tools.common import template_xmlui |
7 from sat.core.log import getLogger | 6 from sat.core.log import getLogger |
12 name = "tickets_new" | 11 name = "tickets_new" |
13 access = C.PAGES_ACCESS_PROFILE | 12 access = C.PAGES_ACCESS_PROFILE |
14 template = "ticket/create.html" | 13 template = "ticket/create.html" |
15 | 14 |
16 | 15 |
17 @defer.inlineCallbacks | 16 async def prepare_render(self, request): |
18 def prepare_render(self, request): | |
19 data = self.getRData(request) | 17 data = self.getRData(request) |
20 template_data = request.template_data | 18 template_data = request.template_data |
21 service, node = data.get("service", ""), data.get("node", "") | 19 service, node = data.get("service", ""), data.get("node", "") |
22 profile = self.getProfile(request) | 20 profile = self.getProfile(request) |
23 schema = yield self.host.bridgeCall("ticketsSchemaGet", service.full(), node, profile) | 21 schema = await self.host.bridgeCall("ticketsSchemaGet", service.full(), node, profile) |
24 data["schema"] = schema | 22 data["schema"] = schema |
25 # following fields are handled in backend | 23 # following fields are handled in backend |
26 ignore = ( | 24 ignore = ( |
27 "author", | 25 "author", |
28 "author_jid", | 26 "author_jid", |
43 | 41 |
44 # same as for tickets_edit, we have to convert for now | 42 # same as for tickets_edit, we have to convert for now |
45 wid = xmlui_obj.widgets['body'] | 43 wid = xmlui_obj.widgets['body'] |
46 if wid.type == "xhtmlbox": | 44 if wid.type == "xhtmlbox": |
47 wid.type = "textbox" | 45 wid.type = "textbox" |
48 wid.value = yield self.host.bridgeCall( | 46 wid.value = await self.host.bridgeCall( |
49 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown", | 47 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown", |
50 False, profile) | 48 False, profile) |
51 template_data["new_ticket_xmlui"] = xmlui_obj | 49 template_data["new_ticket_xmlui"] = xmlui_obj |
52 | 50 |
53 | 51 |
54 @defer.inlineCallbacks | 52 async def on_data_post(self, request): |
55 def on_data_post(self, request): | |
56 data = self.getRData(request) | 53 data = self.getRData(request) |
57 service = data["service"] | 54 service = data["service"] |
58 node = data["node"] | 55 node = data["node"] |
59 posted_data = self.getAllPostedData(request) | 56 posted_data = self.getAllPostedData(request) |
60 if not posted_data["title"] or not posted_data["body"]: | 57 if not posted_data["title"] or not posted_data["body"]: |
64 except (KeyError, IndexError): | 61 except (KeyError, IndexError): |
65 pass | 62 pass |
66 profile = self.getProfile(request) | 63 profile = self.getProfile(request) |
67 | 64 |
68 # we convert back body to XHTML | 65 # we convert back body to XHTML |
69 body = yield self.host.bridgeCall( | 66 body = await self.host.bridgeCall( |
70 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML, | 67 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML, |
71 False, profile) | 68 False, profile) |
72 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, | 69 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, |
73 body=body)] | 70 body=body)] |
74 | 71 |
75 | 72 |
76 yield self.host.bridgeCall( | 73 await self.host.bridgeCall( |
77 "ticketSet", service.full(), node, posted_data, "", "", "", profile | 74 "ticketSet", service.full(), node, posted_data, "", "", "", profile |
78 ) | 75 ) |
79 # we don't want to redirect to creation page on success, but to tickets list | 76 # we don't want to redirect to creation page on success, but to tickets list |
80 data["post_redirect_page"] = ( | 77 data["post_redirect_page"] = ( |
81 self.getPageByName("tickets"), | 78 self.getPageByName("tickets"), |