annotate libervia/web/pages/forums/topics/new/page_meta.py @ 1597:c1c1d68d063e

pages (lists): uses std lib `json` and don't use anymore `DOMNODE`: those tricks are not needed anymore with recent versions of Brython.
author Goffi <goffi@goffi.org>
date Sun, 11 Feb 2024 21:32:53 +0100
parents eb00d593801d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
2
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
4 from libervia.web.server.constants import Const as C
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
5 from libervia.backend.core.i18n import D_
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
6 from libervia.backend.core.log import getLogger
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
7
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
8 log = getLogger(__name__)
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
9
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
10 name = "forum_topic_new"
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
11 label = D_("New Topic")
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
12 access = C.PAGES_ACCESS_PROFILE
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
13 template = "blog/publish.html"
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
14
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
15
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
16 async def prepare_render(self, request):
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
17 template_data = request.template_data
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
18 template_data.update({
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
19 "post_form_id": "forum_topic_edit",
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
20 "publish_title": D_("New Forum Topic"),
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
21 "title_label": D_("Topic"),
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
22 "title_required": True,
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
23 "body_label": D_("Message"),
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
24 "no_tabs": True,
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
25 })
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
26
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
27
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
28 async def on_data_post(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
29 profile = self.get_profile(request)
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
30 if profile is None:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
31 self.page_error(request, C.HTTP_FORBIDDEN)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
32 rdata = self.get_r_data(request)
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
33 service = rdata["service"].full() if rdata["service"] else ""
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
34 node = rdata["node"]
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
35 title, body = self.get_posted_data(request, ("title", "body"))
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
36 title = title.strip()
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
37 body = body.strip()
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
38 if not title or not body:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
39 self.page_error(request, C.HTTP_BAD_REQUEST)
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
40 topic_data = {"title": title, "content": body}
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
41 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
42 await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
43 "forum_topic_create", service, node, topic_data, profile
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
44 )
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
45 except Exception as e:
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
46 if "forbidden" in str(e):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
47 self.page_error(request, 401)
1424
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
48 else:
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
49 raise e
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
50
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
51 rdata["post_redirect_page"] = (self.get_page_by_name("forum_topics"), service, node)