view 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
line wrap: on
line source

#!/usr/bin/env python3

from libervia.server.constants import Const as C
from sat.core.log import getLogger
from sat.tools.common import data_format

log = getLogger(__name__)

name = "blog_edit"
access = C.PAGES_ACCESS_PROFILE
template = "blog/publish.html"


async def on_data_post(self, request):
    profile = self.getProfile(request)
    if profile is None:
        self.pageError(request, C.HTTP_FORBIDDEN)
    request_data = self.getRData(request)
    request_data["post_redirect_page"] = self.getPageByName("blog")
    title, tags, body = self.getPostedData(request, ('title', 'tags', 'body'))
    mb_data = {"content_rich": body}
    title = title.strip()
    if title:
        mb_data["title_rich"] = title
    tags = [t.strip() for t in tags.split(',') if t.strip()]
    if tags:
        mb_data["tags"] = tags

    await self.host.bridgeCall(
        'mbSend',
        "",
        "",
        data_format.serialise(mb_data),
        profile
    )