Mercurial > libervia-web
comparison libervia/pages/forums/topics/new/page_meta.py @ 1424:69ba6b2ba949
pages (forums/topics): new page to edit a topic using blog editor
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 19:05:16 +0200 |
parents | |
children | 106bae41f5c8 |
comparison
equal
deleted
inserted
replaced
1423:870b198e98ea | 1424:69ba6b2ba949 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 from libervia.server.constants import Const as C | |
5 from sat.core.i18n import D_ | |
6 from sat.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.getProfile(request) | |
30 if profile is None: | |
31 self.pageError(request, C.HTTP_FORBIDDEN) | |
32 rdata = self.getRData(request) | |
33 service = rdata["service"].full() if rdata["service"] else "" | |
34 node = rdata["node"] | |
35 title, body = self.getPostedData(request, ("title", "body")) | |
36 title = title.strip() | |
37 body = body.strip() | |
38 if not title or not body: | |
39 self.pageError(request, C.HTTP_BAD_REQUEST) | |
40 topic_data = {"title": title, "content": body} | |
41 try: | |
42 await self.host.bridgeCall( | |
43 "forumTopicCreate", service, node, topic_data, profile | |
44 ) | |
45 except Exception as e: | |
46 if "forbidden" in str(e): | |
47 self.pageError(request, 401) | |
48 else: | |
49 raise e | |
50 | |
51 rdata["post_redirect_page"] = (self.getPageByName("forum_topics"), service, node) |