comparison libervia/web/pages/merge-requests/edit/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/merge-requests/edit/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.web.server.constants import Const as C
5 from libervia.backend.core.i18n import _
6 from libervia.backend.tools.common import template_xmlui
7 from libervia.backend.tools.common import data_format
8 from libervia.backend.core.log import getLogger
9
10 """merge-requests edition"""
11
12 name = "merge-requests_edit"
13 access = C.PAGES_ACCESS_PROFILE
14 template = "merge-request/edit.html"
15 log = getLogger(__name__)
16
17
18 def parse_url(self, request):
19 try:
20 item_id = self.next_path(request)
21 except IndexError:
22 log.warning(_("no list item id specified"))
23 self.page_error(request, C.HTTP_BAD_REQUEST)
24
25 data = self.get_r_data(request)
26 data["list_item_id"] = item_id
27
28
29 async def prepare_render(self, request):
30 data = self.get_r_data(request)
31 template_data = request.template_data
32 service, node, list_item_id = (
33 data.get("service", ""),
34 data.get("node", ""),
35 data["list_item_id"],
36 )
37 profile = self.get_profile(request)
38
39 ignore = (
40 "publisher",
41 "author",
42 "author_jid",
43 "author_email",
44 "created",
45 "updated",
46 "comments_uri",
47 "request_data",
48 "type",
49 )
50 merge_requests = data_format.deserialise(
51 await self.host.bridge_call(
52 "merge_requests_get",
53 service.full() if service else "",
54 node,
55 C.NO_LIMIT,
56 [list_item_id],
57 "",
58 data_format.serialise({}),
59 profile,
60 )
61 )
62 list_item = template_xmlui.create(
63 self.host, merge_requests['items'][0], ignore=ignore
64 )
65
66 try:
67 # small trick to get a one line text input instead of the big textarea
68 list_item.widgets["labels"].type = "string"
69 list_item.widgets["labels"].value = list_item.widgets["labels"].value.replace(
70 "\n", ", "
71 )
72 except KeyError:
73 pass
74
75 # same as list_edit
76 wid = list_item.widgets['body']
77 if wid.type == "xhtmlbox":
78 wid.type = "textbox"
79 wid.value = await self.host.bridge_call(
80 "syntax_convert", wid.value, C.SYNTAX_XHTML, "markdown",
81 False, profile)
82
83 template_data["new_list_item_xmlui"] = list_item
84
85
86 async def on_data_post(self, request):
87 data = self.get_r_data(request)
88 service = data["service"]
89 node = data["node"]
90 list_item_id = data["list_item_id"]
91 posted_data = self.get_all_posted_data(request)
92 if not posted_data["title"] or not posted_data["body"]:
93 self.page_error(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.get_profile(request)
99
100 # we convert back body to XHTML
101 body = await self.host.bridge_call(
102 "syntax_convert", 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 await self.host.bridge_call(
109 "merge_request_set",
110 service.full(),
111 node,
112 "",
113 "auto",
114 posted_data,
115 "",
116 list_item_id,
117 data_format.serialise(extra),
118 profile,
119 )
120 # we don't want to redirect to edit page on success, but to list overview
121 data["post_redirect_page"] = (
122 self.get_page_by_name("merge-requests"),
123 service.full(),
124 node or "@",
125 )