Mercurial > libervia-web
annotate libervia/pages/tickets/edit/page_meta.py @ 1194:bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
"update" was not set in extra, as a result some metadata could be lost on update (author, comments_uri).
fix 301
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 14 Jun 2019 12:50:59 +0200 |
parents | 7b05ebc46141 |
children | 5e67c2564779 |
rev | line source |
---|---|
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from libervia.server.constants import Const as C |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from sat.core.i18n import _ |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from twisted.internet import defer |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from sat.tools.common import template_xmlui |
1194
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1192
diff
changeset
|
8 from sat.tools.common import data_format |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from sat.core.log import getLogger |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
10 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1143
diff
changeset
|
11 log = getLogger(__name__) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 """ticket handling pages""" |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
14 name = u"tickets_edit" |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 access = C.PAGES_ACCESS_PROFILE |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 template = u"ticket/edit.html" |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 def parse_url(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 try: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 item_id = self.nextPath(request) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 except IndexError: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 log.warning(_(u"no ticket id specified")) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
27 data[u"ticket_id"] = item_id |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
28 |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 @defer.inlineCallbacks |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def prepare_render(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 data = self.getRData(request) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 template_data = request.template_data |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
34 service, node, ticket_id = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
35 data.get(u"service", u""), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
36 data.get(u"node", u""), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
37 data[u"ticket_id"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
38 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 profile = self.getProfile(request) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
1192
7b05ebc46141
pages (tickets/edit): don't ignore "author" anymore, to keep it when owner/admin modify a ticket
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
41 # we don't ignore "author" below to keep it when a ticket is edited |
7b05ebc46141
pages (tickets/edit): don't ignore "author" anymore, to keep it when owner/admin modify a ticket
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
42 # by node owner/admin and "consistent publisher" is activated |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
43 ignore = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
44 "publisher", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
45 "author_jid", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
46 "author_email", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
47 "created", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
48 "updated", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
49 "comments_uri", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
50 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
51 tickets = yield self.host.bridgeCall( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
52 "ticketsGet", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
53 service.full() if service else u"", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
54 node, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
55 C.NO_LIMIT, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
56 [ticket_id], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
57 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
58 {}, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
59 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
60 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0] |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 try: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 # small trick to get a one line text input instead of the big textarea |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
65 ticket.widgets[u"labels"].type = u"string" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
66 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
67 u"\n", ", " |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
68 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 except KeyError: |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 pass |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
71 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
72 # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
73 # to a text friendly syntax using markdown |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
74 wid = ticket.widgets[u'body'] |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
75 if wid.type == u"xhtmlbox": |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
76 wid.type = u"textbox" |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
77 wid.value = yield self.host.bridgeCall( |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
78 u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown", |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
79 False, profile) |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
80 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
81 template_data[u"new_ticket_xmlui"] = ticket |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
82 |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 @defer.inlineCallbacks |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 def on_data_post(self, request): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
87 service = data["service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
88 node = data["node"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
89 ticket_id = data["ticket_id"] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 posted_data = self.getAllPostedData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
91 if not posted_data["title"] or not posted_data["body"]: |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 self.pageError(request, C.HTTP_BAD_REQUEST) |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
94 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")] |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 except (KeyError, IndexError): |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 pass |
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 profile = self.getProfile(request) |
1143
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
98 |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
99 # we convert back body to XHTML |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
100 body = yield self.host.bridgeCall( |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
101 u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML, |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
102 False, profile) |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
103 posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML, |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
104 body=body)] |
7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
105 |
1194
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1192
diff
changeset
|
106 extra = {u'update': True} |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
107 yield self.host.bridgeCall( |
1194
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1192
diff
changeset
|
108 "ticketSet", service.full(), node, posted_data, u"", ticket_id, |
bed008b65d7c
pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket:
Goffi <goffi@goffi.org>
parents:
1192
diff
changeset
|
109 data_format.serialise(extra), profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
110 ) |
1096
01538d8a77be
merge-requests, tickets: new "edit" pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 # we don't want to redirect to edit page on success, but to tickets list |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
112 data["post_redirect_page"] = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
113 self.getPageByName(u"tickets"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
114 service.full(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
115 node or u"@", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
116 ) |