Mercurial > libervia-web
comparison libervia/pages/lists/new/page_meta.py @ 1378:e3e303a30a74
pages (tickets): renamed "tickets" to "lists":
"lists" is more generic, and tickets is actually a specific kind of list.
/!\ "tickets_trackers_json" option has been renamed to "lists_directory_json".
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 28 Jan 2021 18:51:44 +0100 |
parents | libervia/pages/tickets/new/page_meta.py@04e7dd6b6f4d |
children | a84383c659b4 |
comparison
equal
deleted
inserted
replaced
1377:46ce79eac754 | 1378:e3e303a30a74 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 from libervia.server.constants import Const as C | |
4 from sat.tools.common import template_xmlui | |
5 from sat.core.log import getLogger | |
6 | |
7 log = getLogger(__name__) | |
8 | |
9 | |
10 name = "list_new" | |
11 access = C.PAGES_ACCESS_PROFILE | |
12 template = "list/create_item.html" | |
13 | |
14 | |
15 async def prepare_render(self, request): | |
16 data = self.getRData(request) | |
17 template_data = request.template_data | |
18 service, node = data.get("service", ""), data.get("node", "") | |
19 profile = self.getProfile(request) | |
20 schema = await self.host.bridgeCall("listSchemaGet", service.full(), node, profile) | |
21 data["schema"] = schema | |
22 # following fields are handled in backend | |
23 ignore = ( | |
24 "author", | |
25 "author_jid", | |
26 "author_email", | |
27 "created", | |
28 "updated", | |
29 "comments_uri", | |
30 "status", | |
31 "milestone", | |
32 "priority", | |
33 ) | |
34 xmlui_obj = template_xmlui.create(self.host, schema, ignore=ignore) | |
35 try: | |
36 # small trick to get a one line text input instead of the big textarea | |
37 xmlui_obj.widgets["labels"].type = "string" | |
38 except KeyError: | |
39 pass | |
40 | |
41 # same as for list_edit, we have to convert for now | |
42 wid = xmlui_obj.widgets['body'] | |
43 if wid.type == "xhtmlbox": | |
44 wid.type = "textbox" | |
45 wid.value = await self.host.bridgeCall( | |
46 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown", | |
47 False, profile) | |
48 template_data["new_list_item_xmlui"] = xmlui_obj | |
49 | |
50 | |
51 async def on_data_post(self, request): | |
52 data = self.getRData(request) | |
53 service = data["service"] | |
54 node = data["node"] | |
55 posted_data = self.getAllPostedData(request) | |
56 if not posted_data["title"] or not posted_data["body"]: | |
57 self.pageError(request, C.HTTP_BAD_REQUEST) | |
58 try: | |
59 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")] | |
60 except (KeyError, IndexError): | |
61 pass | |
62 profile = self.getProfile(request) | |
63 | |
64 # we convert back body to XHTML | |
65 body = await self.host.bridgeCall( | |
66 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML, | |
67 False, profile) | |
68 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, | |
69 body=body)] | |
70 | |
71 | |
72 await self.host.bridgeCall( | |
73 "listSet", service.full(), node, posted_data, "", "", "", profile | |
74 ) | |
75 # we don't want to redirect to creation page on success, but to list overview | |
76 data["post_redirect_page"] = ( | |
77 self.getPageByName("lists"), | |
78 service.full(), | |
79 node or "@", | |
80 ) |