comparison libervia/pages/tickets/edit/page_meta.py @ 1143:7bd47d32da87

pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket: there is currently no way to edit XHTML directly inside the browser with Libervia pages, this patch works around this by doing a conversion to/from markdown.
author Goffi <goffi@goffi.org>
date Sat, 19 Jan 2019 11:42:37 +0100
parents 28e3eb3bb217
children 29eb15062416
comparison
equal deleted inserted replaced
1142:003597f895a0 1143:7bd47d32da87
64 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace( 64 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace(
65 u"\n", ", " 65 u"\n", ", "
66 ) 66 )
67 except KeyError: 67 except KeyError:
68 pass 68 pass
69
70 # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion
71 # to a text friendly syntax using markdown
72 wid = ticket.widgets[u'body']
73 if wid.type == u"xhtmlbox":
74 wid.type = u"textbox"
75 wid.value = yield self.host.bridgeCall(
76 u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown",
77 False, profile)
78
69 template_data[u"new_ticket_xmlui"] = ticket 79 template_data[u"new_ticket_xmlui"] = ticket
70 80
71 81
72 @defer.inlineCallbacks 82 @defer.inlineCallbacks
73 def on_data_post(self, request): 83 def on_data_post(self, request):
81 try: 91 try:
82 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")] 92 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")]
83 except (KeyError, IndexError): 93 except (KeyError, IndexError):
84 pass 94 pass
85 profile = self.getProfile(request) 95 profile = self.getProfile(request)
96
97 # we convert back body to XHTML
98 body = yield self.host.bridgeCall(
99 u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML,
100 False, profile)
101 posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML,
102 body=body)]
103
86 yield self.host.bridgeCall( 104 yield self.host.bridgeCall(
87 "ticketSet", service.full(), node, posted_data, u"", ticket_id, {}, profile 105 "ticketSet", service.full(), node, posted_data, u"", ticket_id, {}, profile
88 ) 106 )
89 # we don't want to redirect to edit page on success, but to tickets list 107 # we don't want to redirect to edit page on success, but to tickets list
90 data["post_redirect_page"] = ( 108 data["post_redirect_page"] = (