comparison libervia/pages/tickets/edit/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/tickets/edit/page_meta.py@cdd389ef97bc
children 7bd47d32da87
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from sat.tools.common import template_xmlui
8 from sat.core.log import getLogger
9
10 log = getLogger("pages/ticket")
11 """ticket handling pages"""
12
13 name = u"tickets_edit"
14 access = C.PAGES_ACCESS_PROFILE
15 template = u"ticket/edit.html"
16
17
18 def parse_url(self, request):
19 try:
20 item_id = self.nextPath(request)
21 except IndexError:
22 log.warning(_(u"no ticket id specified"))
23 self.pageError(request, C.HTTP_BAD_REQUEST)
24
25 data = self.getRData(request)
26 data[u"ticket_id"] = item_id
27
28
29 @defer.inlineCallbacks
30 def prepare_render(self, request):
31 data = self.getRData(request)
32 template_data = request.template_data
33 service, node, ticket_id = (
34 data.get(u"service", u""),
35 data.get(u"node", u""),
36 data[u"ticket_id"],
37 )
38 profile = self.getProfile(request)
39
40 ignore = (
41 "publisher",
42 "author",
43 "author_jid",
44 "author_email",
45 "created",
46 "updated",
47 "comments_uri",
48 )
49 tickets = yield self.host.bridgeCall(
50 "ticketsGet",
51 service.full() if service else u"",
52 node,
53 C.NO_LIMIT,
54 [ticket_id],
55 "",
56 {},
57 profile,
58 )
59 ticket = [template_xmlui.create(self.host, x, ignore=ignore) for x in tickets[0]][0]
60
61 try:
62 # small trick to get a one line text input instead of the big textarea
63 ticket.widgets[u"labels"].type = u"string"
64 ticket.widgets[u"labels"].value = ticket.widgets[u"labels"].value.replace(
65 u"\n", ", "
66 )
67 except KeyError:
68 pass
69 template_data[u"new_ticket_xmlui"] = ticket
70
71
72 @defer.inlineCallbacks
73 def on_data_post(self, request):
74 data = self.getRData(request)
75 service = data["service"]
76 node = data["node"]
77 ticket_id = data["ticket_id"]
78 posted_data = self.getAllPostedData(request)
79 if not posted_data["title"] or not posted_data["body"]:
80 self.pageError(request, C.HTTP_BAD_REQUEST)
81 try:
82 posted_data["labels"] = [l.strip() for l in posted_data["labels"][0].split(",")]
83 except (KeyError, IndexError):
84 pass
85 profile = self.getProfile(request)
86 yield self.host.bridgeCall(
87 "ticketSet", service.full(), node, posted_data, u"", ticket_id, {}, profile
88 )
89 # we don't want to redirect to edit page on success, but to tickets list
90 data["post_redirect_page"] = (
91 self.getPageByName(u"tickets"),
92 service.full(),
93 node or u"@",
94 )