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