Mercurial > libervia-web
comparison src/pages/tickets/view/page_meta.py @ 1113:cdd389ef97bc
server: code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 29 Jun 2018 17:45:26 +0200 |
parents | 01e95ec9df9e |
children |
comparison
equal
deleted
inserted
replaced
1112:f287fc8bb31a | 1113:cdd389ef97bc |
---|---|
9 from twisted.words.protocols.jabber import jid | 9 from twisted.words.protocols.jabber import jid |
10 from sat.tools.common import template_xmlui | 10 from sat.tools.common import template_xmlui |
11 from sat.tools.common import uri | 11 from sat.tools.common import uri |
12 from sat.tools.common import data_objects | 12 from sat.tools.common import data_objects |
13 from sat.core.log import getLogger | 13 from sat.core.log import getLogger |
14 log = getLogger('pages/tickets/view') | 14 |
15 log = getLogger("pages/tickets/view") | |
15 """ticket handling pages""" | 16 """ticket handling pages""" |
16 | 17 |
17 name = u"tickets_view" | 18 name = u"tickets_view" |
18 access = C.PAGES_ACCESS_PUBLIC | 19 access = C.PAGES_ACCESS_PUBLIC |
19 template = u"ticket/item.html" | 20 template = u"ticket/item.html" |
25 except IndexError: | 26 except IndexError: |
26 log.warning(_(u"no ticket id specified")) | 27 log.warning(_(u"no ticket id specified")) |
27 self.pageError(request, C.HTTP_BAD_REQUEST) | 28 self.pageError(request, C.HTTP_BAD_REQUEST) |
28 | 29 |
29 data = self.getRData(request) | 30 data = self.getRData(request) |
30 data[u'ticket_id'] = item_id | 31 data[u"ticket_id"] = item_id |
32 | |
31 | 33 |
32 @defer.inlineCallbacks | 34 @defer.inlineCallbacks |
33 def prepare_render(self, request): | 35 def prepare_render(self, request): |
34 data = self.getRData(request) | 36 data = self.getRData(request) |
35 template_data = request.template_data | 37 template_data = request.template_data |
36 session = self.host.getSessionData(request, session_iface.ISATSession) | 38 session = self.host.getSessionData(request, session_iface.ISATSession) |
37 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id'] | 39 service, node, ticket_id = ( |
40 data.get(u"service", u""), | |
41 data.get(u"node", u""), | |
42 data[u"ticket_id"], | |
43 ) | |
38 profile = self.getProfile(request) | 44 profile = self.getProfile(request) |
39 | 45 |
40 if profile is None: | 46 if profile is None: |
41 profile = C.SERVICE_PROFILE | 47 profile = C.SERVICE_PROFILE |
42 | 48 |
43 tickets = yield self.host.bridgeCall("ticketsGet", service.full() if service else u'', node, C.NO_LIMIT, [ticket_id], '', {'labels_as_list': C.BOOL_TRUE}, profile) | 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 {"labels_as_list": C.BOOL_TRUE}, | |
57 profile, | |
58 ) | |
44 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0] | 59 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0] |
45 template_data[u'item'] = ticket | 60 template_data[u"item"] = ticket |
46 comments_uri = ticket.widgets['comments_uri'].value | 61 comments_uri = ticket.widgets["comments_uri"].value |
47 if comments_uri: | 62 if comments_uri: |
48 uri_data = uri.parseXMPPUri(comments_uri) | 63 uri_data = uri.parseXMPPUri(comments_uri) |
49 template_data['comments_node'] = comments_node = uri_data['node'] | 64 template_data["comments_node"] = comments_node = uri_data["node"] |
50 template_data['comments_service'] = comments_service = uri_data['path'] | 65 template_data["comments_service"] = comments_service = uri_data["path"] |
51 comments = yield self.host.bridgeCall("mbGet", comments_service, | 66 comments = yield self.host.bridgeCall( |
52 comments_node, | 67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile |
53 C.NO_LIMIT, | 68 ) |
54 [], | |
55 {}, | |
56 profile) | |
57 | 69 |
58 template_data[u'comments'] = data_objects.BlogItems(comments) | 70 template_data[u"comments"] = data_objects.BlogItems(comments) |
59 template_data[u'login_url'] = self.getPageRedirectURL(request) | 71 template_data[u"login_url"] = self.getPageRedirectURL(request) |
60 | 72 |
61 if session.connected: | 73 if session.connected: |
62 # we set edition URL only if user is the publisher or the node owner | 74 # we set edition URL only if user is the publisher or the node owner |
63 publisher = jid.JID(ticket.widgets['publisher'].value) | 75 publisher = jid.JID(ticket.widgets["publisher"].value) |
64 is_publisher = publisher.userhostJID() == session.jid.userhostJID() | 76 is_publisher = publisher.userhostJID() == session.jid.userhostJID() |
65 affiliation = None | 77 affiliation = None |
66 if not is_publisher: | 78 if not is_publisher: |
67 node = node or self.host.ns_map['tickets'] | 79 node = node or self.host.ns_map["tickets"] |
68 affiliation = yield self.host.getAffiliation(request, service, node) | 80 affiliation = yield self.host.getAffiliation(request, service, node) |
69 if is_publisher or affiliation == 'owner': | 81 if is_publisher or affiliation == "owner": |
70 template_data[u'url_ticket_edit'] = self.getURLByPath(SubPage('tickets'), service.full(), node or u'@', SubPage('tickets_edit'), ticket_id) | 82 template_data[u"url_ticket_edit"] = self.getURLByPath( |
83 SubPage("tickets"), | |
84 service.full(), | |
85 node or u"@", | |
86 SubPage("tickets_edit"), | |
87 ticket_id, | |
88 ) | |
89 | |
71 | 90 |
72 @defer.inlineCallbacks | 91 @defer.inlineCallbacks |
73 def on_data_post(self, request): | 92 def on_data_post(self, request): |
74 type_ = self.getPostedData(request, u'type') | 93 type_ = self.getPostedData(request, u"type") |
75 if type_ == u'comment': | 94 if type_ == u"comment": |
76 blog_page = self.getPageByName(u'blog_view') | 95 blog_page = self.getPageByName(u"blog_view") |
77 yield blog_page.on_data_post(self, request) | 96 yield blog_page.on_data_post(self, request) |
78 else: | 97 else: |
79 log.warning(_(u"Unhandled data type: {}").format(type_)) | 98 log.warning(_(u"Unhandled data type: {}").format(type_)) |