Mercurial > libervia-web
comparison libervia/pages/tickets/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 | 5e67c2564779 |
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 |
9 from sat.core.log import getLogger | 9 from sat.core.log import getLogger |
10 | 10 |
11 log = getLogger(__name__) | 11 log = getLogger(__name__) |
12 """ticket handling pages""" | 12 """ticket handling pages""" |
13 | 13 |
14 name = u"tickets_edit" | 14 name = "tickets_edit" |
15 access = C.PAGES_ACCESS_PROFILE | 15 access = C.PAGES_ACCESS_PROFILE |
16 template = u"ticket/edit.html" | 16 template = "ticket/edit.html" |
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 # we don't ignore "author" below to keep it when a ticket is edited | 41 # we don't ignore "author" below to keep it when a ticket is edited |
42 # by node owner/admin and "consistent publisher" is activated | 42 # by node owner/admin and "consistent publisher" is activated |
49 "updated", | 49 "updated", |
50 "comments_uri", | 50 "comments_uri", |
51 ) | 51 ) |
52 tickets = yield self.host.bridgeCall( | 52 tickets = yield self.host.bridgeCall( |
53 "ticketsGet", | 53 "ticketsGet", |
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 # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion | 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 | 74 # to a text friendly syntax using markdown |
75 wid = ticket.widgets[u'body'] | 75 wid = ticket.widgets['body'] |
76 if wid.type == u"xhtmlbox": | 76 if wid.type == "xhtmlbox": |
77 wid.type = u"textbox" | 77 wid.type = "textbox" |
78 wid.value = yield self.host.bridgeCall( | 78 wid.value = yield self.host.bridgeCall( |
79 u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown", | 79 "syntaxConvert", wid.value, C.SYNTAX_XHTML, "markdown", |
80 False, profile) | 80 False, profile) |
81 | 81 |
82 template_data[u"new_ticket_xmlui"] = ticket | 82 template_data["new_ticket_xmlui"] = ticket |
83 | 83 |
84 | 84 |
85 @defer.inlineCallbacks | 85 @defer.inlineCallbacks |
86 def on_data_post(self, request): | 86 def on_data_post(self, request): |
87 data = self.getRData(request) | 87 data = self.getRData(request) |
97 pass | 97 pass |
98 profile = self.getProfile(request) | 98 profile = self.getProfile(request) |
99 | 99 |
100 # we convert back body to XHTML | 100 # we convert back body to XHTML |
101 body = yield self.host.bridgeCall( | 101 body = yield self.host.bridgeCall( |
102 u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML, | 102 "syntaxConvert", posted_data['body'][0], "markdown", C.SYNTAX_XHTML, |
103 False, profile) | 103 False, profile) |
104 posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, | 104 posted_data['body'] = ['<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, |
105 body=body)] | 105 body=body)] |
106 | 106 |
107 extra = {u'update': True} | 107 extra = {'update': True} |
108 yield self.host.bridgeCall( | 108 yield self.host.bridgeCall( |
109 "ticketSet", service.full(), node, posted_data, u"", ticket_id, | 109 "ticketSet", service.full(), node, posted_data, "", ticket_id, |
110 data_format.serialise(extra), profile | 110 data_format.serialise(extra), profile |
111 ) | 111 ) |
112 # we don't want to redirect to edit page on success, but to tickets list | 112 # we don't want to redirect to edit page on success, but to tickets list |
113 data["post_redirect_page"] = ( | 113 data["post_redirect_page"] = ( |
114 self.getPageByName(u"tickets"), | 114 self.getPageByName("tickets"), |
115 service.full(), | 115 service.full(), |
116 node or u"@", | 116 node or "@", |
117 ) | 117 ) |