comparison 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
comparison
equal deleted inserted replaced
939:1375b96f4309 940:e30a4b7eff09
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 libervia.server import session_iface
9 from sat.tools.common import uri
10 from sat.core.log import getLogger
11 log = getLogger('pages/g/e')
12
13 access = C.PAGES_ACCESS_PROFILE
14 template = u"event/invitation.html"
15
16
17 @defer.inlineCallbacks
18 def prepare_render(self, request):
19 template_data = request.template_data
20 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
21 try:
22 main_uri = guest_session.data['main_uri']
23 event_uri = guest_session.data['event_uri']
24 except KeyError:
25 log.warning(_(u"main or event URI not found, can't render event page"))
26 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
27
28 data = self.getRData(request)
29
30 ## Event ##
31
32 event_uri_data = uri.parseXMPPUri(event_uri)
33 if event_uri_data[u'type'] != u'pubsub':
34 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
35
36 event_service = template_data[u'event_service'] = jid.JID(event_uri_data[u'path'])
37 event_node = template_data[u'event_node'] = event_uri_data[u'node']
38 profile = self.getProfile(request)
39 event_data = yield self.host.bridgeCall(u"eventGet", event_service.userhost(), event_node, profile)
40 template_data['event'] = event_data
41
42 ## Blog ##
43
44 main_uri_data = uri.parseXMPPUri(main_uri)
45 if main_uri_data[u'type'] != u'pubsub' or main_uri_data.get('sub_type') != 'microblog':
46 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
47
48 data[u'service'] = jid.JID(main_uri_data[u'path'])
49 data[u'node'] = main_uri_data[u'node']
50
51 # we now need blog items, using blog common page
52 # this will fill the "items" template data
53 blog_page = self.getPageByName(u'blog')
54 yield blog_page.prepare_render(self, request)
55
56 @defer.inlineCallbacks
57 def on_data_post(self, request):
58 type_ = self.getPostedData(request, u'type')
59 if type_ == u'comment':
60 blog_page = self.getPageByName(u'blog')
61 yield blog_page.on_data_post(self, request)
62 elif type_ == u'attendance':
63 profile = self.getProfile(request)
64 service, node, attend, guests = self.getPostedData(request, (u'service', u'node', u'attend', u'guests'))
65 data = {u'attend': attend,
66 u'guests': guests}
67 yield self.host.bridgeCall(u"eventSet", service, node, data, profile)
68 else:
69 log.warning(_(u"Unhandled data type: {}").format(type_))