annotate src/pages/g/e/page_meta.py @ 940:e30a4b7eff09

page (g/e): events invitations first draft
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:17:46 +0200
parents
children 6b55d038b121
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']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 profile = self.getProfile(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 event_data = yield self.host.bridgeCall(u"eventGet", event_service.userhost(), event_node, profile)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 template_data['event'] = event_data
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 ## Blog ##
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 main_uri_data = uri.parseXMPPUri(main_uri)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 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
46 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 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
49 data[u'node'] = main_uri_data[u'node']
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 # we now need blog items, using blog common page
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 # this will fill the "items" template data
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 yield blog_page.prepare_render(self, request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 @defer.inlineCallbacks
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def on_data_post(self, request):
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 type_ = self.getPostedData(request, u'type')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 if type_ == u'comment':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 blog_page = self.getPageByName(u'blog')
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 yield blog_page.on_data_post(self, request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 elif type_ == u'attendance':
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 profile = self.getProfile(request)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 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
65 data = {u'attend': attend,
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 u'guests': guests}
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 yield self.host.bridgeCall(u"eventSet", service, node, data, profile)
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 else:
e30a4b7eff09 page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 log.warning(_(u"Unhandled data type: {}").format(type_))