annotate src/pages/g/e/page_meta.py @ 943:aacda981c348

pages (g/e): use blog_uri from event instead of guest's main uri
author Goffi <goffi@goffi.org>
date Fri, 19 May 2017 13:54:49 +0200
parents 6b55d038b121
children d076b722ca52
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 event_uri = guest_session.data['event_uri']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 except KeyError:
943
aacda981c348 pages (g/e): use blog_uri from event instead of guest's main uri
Goffi <goffi@goffi.org>
parents: 942
diff changeset
24 log.warning(_(u"event URI not found, can't render event page"))
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 data = self.getRData(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 ## Event ##
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 event_uri_data = uri.parseXMPPUri(event_uri)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 if event_uri_data[u'type'] != u'pubsub':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 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
36 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
37 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
38 profile = self.getProfile(request)
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
39 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
40 try:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
41 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
42 except KeyError:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
43 pass
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
44 else:
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
45 template_data['background_image'] = background_image
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 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
47 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
48 u"eventInviteeGet",
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
49 event_data['invitees_service'],
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
50 event_data['invitees_node'],
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
51 profile)
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
52 template_data['invitee'] = event_invitee_data
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 ## Blog ##
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55
943
aacda981c348 pages (g/e): use blog_uri from event instead of guest's main uri
Goffi <goffi@goffi.org>
parents: 942
diff changeset
56 data[u'service'] = jid.JID(event_data[u'blog_service'])
aacda981c348 pages (g/e): use blog_uri from event instead of guest's main uri
Goffi <goffi@goffi.org>
parents: 942
diff changeset
57 data[u'node'] = event_data[u'blog_node']
940
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 # we now need blog items, using blog common page
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 # this will fill the "items" template data
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 yield blog_page.prepare_render(self, request)
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 @defer.inlineCallbacks
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def on_data_post(self, request):
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 type_ = self.getPostedData(request, u'type')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 if type_ == u'comment':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 yield blog_page.on_data_post(self, request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 elif type_ == u'attendance':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 profile = self.getProfile(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 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
73 data = {u'attend': attend,
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 u'guests': guests}
942
6b55d038b121 pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents: 940
diff changeset
75 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
76 else:
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 log.warning(_(u"Unhandled data type: {}").format(type_))