Mercurial > libervia-web
view libervia/pages/forums/topics/page_meta.py @ 1247:a6c7f07f1e4d
tasks: implicit tasks + Brython task:
- implicit tasks are tasks launched for every site.
- a first one is made for Brython: it will install Brython and copy suitable files and set
template data if Brython code is written in page `_browser` subdirectory.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Apr 2020 22:07:18 +0200 |
parents | 8aff742d0dd0 |
children | 6b7f9c3558cc |
line wrap: on
line source
#!/usr/bin/env python3 from libervia.server.constants import Const as C from twisted.internet import defer from sat.core.i18n import _ from sat.core.log import getLogger from sat.tools.common import uri as xmpp_uri from sat.tools.common import data_format log = getLogger(__name__) name = "forum_topics" access = C.PAGES_ACCESS_PUBLIC template = "forum/view_topics.html" def parse_url(self, request): self.getPathArgs(request, ["service", "node"], 2, service="jid") @defer.inlineCallbacks def prepare_render(self, request): profile = self.getProfile(request) or C.SERVICE_PROFILE data = self.getRData(request) service, node = data["service"], data["node"] request.template_data.update({"service": service, "node": node}) template_data = request.template_data topics, metadata = yield self.host.bridgeCall( "forumTopicsGet", service.full(), node, {}, profile ) template_data["identities"] = identities = {} for topic in topics: parsed_uri = xmpp_uri.parseXMPPUri(topic["uri"]) author = topic["author"] topic["http_uri"] = self.getPageByName("forum_view").getURL( parsed_uri["path"], parsed_uri["node"] ) if author not in identities: id_raw = yield self.host.bridgeCall( "identityGet", author, [], True, profile ) identities[topic["author"]] = data_format.deserialise(id_raw) template_data["topics"] = topics @defer.inlineCallbacks def on_data_post(self, request): profile = self.getProfile(request) if profile is None: self.pageError(request, C.HTTP_FORBIDDEN) type_ = self.getPostedData(request, "type") if type_ == "new_topic": service, node, title, body = self.getPostedData( request, ("service", "node", "title", "body") ) if not title or not body: self.pageError(request, C.HTTP_BAD_REQUEST) topic_data = {"title": title, "content": body} try: yield self.host.bridgeCall( "forumTopicCreate", service, node, topic_data, profile ) except Exception as e: if "forbidden" in str(e): self.pageError(request, 401) else: raise e else: log.warning(_("Unhandled data type: {}").format(type_))