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