comparison libervia/web/pages/events/rsvp/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/events/rsvp/page_meta.py@106bae41f5c8
children 4ecae80d6d39
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.web.server.constants import Const as C
5 from libervia.backend.core.i18n import _, D_
6 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid
8 from libervia.backend.core.log import getLogger
9 from libervia.backend.tools.common.template import safe
10 import time
11 import html
12
13 """creation of new events"""
14
15 name = "event_rsvp"
16 label = D_("Event Invitation")
17 access = C.PAGES_ACCESS_PROFILE
18 template = "event/invitation.html"
19 log = getLogger(__name__)
20
21
22 def parse_url(self, request):
23 self.get_path_args(
24 request,
25 ("event_service", "event_node", "event_id"),
26 min_args=2,
27 event_service="@jid",
28 event_id="",
29 )
30
31
32 @defer.inlineCallbacks
33 def prepare_render(self, request):
34 template_data = request.template_data
35 data = self.get_r_data(request)
36 profile = self.get_profile(request)
37
38 ## Event ##
39
40 event_service = data["event_service"]
41 event_node = data["event_node"]
42 event_id = data["event_id"]
43 event_timestamp, event_data = yield self.host.bridge_call(
44 "eventGet",
45 event_service.userhost() if event_service else "",
46 event_node,
47 event_id,
48 profile,
49 )
50 try:
51 background_image = event_data.pop("background-image")
52 except KeyError:
53 pass
54 else:
55 template_data["dynamic_style"] = safe(
56 """
57 html {
58 background-image: url("%s");
59 background-size: 15em;
60 }
61 """
62 % html.escape(background_image, True)
63 )
64 template_data["event"] = event_data
65 event_invitee_data = yield self.host.bridge_call(
66 "event_invitee_get",
67 event_data["invitees_service"],
68 event_data["invitees_node"],
69 '',
70 profile,
71 )
72 template_data["invitee"] = event_invitee_data
73 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))
74
75 ## Blog ##
76
77 data["service"] = jid.JID(event_data["blog_service"])
78 data["node"] = event_data["blog_node"]
79 data["allow_commenting"] = "simple"
80
81 # we now need blog items, using blog common page
82 # this will fill the "items" template data
83 blog_page = self.get_page_by_name("blog_view")
84 yield blog_page.prepare_render(self, request)
85
86
87 @defer.inlineCallbacks
88 def on_data_post(self, request):
89 type_ = self.get_posted_data(request, "type")
90 if type_ == "comment":
91 blog_page = self.get_page_by_name("blog_view")
92 yield blog_page.on_data_post(self, request)
93 elif type_ == "attendance":
94 profile = self.get_profile(request)
95 service, node, attend, guests = self.get_posted_data(
96 request, ("service", "node", "attend", "guests")
97 )
98 data = {"attend": attend, "guests": guests}
99 yield self.host.bridge_call("event_invitee_set", service, node, data, profile)
100 else:
101 log.warning(_("Unhandled data type: {}").format(type_))