comparison libervia/pages/tickets/view/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 29eb15062416
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 libervia.server.utils import SubPage 6 from libervia.server.utils import SubPage
13 from sat.core.log import getLogger 13 from sat.core.log import getLogger
14 14
15 log = getLogger(__name__) 15 log = getLogger(__name__)
16 """ticket handling pages""" 16 """ticket handling pages"""
17 17
18 name = u"tickets_view" 18 name = "tickets_view"
19 access = C.PAGES_ACCESS_PUBLIC 19 access = C.PAGES_ACCESS_PUBLIC
20 template = u"ticket/item.html" 20 template = "ticket/item.html"
21 21
22 22
23 def parse_url(self, request): 23 def parse_url(self, request):
24 try: 24 try:
25 item_id = self.nextPath(request) 25 item_id = self.nextPath(request)
26 except IndexError: 26 except IndexError:
27 log.warning(_(u"no ticket id specified")) 27 log.warning(_("no ticket id specified"))
28 self.pageError(request, C.HTTP_BAD_REQUEST) 28 self.pageError(request, C.HTTP_BAD_REQUEST)
29 29
30 data = self.getRData(request) 30 data = self.getRData(request)
31 data[u"ticket_id"] = item_id 31 data["ticket_id"] = item_id
32 32
33 33
34 @defer.inlineCallbacks 34 @defer.inlineCallbacks
35 def prepare_render(self, request): 35 def prepare_render(self, request):
36 data = self.getRData(request) 36 data = self.getRData(request)
37 template_data = request.template_data 37 template_data = request.template_data
38 session = self.host.getSessionData(request, session_iface.ISATSession) 38 session = self.host.getSessionData(request, session_iface.ISATSession)
39 service, node, ticket_id = ( 39 service, node, ticket_id = (
40 data.get(u"service", u""), 40 data.get("service", ""),
41 data.get(u"node", u""), 41 data.get("node", ""),
42 data[u"ticket_id"], 42 data["ticket_id"],
43 ) 43 )
44 profile = self.getProfile(request) 44 profile = self.getProfile(request)
45 45
46 if profile is None: 46 if profile is None:
47 profile = C.SERVICE_PROFILE 47 profile = C.SERVICE_PROFILE
48 48
49 tickets = yield self.host.bridgeCall( 49 tickets = yield self.host.bridgeCall(
50 "ticketsGet", 50 "ticketsGet",
51 service.full() if service else u"", 51 service.full() if service else "",
52 node, 52 node,
53 C.NO_LIMIT, 53 C.NO_LIMIT,
54 [ticket_id], 54 [ticket_id],
55 "", 55 "",
56 {"labels_as_list": C.BOOL_TRUE}, 56 {"labels_as_list": C.BOOL_TRUE},
57 profile, 57 profile,
58 ) 58 )
59 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]
60 template_data[u"item"] = ticket 60 template_data["item"] = ticket
61 comments_uri = ticket.widgets["comments_uri"].value 61 comments_uri = ticket.widgets["comments_uri"].value
62 if comments_uri: 62 if comments_uri:
63 uri_data = uri.parseXMPPUri(comments_uri) 63 uri_data = uri.parseXMPPUri(comments_uri)
64 template_data["comments_node"] = comments_node = uri_data["node"] 64 template_data["comments_node"] = comments_node = uri_data["node"]
65 template_data["comments_service"] = comments_service = uri_data["path"] 65 template_data["comments_service"] = comments_service = uri_data["path"]
66 comments = yield self.host.bridgeCall( 66 comments = yield self.host.bridgeCall(
67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile 67 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile
68 ) 68 )
69 69
70 template_data[u"comments"] = data_objects.BlogItems(comments) 70 template_data["comments"] = data_objects.BlogItems(comments)
71 template_data[u"login_url"] = self.getPageRedirectURL(request) 71 template_data["login_url"] = self.getPageRedirectURL(request)
72 72
73 if session.connected: 73 if session.connected:
74 # 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
75 publisher = jid.JID(ticket.widgets["publisher"].value) 75 publisher = jid.JID(ticket.widgets["publisher"].value)
76 is_publisher = publisher.userhostJID() == session.jid.userhostJID() 76 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
77 affiliation = None 77 affiliation = None
78 if not is_publisher: 78 if not is_publisher:
79 node = node or self.host.ns_map["tickets"] 79 node = node or self.host.ns_map["tickets"]
80 affiliation = yield self.host.getAffiliation(request, service, node) 80 affiliation = yield self.host.getAffiliation(request, service, node)
81 if is_publisher or affiliation == "owner": 81 if is_publisher or affiliation == "owner":
82 template_data[u"url_ticket_edit"] = self.getURLByPath( 82 template_data["url_ticket_edit"] = self.getURLByPath(
83 SubPage("tickets"), 83 SubPage("tickets"),
84 service.full(), 84 service.full(),
85 node or u"@", 85 node or "@",
86 SubPage("tickets_edit"), 86 SubPage("tickets_edit"),
87 ticket_id, 87 ticket_id,
88 ) 88 )
89 89
90 90
91 @defer.inlineCallbacks 91 @defer.inlineCallbacks
92 def on_data_post(self, request): 92 def on_data_post(self, request):
93 type_ = self.getPostedData(request, u"type") 93 type_ = self.getPostedData(request, "type")
94 if type_ == u"comment": 94 if type_ == "comment":
95 blog_page = self.getPageByName(u"blog_view") 95 blog_page = self.getPageByName("blog_view")
96 yield blog_page.on_data_post(self, request) 96 yield blog_page.on_data_post(self, request)
97 else: 97 else:
98 log.warning(_(u"Unhandled data type: {}").format(type_)) 98 log.warning(_("Unhandled data type: {}").format(type_))