annotate libervia/pages/blog/edit/page_meta.py @ 1416:0554103ec700

pages (blog): new `edit` page: this page is used for new blog post and may be used for editing existing posts too. New `editor` module is using for autosave and tags editor. New `mbPreview` bridge method is used to generate preview when javascript is available.
author Goffi <goffi@goffi.org>
date Thu, 29 Apr 2021 16:55:07 +0200
parents
children 925a7c498cda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1416
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.core.log import getLogger
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.tools.common import data_format
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 log = getLogger(__name__)
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
8
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 name = "blog_edit"
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 access = C.PAGES_ACCESS_PROFILE
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 template = "blog/publish.html"
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 async def on_data_post(self, request):
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 profile = self.getProfile(request)
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 if profile is None:
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 self.pageError(request, C.HTTP_FORBIDDEN)
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 request_data = self.getRData(request)
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 request_data["post_redirect_page"] = self.getPageByName("blog")
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 title, tags, body = self.getPostedData(request, ('title', 'tags', 'body'))
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 mb_data = {"content_rich": body}
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 title = title.strip()
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 if title:
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 mb_data["title_rich"] = title
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 tags = [t.strip() for t in tags.split(',') if t.strip()]
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 if tags:
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 mb_data["tags"] = tags
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 await self.host.bridgeCall(
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 'mbSend',
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "",
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 "",
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 data_format.serialise(mb_data),
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 profile
0554103ec700 pages (blog): new `edit` page:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 )