comparison libervia/web/pages/events/view/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/view/page_meta.py@106bae41f5c8
children
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 _
6 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid
8 from libervia.web.server import session_iface
9 from libervia.backend.tools.common import uri
10 from libervia.backend.tools.common.template import safe
11 import time
12 import html
13 from libervia.backend.core.log import getLogger
14
15 name = "event_view"
16 access = C.PAGES_ACCESS_PROFILE
17 template = "event/invitation.html"
18 log = getLogger(__name__)
19
20
21 @defer.inlineCallbacks
22 def prepare_render(self, request):
23 template_data = request.template_data
24 guest_session = self.host.get_session_data(request, session_iface.IWebGuestSession)
25 try:
26 event_uri = guest_session.data["event_uri"]
27 except KeyError:
28 log.warning(_("event URI not found, can't render event page"))
29 self.page_error(request, C.HTTP_SERVICE_UNAVAILABLE)
30
31 data = self.get_r_data(request)
32
33 ## Event ##
34
35 event_uri_data = uri.parse_xmpp_uri(event_uri)
36 if event_uri_data["type"] != "pubsub":
37 self.page_error(request, C.HTTP_SERVICE_UNAVAILABLE)
38
39 event_service = template_data["event_service"] = jid.JID(event_uri_data["path"])
40 event_node = template_data["event_node"] = event_uri_data["node"]
41 event_id = template_data["event_id"] = event_uri_data.get("item", "")
42 profile = self.get_profile(request)
43 event_timestamp, event_data = yield self.host.bridge_call(
44 "eventGet", event_service.userhost(), event_node, event_id, profile
45 )
46 try:
47 background_image = event_data.pop("background-image")
48 except KeyError:
49 pass
50 else:
51 template_data["dynamic_style"] = safe(
52 """
53 html {
54 background-image: url("%s");
55 background-size: 15em;
56 }
57 """
58 % html.escape(background_image, True)
59 )
60 template_data["event"] = event_data
61 event_invitee_data = yield self.host.bridge_call(
62 "event_invitee_get",
63 event_data["invitees_service"],
64 event_data["invitees_node"],
65 '',
66 profile,
67 )
68 template_data["invitee"] = event_invitee_data
69 template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))
70
71 ## Blog ##
72
73 data["service"] = jid.JID(event_data["blog_service"])
74 data["node"] = event_data["blog_node"]
75 data["allow_commenting"] = "simple"
76
77 # we now need blog items, using blog common page
78 # this will fill the "items" template data
79 blog_page = self.get_page_by_name("blog_view")
80 yield blog_page.prepare_render(self, request)
81
82
83 @defer.inlineCallbacks
84 def on_data_post(self, request):
85 type_ = self.get_posted_data(request, "type")
86 if type_ == "comment":
87 blog_page = self.get_page_by_name("blog_view")
88 yield blog_page.on_data_post(self, request)
89 elif type_ == "attendance":
90 profile = self.get_profile(request)
91 service, node, attend, guests = self.get_posted_data(
92 request, ("service", "node", "attend", "guests")
93 )
94 data = {"attend": attend, "guests": guests}
95 yield self.host.bridge_call("event_invitee_set", service, node, data, profile)
96 else:
97 log.warning(_("Unhandled data type: {}").format(type_))