comparison libervia/pages/events/rsvp/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 import time 10 import time
11 import cgi 11 import cgi
12 12
13 """creation of new events""" 13 """creation of new events"""
14 14
15 name = u"event_rsvp" 15 name = "event_rsvp"
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 def parse_url(self, request): 21 def parse_url(self, request):
22 self.getPathArgs( 22 self.getPathArgs(
35 profile = self.getProfile(request) 35 profile = self.getProfile(request)
36 36
37 ## Event ## 37 ## Event ##
38 38
39 event_service = data["event_service"] 39 event_service = data["event_service"]
40 event_node = data[u"event_node"] 40 event_node = data["event_node"]
41 event_id = data[u"event_id"] 41 event_id = data["event_id"]
42 event_timestamp, event_data = yield self.host.bridgeCall( 42 event_timestamp, event_data = yield self.host.bridgeCall(
43 u"eventGet", 43 "eventGet",
44 event_service.userhost() if event_service else "", 44 event_service.userhost() if event_service else "",
45 event_node, 45 event_node,
46 event_id, 46 event_id,
47 profile, 47 profile,
48 ) 48 )
50 background_image = event_data.pop("background-image") 50 background_image = event_data.pop("background-image")
51 except KeyError: 51 except KeyError:
52 pass 52 pass
53 else: 53 else:
54 template_data["dynamic_style"] = safe( 54 template_data["dynamic_style"] = safe(
55 u""" 55 """
56 html { 56 html {
57 background-image: url("%s"); 57 background-image: url("%s");
58 background-size: 15em; 58 background-size: 15em;
59 } 59 }
60 """ 60 """
61 % cgi.escape(background_image, True) 61 % cgi.escape(background_image, True)
62 ) 62 )
63 template_data["event"] = event_data 63 template_data["event"] = event_data
64 event_invitee_data = yield self.host.bridgeCall( 64 event_invitee_data = yield self.host.bridgeCall(
65 u"eventInviteeGet", 65 "eventInviteeGet",
66 event_data["invitees_service"], 66 event_data["invitees_service"],
67 event_data["invitees_node"], 67 event_data["invitees_node"],
68 profile, 68 profile,
69 ) 69 )
70 template_data["invitee"] = event_invitee_data 70 template_data["invitee"] = event_invitee_data
71 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24)) 71 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))
72 72
73 ## Blog ## 73 ## Blog ##
74 74
75 data[u"service"] = jid.JID(event_data[u"blog_service"]) 75 data["service"] = jid.JID(event_data["blog_service"])
76 data[u"node"] = event_data[u"blog_node"] 76 data["node"] = event_data["blog_node"]
77 data[u"allow_commenting"] = u"simple" 77 data["allow_commenting"] = "simple"
78 78
79 # we now need blog items, using blog common page 79 # we now need blog items, using blog common page
80 # this will fill the "items" template data 80 # this will fill the "items" template data
81 blog_page = self.getPageByName(u"blog_view") 81 blog_page = self.getPageByName("blog_view")
82 yield blog_page.prepare_render(self, request) 82 yield blog_page.prepare_render(self, request)
83 83
84 84
85 @defer.inlineCallbacks 85 @defer.inlineCallbacks
86 def on_data_post(self, request): 86 def on_data_post(self, request):
87 type_ = self.getPostedData(request, u"type") 87 type_ = self.getPostedData(request, "type")
88 if type_ == u"comment": 88 if type_ == "comment":
89 blog_page = self.getPageByName(u"blog_view") 89 blog_page = self.getPageByName("blog_view")
90 yield blog_page.on_data_post(self, request) 90 yield blog_page.on_data_post(self, request)
91 elif type_ == u"attendance": 91 elif type_ == "attendance":
92 profile = self.getProfile(request) 92 profile = self.getProfile(request)
93 service, node, attend, guests = self.getPostedData( 93 service, node, attend, guests = self.getPostedData(
94 request, (u"service", u"node", u"attend", u"guests") 94 request, ("service", "node", "attend", "guests")
95 ) 95 )
96 data = {u"attend": attend, u"guests": guests} 96 data = {"attend": attend, "guests": guests}
97 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile) 97 yield self.host.bridgeCall("eventInviteeSet", service, node, data, profile)
98 else: 98 else:
99 log.warning(_(u"Unhandled data type: {}").format(type_)) 99 log.warning(_("Unhandled data type: {}").format(type_))