Mercurial > libervia-web
comparison libervia/web/pages/forums/topics/new/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/forums/topics/new/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 D_ | |
6 from libervia.backend.core.log import getLogger | |
7 | |
8 log = getLogger(__name__) | |
9 | |
10 name = "forum_topic_new" | |
11 label = D_("New Topic") | |
12 access = C.PAGES_ACCESS_PROFILE | |
13 template = "blog/publish.html" | |
14 | |
15 | |
16 async def prepare_render(self, request): | |
17 template_data = request.template_data | |
18 template_data.update({ | |
19 "post_form_id": "forum_topic_edit", | |
20 "publish_title": D_("New Forum Topic"), | |
21 "title_label": D_("Topic"), | |
22 "title_required": True, | |
23 "body_label": D_("Message"), | |
24 "no_tabs": True, | |
25 }) | |
26 | |
27 | |
28 async def on_data_post(self, request): | |
29 profile = self.get_profile(request) | |
30 if profile is None: | |
31 self.page_error(request, C.HTTP_FORBIDDEN) | |
32 rdata = self.get_r_data(request) | |
33 service = rdata["service"].full() if rdata["service"] else "" | |
34 node = rdata["node"] | |
35 title, body = self.get_posted_data(request, ("title", "body")) | |
36 title = title.strip() | |
37 body = body.strip() | |
38 if not title or not body: | |
39 self.page_error(request, C.HTTP_BAD_REQUEST) | |
40 topic_data = {"title": title, "content": body} | |
41 try: | |
42 await self.host.bridge_call( | |
43 "forum_topic_create", service, node, topic_data, profile | |
44 ) | |
45 except Exception as e: | |
46 if "forbidden" in str(e): | |
47 self.page_error(request, 401) | |
48 else: | |
49 raise e | |
50 | |
51 rdata["post_redirect_page"] = (self.get_page_by_name("forum_topics"), service, node) |