view libervia/web/pages/u/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/u/page_meta.py@106bae41f5c8
children
line wrap: on
line source

#!/usr/bin/env python3


from libervia.web.server.constants import Const as C
from twisted.internet import defer
from twisted.words.protocols.jabber import jid

"""page used to target a user profile, e.g. for public blog"""

name = "user"
access = C.PAGES_ACCESS_PUBLIC  # can be a callable
template = "blog/articles.html"
url_cache = True


@defer.inlineCallbacks
def parse_url(self, request):
    try:
        prof_requested = self.next_path(request)
    except IndexError:
        self.page_error(request)

    data = self.get_r_data(request)

    target_profile = yield self.host.bridge_call("profile_name_get", prof_requested)
    request.template_data["target_profile"] = target_profile
    target_jid = yield self.host.bridge_call(
        "param_get_a_async", "JabberID", "Connection", "value", profile_key=target_profile
    )
    target_jid = jid.JID(target_jid)
    data["service"] = target_jid

    # if URL is parsed here, we'll have atom.xml available and we need to
    # add the link to the page
    atom_url = self.get_sub_page_url(request, 'user_blog_feed_atom')
    request.template_data['atom_url'] = atom_url
    request.template_data.setdefault('links', []).append({
        "href": atom_url,
        "type": "application/atom+xml",
        "rel": "alternate",
        "title": "{target_profile}'s blog".format(target_profile=target_profile)})

def add_breadcrumb(self, request, breadcrumbs):
    # we don't want a breadcrumb here
    pass


@defer.inlineCallbacks
def prepare_render(self, request):
    data = self.get_r_data(request)
    self.check_cache(
        request, C.CACHE_PUBSUB, service=data["service"], node=None, short="microblog"
    )
    self.page_redirect("blog_view", request)

def on_data_post(self, request):
    return self.get_page_by_name("blog_view").on_data_post(self, request)