annotate 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
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
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import D_
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
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):
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
29 profile = self.getProfile(request)
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:
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
31 self.pageError(request, C.HTTP_FORBIDDEN)
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
32 rdata = self.getRData(request)
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"]
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
35 title, body = self.getPostedData(request, ("title", "body"))
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:
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.pageError(request, C.HTTP_BAD_REQUEST)
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:
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
42 await self.host.bridgeCall(
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "forumTopicCreate", service, node, topic_data, profile
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):
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.pageError(request, 401)
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
69ba6b2ba949 pages (forums/topics): new page to edit a topic using blog editor
Goffi <goffi@goffi.org>
parents:
diff changeset
51 rdata["post_redirect_page"] = (self.getPageByName("forum_topics"), service, node)