annotate src/pages/g/e/page_meta.py @ 942:6b55d038b121

pages (g/e): adapted event handling to changes in backend
author Goffi <goffi@goffi.org>
date Fri, 19 May 2017 12:57:53 +0200
parents e30a4b7eff09
children aacda981c348
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from twisted.words.protocols.jabber import jid
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from libervia.server import session_iface
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from sat.tools.common import uri
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from sat.core.log import getLogger
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 log = getLogger('pages/g/e')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = u"event/invitation.html"
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 @defer.inlineCallbacks
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 def prepare_render(self, request):
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 template_data = request.template_data
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 try:
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 main_uri = guest_session.data['main_uri']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 event_uri = guest_session.data['event_uri']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 except KeyError:
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 log.warning(_(u"main or event URI not found, can't render event page"))
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 data = self.getRData(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 ## Event ##
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 event_uri_data = uri.parseXMPPUri(event_uri)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 if event_uri_data[u'type'] != u'pubsub':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 event_service = template_data[u'event_service'] = jid.JID(event_uri_data[u'path'])
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 event_node = template_data[u'event_node'] = event_uri_data[u'node']
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
38 event_id = template_data[u'event_id'] = event_uri_data.get(u'item','')
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 profile = self.getProfile(request)
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
40 event_timestamp, event_data = yield self.host.bridgeCall(u"eventGet", event_service.userhost(), event_node, event_id, profile)
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
41 try:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
42 background_image = event_data.pop('background-image')
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
43 except KeyError:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
44 pass
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
45 else:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
46 template_data['background_image'] = background_image
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 template_data['event'] = event_data
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
48 event_invitee_data = yield self.host.bridgeCall(
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
49 u"eventInviteeGet",
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
50 event_data['invitees_service'],
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
51 event_data['invitees_node'],
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
52 profile)
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
53 template_data['invitee'] = event_invitee_data
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 ## Blog ##
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 main_uri_data = uri.parseXMPPUri(main_uri)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 if main_uri_data[u'type'] != u'pubsub' or main_uri_data.get('sub_type') != 'microblog':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 data[u'service'] = jid.JID(main_uri_data[u'path'])
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 data[u'node'] = main_uri_data[u'node']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # we now need blog items, using blog common page
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 # this will fill the "items" template data
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 yield blog_page.prepare_render(self, request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 @defer.inlineCallbacks
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def on_data_post(self, request):
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 type_ = self.getPostedData(request, u'type')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 if type_ == u'comment':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 yield blog_page.on_data_post(self, request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 elif type_ == u'attendance':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 profile = self.getProfile(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 service, node, attend, guests = self.getPostedData(request, (u'service', u'node', u'attend', u'guests'))
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 data = {u'attend': attend,
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 u'guests': guests}
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
80 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile)
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 else:
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 log.warning(_(u"Unhandled data type: {}").format(type_))