Mercurial > libervia-web
annotate src/pages/g/e/page_meta.py @ 1061:bacb8f229742
pages: fixed unicode escaping when using a redirecting URL
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 11 Mar 2018 19:28:10 +0100 |
parents | ad97d7e7de3b |
children | 1c09f41e2f52 |
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 |
1028
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
10 from sat.tools.common.template import safe |
946
d076b722ca52
pages (g/e): added days left before the event as a template variable
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
11 import time |
1028
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
12 import cgi |
940
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 from sat.core.log import getLogger |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 log = getLogger('pages/g/e') |
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 access = C.PAGES_ACCESS_PROFILE |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 template = u"event/invitation.html" |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 @defer.inlineCallbacks |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 def prepare_render(self, request): |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 template_data = request.template_data |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 try: |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 event_uri = guest_session.data['event_uri'] |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 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
|
27 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
|
28 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE) |
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 data = self.getRData(request) |
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 ## |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 event_uri_data = uri.parseXMPPUri(event_uri) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 if event_uri_data[u'type'] != u'pubsub': |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 profile = self.getProfile(request) |
942
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
42 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
|
43 try: |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
44 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
|
45 except KeyError: |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
46 pass |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
47 else: |
1028
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
48 template_data['dynamic_style'] = safe(u""" |
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
49 html { |
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
50 background-image: url("%s"); |
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
51 background-size: 15em; |
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
52 } |
ad97d7e7de3b
pages (g/e): replaced background_image by new dynamic_style template variable
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
53 """ % cgi.escape(background_image, True)) |
940
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 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
|
55 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
|
56 u"eventInviteeGet", |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
57 event_data['invitees_service'], |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
58 event_data['invitees_node'], |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
59 profile) |
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
60 template_data['invitee'] = event_invitee_data |
946
d076b722ca52
pages (g/e): added days left before the event as a template variable
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
61 template_data['days_left'] = int((event_timestamp - time.time()) / (60 * 60 * 24)) |
940
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 ## Blog ## |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
943
aacda981c348
pages (g/e): use blog_uri from event instead of guest's main uri
Goffi <goffi@goffi.org>
parents:
942
diff
changeset
|
65 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
|
66 data[u'node'] = event_data[u'blog_node'] |
949
36e9747520fd
pages (common/blog): use request data to indicate if comments are allowed
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
67 data[u'allow_commenting'] = u'simple' |
940
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 # we now need blog items, using blog common page |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 # this will fill the "items" template data |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 blog_page = self.getPageByName(u'blog') |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 yield blog_page.prepare_render(self, request) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 @defer.inlineCallbacks |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 def on_data_post(self, request): |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 type_ = self.getPostedData(request, u'type') |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 if type_ == u'comment': |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 blog_page = self.getPageByName(u'blog') |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 yield blog_page.on_data_post(self, request) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 elif type_ == u'attendance': |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 profile = self.getProfile(request) |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 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
|
83 data = {u'attend': attend, |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 u'guests': guests} |
942
6b55d038b121
pages (g/e): adapted event handling to changes in backend
Goffi <goffi@goffi.org>
parents:
940
diff
changeset
|
85 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
|
86 else: |
e30a4b7eff09
page (g/e): events invitations first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 log.warning(_(u"Unhandled data type: {}").format(type_)) |