Mercurial > libervia-web
annotate libervia/pages/events/rsvp/page_meta.py @ 1145:29eb15062416
pages: set __name__ for imported pages
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Jan 2019 08:41:43 +0100 |
parents | 28e3eb3bb217 |
children | b2d067339de3 |
rev | line source |
---|---|
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from libervia.server.constants import Const as C |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from sat.core.i18n import _ |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from twisted.internet import defer |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from twisted.words.protocols.jabber import jid |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 from sat.core.log import getLogger |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from sat.tools.common.template import safe |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 import time |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 import cgi |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
12 |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 """creation of new events""" |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
15 name = u"event_rsvp" |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 access = C.PAGES_ACCESS_PROFILE |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 template = u"event/invitation.html" |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
18 log = getLogger(__name__) |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 def parse_url(self, request): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
22 self.getPathArgs( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
23 request, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
24 ("event_service", "event_node", "event_id"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
25 min_args=2, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
26 event_service="@jid", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
27 event_id="", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
28 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
29 |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 @defer.inlineCallbacks |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 def prepare_render(self, request): |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 template_data = request.template_data |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 data = self.getRData(request) |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 profile = self.getProfile(request) |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 ## Event ## |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
39 event_service = data["event_service"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
40 event_node = data[u"event_node"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
41 event_id = data[u"event_id"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
42 event_timestamp, event_data = yield self.host.bridgeCall( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
43 u"eventGet", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
44 event_service.userhost() if event_service else "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
45 event_node, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
46 event_id, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
47 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
48 ) |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
50 background_image = event_data.pop("background-image") |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 except KeyError: |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 pass |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 else: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
54 template_data["dynamic_style"] = safe( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
55 u""" |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 html { |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 background-image: url("%s"); |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 background-size: 15em; |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 } |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
60 """ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
61 % cgi.escape(background_image, True) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
62 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
63 template_data["event"] = event_data |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 event_invitee_data = yield self.host.bridgeCall( |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 u"eventInviteeGet", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
66 event_data["invitees_service"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
67 event_data["invitees_node"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
68 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
69 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
70 template_data["invitee"] = event_invitee_data |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
71 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24)) |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 ## Blog ## |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
75 data[u"service"] = jid.JID(event_data[u"blog_service"]) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
76 data[u"node"] = event_data[u"blog_node"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
77 data[u"allow_commenting"] = u"simple" |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 # we now need blog items, using blog common page |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 # this will fill the "items" template data |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
81 blog_page = self.getPageByName(u"blog_view") |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 yield blog_page.prepare_render(self, request) |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
84 |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 @defer.inlineCallbacks |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def on_data_post(self, request): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
87 type_ = self.getPostedData(request, u"type") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
88 if type_ == u"comment": |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
89 blog_page = self.getPageByName(u"blog_view") |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 yield blog_page.on_data_post(self, request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
91 elif type_ == u"attendance": |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 profile = self.getProfile(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
93 service, node, attend, guests = self.getPostedData( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
94 request, (u"service", u"node", u"attend", u"guests") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
95 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1111
diff
changeset
|
96 data = {u"attend": attend, u"guests": guests} |
1111
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 yield self.host.bridgeCall(u"eventInviteeSet", service, node, data, profile) |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 else: |
4d1c4bd4931a
pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 log.warning(_(u"Unhandled data type: {}").format(type_)) |