comparison libervia/pages/lists/edit/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/edit/page_meta.py@04e7dd6b6f4d
children a84383c659b4
comparison
equal deleted inserted replaced
1377:46ce79eac754 1378:e3e303a30a74
1 #!/usr/bin/env python3
2
3
4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from sat.tools.common import template_xmlui
8 from sat.tools.common import data_format
9 from sat.core.log import getLogger
10
11 log = getLogger(__name__)
12
13 name = "list_edit"
14 access = C.PAGES_ACCESS_PROFILE
15 template = "list/edit.html"
16
17
18 def parse_url(self, request):
19 try:
20 item_id = self.nextPath(request)
21 except IndexError:
22 log.warning(_("no list item id specified"))
23 self.pageError(request, C.HTTP_BAD_REQUEST)
24
25 data = self.getRData(request)
26 data["list_item_id"] = item_id
27
28
29 @defer.inlineCallbacks
30 def prepare_render(self, request):
31 data = self.getRData(request)
32 template_data = request.template_data
33 service, node, list_item_id = (
34 data.get("service", ""),
35 data.get("node", ""),
36 data["list_item_id"],
37 )
38 profile = self.getProfile(request)
39
40 # we don't ignore "author" below to keep it when a list item is edited
41 # by node owner/admin and "consistent publisher" is activated
42 ignore = (
43 "publisher",
44 "author",
45 "author_jid",
46 "author_email",
47 "created",
48 "updated",
49 "comments_uri",
50 )
51 list_raw = yield self.host.bridgeCall(
52 "listGet",
53 service.full() if service else "",
54 node,
55 C.NO_LIMIT,
56 [list_item_id],
57 "",
58 {},
59 profile,
60 )
61 list_items, metadata = data_format.deserialise(list_raw, type_check=list)
62 list_item = [template_xmlui.create(self.host, x, ignore=ignore) for x in list_items][0]
63
64 try:
65 # small trick to get a one line text input instead of the big textarea
66 list_item.widgets["labels"].type = "string"
67 list_item.widgets["labels"].value = list_item.widgets["labels"].value.replace(
68 "\n", ", "
69 )
70 except KeyError:
71 pass
72
73 # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion
74 # to a text friendly syntax using markdown
75 wid = list_item.widgets['body']
76 if wid.type == "xhtmlbox":
77 wid.type = "textbox"
78 wid.value = yield self.host.bridgeCall(
79 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown",
80 False, profile)
81
82 template_data["new_list_item_xmlui"] = list_item
83
84
85 @defer.inlineCallbacks
86 def on_data_post(self, request):
87 data = self.getRData(request)
88 service = data["service"]
89 node = data["node"]
90 list_item_id = data["list_item_id"]
91 posted_data = self.getAllPostedData(request)
92 if not posted_data["title"] or not posted_data["body"]:
93 self.pageError(request, C.HTTP_BAD_REQUEST)
94 try:
95 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")]
96 except (KeyError, IndexError):
97 pass
98 profile = self.getProfile(request)
99
100 # we convert back body to XHTML
101 body = yield self.host.bridgeCall(
102 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML,
103 False, profile)
104 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML,
105 body=body)]
106
107 extra = {'update': True}
108 yield self.host.bridgeCall(
109 "listSet", service.full(), node, posted_data, "", list_item_id,
110 data_format.serialise(extra), profile
111 )
112 # we don't want to redirect to edit page on success, but to list overview
113 data["post_redirect_page"] = (
114 self.getPageByName("lists"),
115 service.full(),
116 node or "@",
117 )