Mercurial > libervia-web
comparison libervia/pages/g/e/page_meta.py @ 1174:e0b3f1d78f8c
pages (g/e): use redirect instead of duplicating code of "event_view"
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 03 May 2019 20:52:13 +0200 |
parents | 29eb15062416 |
children | b2d067339de3 |
comparison
equal
deleted
inserted
replaced
1173:0f37b65fe7c2 | 1174:e0b3f1d78f8c |
---|---|
1 #!/usr/bin/env python2.7 | 1 #!/usr/bin/env python2.7 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 from libervia.server.constants import Const as C | 4 redirect = u"event_view" |
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 log = getLogger(__name__) | |
16 | |
17 access = C.PAGES_ACCESS_PROFILE | |
18 template = u"event/invitation.html" | |
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_)) |