comparison libervia/pages/events/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 acec8e9185db
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 twisted.internet import defer 6 from twisted.internet import defer
10 from sat.tools.common.template import safe 10 from sat.tools.common.template import safe
11 import time 11 import time
12 import cgi 12 import cgi
13 from sat.core.log import getLogger 13 from sat.core.log import getLogger
14 14
15 name = u"event_view" 15 name = "event_view"
16 access = C.PAGES_ACCESS_PROFILE 16 access = C.PAGES_ACCESS_PROFILE
17 template = u"event/invitation.html" 17 template = "event/invitation.html"
18 log = getLogger(__name__) 18 log = getLogger(__name__)
19 19
20 20
21 @defer.inlineCallbacks 21 @defer.inlineCallbacks
22 def prepare_render(self, request): 22 def prepare_render(self, request):
23 template_data = request.template_data 23 template_data = request.template_data
24 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession) 24 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
25 try: 25 try:
26 event_uri = guest_session.data["event_uri"] 26 event_uri = guest_session.data["event_uri"]
27 except KeyError: 27 except KeyError:
28 log.warning(_(u"event URI not found, can't render event page")) 28 log.warning(_("event URI not found, can't render event page"))
29 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE) 29 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
30 30
31 data = self.getRData(request) 31 data = self.getRData(request)
32 32
33 ## Event ## 33 ## Event ##
34 34
35 event_uri_data = uri.parseXMPPUri(event_uri) 35 event_uri_data = uri.parseXMPPUri(event_uri)
36 if event_uri_data[u"type"] != u"pubsub": 36 if event_uri_data["type"] != "pubsub":
37 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE) 37 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
38 38
39 event_service = template_data[u"event_service"] = jid.JID(event_uri_data[u"path"]) 39 event_service = template_data["event_service"] = jid.JID(event_uri_data["path"])
40 event_node = template_data[u"event_node"] = event_uri_data[u"node"] 40 event_node = template_data["event_node"] = event_uri_data["node"]
41 event_id = template_data[u"event_id"] = event_uri_data.get(u"item", "") 41 event_id = template_data["event_id"] = event_uri_data.get("item", "")
42 profile = self.getProfile(request) 42 profile = self.getProfile(request)
43 event_timestamp, event_data = yield self.host.bridgeCall( 43 event_timestamp, event_data = yield self.host.bridgeCall(
44 u"eventGet", event_service.userhost(), event_node, event_id, profile 44 "eventGet", event_service.userhost(), event_node, event_id, profile
45 ) 45 )
46 try: 46 try:
47 background_image = event_data.pop("background-image") 47 background_image = event_data.pop("background-image")
48 except KeyError: 48 except KeyError:
49 pass 49 pass
50 else: 50 else:
51 template_data["dynamic_style"] = safe( 51 template_data["dynamic_style"] = safe(
52 u""" 52 """
53 html { 53 html {
54 background-image: url("%s"); 54 background-image: url("%s");
55 background-size: 15em; 55 background-size: 15em;
56 } 56 }
57 """ 57 """
58 % cgi.escape(background_image, True) 58 % cgi.escape(background_image, True)
59 ) 59 )
60 template_data["event"] = event_data 60 template_data["event"] = event_data
61 event_invitee_data = yield self.host.bridgeCall( 61 event_invitee_data = yield self.host.bridgeCall(
62 u"eventInviteeGet", 62 "eventInviteeGet",
63 event_data["invitees_service"], 63 event_data["invitees_service"],
64 event_data["invitees_node"], 64 event_data["invitees_node"],
65 profile, 65 profile,
66 ) 66 )
67 template_data["invitee"] = event_invitee_data 67 template_data["invitee"] = event_invitee_data
68 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24)) 68 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))
69 69
70 ## Blog ## 70 ## Blog ##
71 71
72 data[u"service"] = jid.JID(event_data[u"blog_service"]) 72 data["service"] = jid.JID(event_data["blog_service"])
73 data[u"node"] = event_data[u"blog_node"] 73 data["node"] = event_data["blog_node"]
74 data[u"allow_commenting"] = u"simple" 74 data["allow_commenting"] = "simple"
75 75
76 # we now need blog items, using blog common page 76 # we now need blog items, using blog common page
77 # this will fill the "items" template data 77 # this will fill the "items" template data
78 blog_page = self.getPageByName(u"blog_view") 78 blog_page = self.getPageByName("blog_view")
79 yield blog_page.prepare_render(self, request) 79 yield blog_page.prepare_render(self, request)
80 80
81 81
82 @defer.inlineCallbacks 82 @defer.inlineCallbacks
83 def on_data_post(self, request): 83 def on_data_post(self, request):
84 type_ = self.getPostedData(request, u"type") 84 type_ = self.getPostedData(request, "type")
85 if type_ == u"comment": 85 if type_ == "comment":
86 blog_page = self.getPageByName(u"blog_view") 86 blog_page = self.getPageByName("blog_view")
87 yield blog_page.on_data_post(self, request) 87 yield blog_page.on_data_post(self, request)
88 elif type_ == u"attendance": 88 elif type_ == "attendance":
89 profile = self.getProfile(request) 89 profile = self.getProfile(request)
90 service, node, attend, guests = self.getPostedData( 90 service, node, attend, guests = self.getPostedData(
91 request, (u"service", u"node", u"attend", u"guests") 91 request, ("service", "node", "attend", "guests")
92 ) 92 )
93 data = {u"attend": attend, u"guests": guests} 93 data = {"attend": attend, "guests": guests}
94 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile) 94 yield self.host.bridgeCall("eventInviteeSet", service, node, data, profile)
95 else: 95 else:
96 log.warning(_(u"Unhandled data type: {}").format(type_)) 96 log.warning(_("Unhandled data type: {}").format(type_))