comparison libervia/pages/merge-requests/edit/page_meta.py @ 1216:b2d067339de3

python 3 port: /!\ Python 3.6+ is now needed to use libervia /!\ instability may occur and features may not be working anymore, this will improve with time /!\ TxJSONRPC dependency has been removed The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog, JSON RPC related code). Adapted code to work without `html` and `themes` dirs.
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:12:31 +0200
parents bed008b65d7c
children f511f8fbbf8a
comparison
equal deleted inserted replaced
1215:f14ab8a25e8b 1216:b2d067339de3
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _ 5 from sat.core.i18n import _
6 from twisted.internet import defer 6 from twisted.internet import defer
8 from sat.tools.common import data_format 8 from sat.tools.common import data_format
9 from sat.core.log import getLogger 9 from sat.core.log import getLogger
10 10
11 """merge-requests edition""" 11 """merge-requests edition"""
12 12
13 name = u"merge-requests_edit" 13 name = "merge-requests_edit"
14 access = C.PAGES_ACCESS_PROFILE 14 access = C.PAGES_ACCESS_PROFILE
15 template = u"merge-request/edit.html" 15 template = "merge-request/edit.html"
16 log = getLogger(__name__) 16 log = getLogger(__name__)
17 17
18 18
19 def parse_url(self, request): 19 def parse_url(self, request):
20 try: 20 try:
21 item_id = self.nextPath(request) 21 item_id = self.nextPath(request)
22 except IndexError: 22 except IndexError:
23 log.warning(_(u"no ticket id specified")) 23 log.warning(_("no ticket id specified"))
24 self.pageError(request, C.HTTP_BAD_REQUEST) 24 self.pageError(request, C.HTTP_BAD_REQUEST)
25 25
26 data = self.getRData(request) 26 data = self.getRData(request)
27 data[u"ticket_id"] = item_id 27 data["ticket_id"] = item_id
28 28
29 29
30 @defer.inlineCallbacks 30 @defer.inlineCallbacks
31 def prepare_render(self, request): 31 def prepare_render(self, request):
32 data = self.getRData(request) 32 data = self.getRData(request)
33 template_data = request.template_data 33 template_data = request.template_data
34 service, node, ticket_id = ( 34 service, node, ticket_id = (
35 data.get(u"service", u""), 35 data.get("service", ""),
36 data.get(u"node", u""), 36 data.get("node", ""),
37 data[u"ticket_id"], 37 data["ticket_id"],
38 ) 38 )
39 profile = self.getProfile(request) 39 profile = self.getProfile(request)
40 40
41 ignore = ( 41 ignore = (
42 "publisher", 42 "publisher",
49 "request_data", 49 "request_data",
50 "type", 50 "type",
51 ) 51 )
52 tickets = yield self.host.bridgeCall( 52 tickets = yield self.host.bridgeCall(
53 "mergeRequestsGet", 53 "mergeRequestsGet",
54 service.full() if service else u"", 54 service.full() if service else "",
55 node, 55 node,
56 C.NO_LIMIT, 56 C.NO_LIMIT,
57 [ticket_id], 57 [ticket_id],
58 "", 58 "",
59 {}, 59 {},
61 ) 61 )
62 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0] 62 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0]
63 63
64 try: 64 try:
65 # small trick to get a one line text input instead of the big textarea 65 # small trick to get a one line text input instead of the big textarea
66 ticket.widgets[u"labels"].type = u"string" 66 ticket.widgets["labels"].type = "string"
67 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace( 67 ticket.widgets["labels"].value = ticket.widgets["labels"].value.replace(
68 u"\n", ", " 68 "\n", ", "
69 ) 69 )
70 except KeyError: 70 except KeyError:
71 pass 71 pass
72 72
73 # same as tickets_edit 73 # same as tickets_edit
74 wid = ticket.widgets[u'body'] 74 wid = ticket.widgets['body']
75 if wid.type == u"xhtmlbox": 75 if wid.type == "xhtmlbox":
76 wid.type = u"textbox" 76 wid.type = "textbox"
77 wid.value = yield self.host.bridgeCall( 77 wid.value = yield self.host.bridgeCall(
78 u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown", 78 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown",
79 False, profile) 79 False, profile)
80 80
81 template_data[u"new_ticket_xmlui"] = ticket 81 template_data["new_ticket_xmlui"] = ticket
82 82
83 83
84 @defer.inlineCallbacks 84 @defer.inlineCallbacks
85 def on_data_post(self, request): 85 def on_data_post(self, request):
86 data = self.getRData(request) 86 data = self.getRData(request)
96 pass 96 pass
97 profile = self.getProfile(request) 97 profile = self.getProfile(request)
98 98
99 # we convert back body to XHTML 99 # we convert back body to XHTML
100 body = yield self.host.bridgeCall( 100 body = yield self.host.bridgeCall(
101 u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML, 101 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML,
102 False, profile) 102 False, profile)
103 posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, 103 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML,
104 body=body)] 104 body=body)]
105 105
106 extra = {u'update': True} 106 extra = {'update': True}
107 yield self.host.bridgeCall( 107 yield self.host.bridgeCall(
108 "mergeRequestSet", 108 "mergeRequestSet",
109 service.full(), 109 service.full(),
110 node, 110 node,
111 u"", 111 "",
112 u"auto", 112 "auto",
113 posted_data, 113 posted_data,
114 u"", 114 "",
115 ticket_id, 115 ticket_id,
116 data_format.serialise(extra), 116 data_format.serialise(extra),
117 profile, 117 profile,
118 ) 118 )
119 # we don't want to redirect to edit page on success, but to tickets list 119 # we don't want to redirect to edit page on success, but to tickets list
120 data["post_redirect_page"] = ( 120 data["post_redirect_page"] = (
121 self.getPageByName(u"merge-requests"), 121 self.getPageByName("merge-requests"),
122 service.full(), 122 service.full(),
123 node or u"@", 123 node or "@",
124 ) 124 )