view libervia/web/pages/events/rsvp/page_meta.py @ 1602:6feac4a25e60

browser: Remote Control implementation: - Add `cbor-x` JS dependency. - In "Call" page, a Remote Control session can now be started. This is done by clicking on a search item 3 dots menu. Libervia Web will act as a controlling device. The call box is then adapted, and mouse/wheel and keyboard events are sent to remote, touch events are converted to mouse one. - Some Brython 3.12* related changes. rel 436
author Goffi <goffi@goffi.org>
date Sat, 11 May 2024 14:02:22 +0200
parents 4ecae80d6d39
children
line wrap: on
line source

#!/usr/bin/env python3


from libervia.web.server.constants import Const as C
from libervia.backend.core.i18n import _, D_
from twisted.internet import defer
from twisted.words.protocols.jabber import jid
from libervia.backend.core.log import getLogger
from libervia.backend.tools.common.template import safe
import time
import html

"""creation of new events"""

name = "event_rsvp"
label = D_("Event Invitation")
access = C.PAGES_ACCESS_PROFILE
template = "event/invitation.html"
log = getLogger(__name__)


def parse_url(self, request):
    self.get_path_args(
        request,
        ("event_service", "event_node", "event_id"),
        min_args=2,
        event_service="@jid",
        event_id="",
    )


async def prepare_render(self, request):
    template_data = request.template_data
    data = self.get_r_data(request)
    profile = self.get_profile(request)

    ## Event ##

    event_service = data["event_service"]
    event_node = data["event_node"]
    event_id = data["event_id"]
    event_timestamp, event_data = await self.host.bridge_call(
        "events_get",
        event_service.userhost() if event_service else "",
        event_node,
        [event_id],
        "",
        profile,
    )
    try:
        background_image = event_data.pop("background-image")
    except KeyError:
        pass
    else:
        template_data["dynamic_style"] = safe(
            """
            html {
                background-image: url("%s");
                background-size: 15em;
            }
            """
            % html.escape(background_image, True)
        )
    template_data["event"] = event_data
    event_invitee_data = await self.host.bridge_call(
        "event_invitee_get",
        event_data["invitees_service"],
        event_data["invitees_node"],
        [],
        "",
        profile,
    )
    template_data["invitee"] = event_invitee_data
    template_data["days_left"] = int((event_timestamp - time.time()) / (60 * 60 * 24))

    ## Blog ##

    data["service"] = jid.JID(event_data["blog_service"])
    data["node"] = event_data["blog_node"]
    data["allow_commenting"] = "simple"

    # we now need blog items, using blog common page
    # this will fill the "items" template data
    blog_page = self.get_page_by_name("blog_view")
    await blog_page.prepare_render(self, request)


async def on_data_post(self, request):
    type_ = self.get_posted_data(request, "type")
    if type_ == "comment":
        blog_page = self.get_page_by_name("blog_view")
        await blog_page.on_data_post(self, request)
    elif type_ == "attendance":
        profile = self.get_profile(request)
        service, node, attend, guests = self.get_posted_data(
            request, ("service", "node", "attend", "guests")
        )
        data = {"attend": attend, "guests": guests}
        await self.host.bridge_call("event_invitee_set", service, node, data, profile)
    else:
        log.warning(_("Unhandled data type: {}").format(type_))