comparison libervia/pages/events/view/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/events/view/page_meta.py@cdd389ef97bc
children 29eb15062416
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
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(
44 u"eventGet", event_service.userhost(), event_node, event_id, profile
45 )
46 try:
47 background_image = event_data.pop("background-image")
48 except KeyError:
49 pass
50 else:
51 template_data["dynamic_style"] = safe(
52 u"""
53 html {
54 background-image: url("%s");
55 background-size: 15em;
56 }
57 """
58 % cgi.escape(background_image, True)
59 )
60 template_data["event"] = event_data
61 event_invitee_data = yield self.host.bridgeCall(
62 u"eventInviteeGet",
63 event_data["invitees_service"],
64 event_data["invitees_node"],
65 profile,
66 )
67 template_data["invitee"] = event_invitee_data
68 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))
69
70 ## Blog ##
71
72 data[u"service"] = jid.JID(event_data[u"blog_service"])
73 data[u"node"] = event_data[u"blog_node"]
74 data[u"allow_commenting"] = u"simple"
75
76 # we now need blog items, using blog common page
77 # this will fill the "items" template data
78 blog_page = self.getPageByName(u"blog_view")
79 yield blog_page.prepare_render(self, request)
80
81
82 @defer.inlineCallbacks
83 def on_data_post(self, request):
84 type_ = self.getPostedData(request, u"type")
85 if type_ == u"comment":
86 blog_page = self.getPageByName(u"blog_view")
87 yield blog_page.on_data_post(self, request)
88 elif type_ == u"attendance":
89 profile = self.getProfile(request)
90 service, node, attend, guests = self.getPostedData(
91 request, (u"service", u"node", u"attend", u"guests")
92 )
93 data = {u"attend": attend, u"guests": guests}
94 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile)
95 else:
96 log.warning(_(u"Unhandled data type: {}").format(type_))