示例#1
0
    def edit_or_create_page(self, title, html, url):
        """CMS page edit or create.

        Action for CMS Page.
        Receives title, content(html), tags and cagetory
        Save title, content(html), pure content(further use), page_url
        also auto save author as current_user.

        Args:
            POST:
                title: page title
                html: content html
                url: page url
            GET:
                page_url: string

        Returns:
            POST:
                none (for create or save page only)
            GET:
                page object or none

        Save:
            title: string
            html: string
            content: string without html tags
            url: string page_url
            summary: first 80 characters in content with 3 dots in the end
            author: current_user_object
        """
        title = SiteHelpers().secure_filename(title)
        content = SiteHelpers().strip_html_tags(html)
        author = UserDispatcher().get_profile()

        created = StaticPage.objects(url=url)

        if created:
            page = created.first()
            page.title = title
        else:
            page = StaticPage(title=title,
                              url=SiteHelpers().secure_filename(url))

        page.content = content
        page.summary = content[0:80] + '...'
        page.html = html
        page.author = author
        return page.save()
示例#2
0
    def edit_or_create_page(self, title, html, url):
        """CMS page edit or create.

        Action for CMS Page.
        Receives title, content(html), tags and cagetory
        Save title, content(html), pure content(further use), page_url
        also auto save author as current_user.

        Args:
            POST:
                title: page title
                html: content html
                url: page url
            GET:
                page_url: string

        Returns:
            POST:
                none (for create or save page only)
            GET:
                page object or none

        Save:
            title: string
            html: string
            content: string without html tags
            url: string page_url
            summary: first 80 characters in content with 3 dots in the end
            author: current_user_object
        """
        title = SiteHelpers().secure_filename(title)
        content = SiteHelpers().strip_html_tags(html)
        author = UserDispatcher().get_profile()

        created = StaticPage.objects(url=url)

        if created:
            page = created.first()
            page.title = title
        else:
            page = StaticPage(title=title,
                              url=SiteHelpers().secure_filename(url))

        page.content = content
        page.summary = content[0:80] + '...'
        page.html = html
        page.author = author
        return page.save()
示例#3
0
 def get_static_page(self, page_url):
     return StaticPage.objects(url=page_url).first()
示例#4
0
def cmspage_edit(page_url):
    """CMS page edit or create.

    Action for CMS Page.
    Receives title, content(html), tags and cagetory
    Save title, content(html), pure content(further use), page_url
    also auto save author as current_user.

    Methods:
        GET and POST

    Args:
        POST:
            title: page title
            html: content html
            url: page url
        GET:
            page_url: string

    Returns:
        POST:
            none (for create or save page only)
        GET:
            page object or none

    Save:
        title: string
        html: string
        content: string without html tags
        url: string page_url
        summary: first 80 characters in content with 3 dots in the end
        author: current_user_object
    """
    if request.method == 'POST':
        re_helper = ReHelper()

        title = re_helper.r_slash(request.form["title"])
        html = request.form["content"]
        url = request.form["url"]

        parser = MyHTMLParser()
        parser.feed(html)
        content = parser.html  # the pure content without html tags

        author = UserModel.objects.first()

        created = StaticPage.objects(url=url)

        if created:
            page = created[0]
        else:
            page = StaticPage(title=title, url=re_helper.r_slash(url))

        page.content = content
        page.summary = content[0:80] + '...'
        page.html = html
        page.author = author
        page.save()

        return redirect(url_for('admin.cmspage_list'))

    else:
        page = StaticPage.objects(url=page_url).first()

        return render_template('admin/page/edit.html', page=page)
示例#5
0
def cmspage_edit(page_url):
    """CMS page edit or create.

    Action for CMS Page.
    Receives title, content(html), tags and cagetory
    Save title, content(html), pure content(further use), page_url
    also auto save author as current_user.

    Methods:
        GET and POST

    Args:
        POST:
            title: page title
            html: content html
            url: page url
        GET:
            page_url: string

    Returns:
        POST:
            none (for create or save page only)
        GET:
            page object or none

    Save:
        title: string
        html: string
        content: string without html tags
        url: string page_url
        summary: first 80 characters in content with 3 dots in the end
        author: current_user_object
    """
    if request.method == 'POST':
        re_helper = ReHelper()

        title = re_helper.r_slash(request.form["title"])
        html = request.form["content"]
        url = request.form["url"]

        parser = MyHTMLParser()
        parser.feed(html)
        content = parser.html  # the pure content without html tags

        author = UserModel.objects.first()

        created = StaticPage.objects(url=url)

        if created:
            page = created[0]
        else:
            page = StaticPage(title=title, url=re_helper.r_slash(url))

        page.content = content
        page.summary = content[0:80] + '...'
        page.html = html
        page.author = author
        page.save()

        return redirect(url_for('admin.cmspage_list'))

    else:
        page = StaticPage.objects(url=page_url).first()

        return render_template('admin/page/edit.html', page=page)
示例#6
0
 def get_static_page(self, page_url):
     return StaticPage.objects(url=page_url).first()