comparison src/pages/events/view/page_meta.py @ 1111:4d1c4bd4931a

pages (events): added root, admin, new, rsvp and view pages
author Goffi <goffi@goffi.org>
date Thu, 21 Jun 2018 01:19:57 +0200
parents
children cdd389ef97bc
comparison
equal deleted inserted replaced
1110:045e8bdaed4f 1111:4d1c4bd4931a
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid
8 from libervia.server import session_iface
9 from sat.tools.common import uri
10 from sat.tools.common.template import safe
11 import time
12 import cgi
13 from sat.core.log import getLogger
14
15 name = u'event_view'
16 access = C.PAGES_ACCESS_PROFILE
17 template = u"event/invitation.html"
18 log = getLogger(u'pages/' + name)
19
20
21 @defer.inlineCallbacks
22 def prepare_render(self, request):
23 template_data = request.template_data
24 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
25 try:
26 event_uri = guest_session.data['event_uri']
27 except KeyError:
28 log.warning(_(u"event URI not found, can't render event page"))
29 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
30
31 data = self.getRData(request)
32
33 ## Event ##
34
35 event_uri_data = uri.parseXMPPUri(event_uri)
36 if event_uri_data[u'type'] != u'pubsub':
37 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
38
39 event_service = template_data[u'event_service'] = jid.JID(event_uri_data[u'path'])
40 event_node = template_data[u'event_node'] = event_uri_data[u'node']
41 event_id = template_data[u'event_id'] = event_uri_data.get(u'item','')
42 profile = self.getProfile(request)
43 event_timestamp, event_data = yield self.host.bridgeCall(u"eventGet", event_service.userhost(), event_node, event_id, profile)
44 try:
45 background_image = event_data.pop('background-image')
46 except KeyError:
47 pass
48 else:
49 template_data['dynamic_style'] = safe(u"""
50 html {
51 background-image: url("%s");
52 background-size: 15em;
53 }
54 """ % cgi.escape(background_image, True))
55 template_data['event'] = event_data
56 event_invitee_data = yield self.host.bridgeCall(
57 u"eventInviteeGet",
58 event_data['invitees_service'],
59 event_data['invitees_node'],
60 profile)
61 template_data['invitee'] = event_invitee_data
62 template_data['days_left'] = int((event_timestamp - time.time()) / (60 * 60 * 24))
63
64 ## Blog ##
65
66 data[u'service'] = jid.JID(event_data[u'blog_service'])
67 data[u'node'] = event_data[u'blog_node']
68 data[u'allow_commenting'] = u'simple'
69
70 # we now need blog items, using blog common page
71 # this will fill the "items" template data
72 blog_page = self.getPageByName(u'blog_view')
73 yield blog_page.prepare_render(self, request)
74
75 @defer.inlineCallbacks
76 def on_data_post(self, request):
77 type_ = self.getPostedData(request, u'type')
78 if type_ == u'comment':
79 blog_page = self.getPageByName(u'blog_view')
80 yield blog_page.on_data_post(self, request)
81 elif type_ == u'attendance':
82 profile = self.getProfile(request)
83 service, node, attend, guests = self.getPostedData(request, (u'service', u'node', u'attend', u'guests'))
84 data = {u'attend': attend,
85 u'guests': guests}
86 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile)
87 else:
88 log.warning(_(u"Unhandled data type: {}").format(type_))