Exemplo n.º 1
0
def article_read(context, request):
    """
    Display an article
    """
    c = ArticleLib()
    result = {}
    page_id = request.matchdict.get('page_id') or "Front_Page"
    revision_id = request.matchdict.get('revision')
    try:
        page = c.show_page(page_id)
        if revision_id:
            revision = c.show_revision(page, revision_id)
        else:
            revision = page.revisions[0]
        if page.private and not has_permission("set_private", context,
                                               request):
            raise HTTPForbidden
        else:
            result.update({
                'page': page,
                'revision': revision,
                "revision_id": revision_id,
                "thread_enabled": False
            })

            if (request.query_string.startswith("comments")
                    and page.thread_id != -1):
                from pyracms_forum.views import get_thread
                result.update(get_thread(context, request, page.thread_id))
                result.update({"thread_enabled": True})
            return result
    except PageNotFound:
        return redirect(request, "article_create", page_id=page_id)
Exemplo n.º 2
0
def article_hide_display_name(context, request):
    """
    Hide display name header
    """
    c = ArticleLib()
    page_id = request.matchdict.get('page_id')
    c.hide_display_name(page_id)
    return redirect(request, "article_read", page_id=page_id)
Exemplo n.º 3
0
def article_switch_renderer(context, request):
    """
    Use another rendering engine for the page
    """
    c = ArticleLib()
    page_id = request.matchdict.get('page_id')
    c.switch_renderer(page_id)
    return redirect(request, "article_read", page_id=page_id)
Exemplo n.º 4
0
def article_set_private(context, request):
    """
    Make page private
    """
    c = ArticleLib()
    page_id = request.matchdict.get('page_id')
    c.set_private(request, page_id)
    return redirect(request, "article_read", page_id=page_id)
Exemplo n.º 5
0
def check_owner(context, request):
    page_id = request.matchdict.get('page_id')
    g = ArticleLib()
    page = g.show_page(page_id)
    if (has_permission('article_mod', context, request)
            or page.user == u.show(get_username(request))):
        return True
    else:
        raise HTTPForbidden
Exemplo n.º 6
0
def article_add_vote(context, request):
    """
    Add a vote to an article
    """
    vote_id = request.matchdict.get('vote_id')
    like = request.matchdict.get('like').lower() == "true"
    a = ArticleLib()
    article = a.show_page(vote_id)
    try:
        a.add_vote(article, u.show(get_username(request)), like)
        request.session.flash(s.show_setting("INFO_VOTE"), INFO)
    except AlreadyVoted:
        request.session.flash(s.show_setting("ERROR_VOTE"), ERROR)
    return redirect(request, "article_read", page_id=vote_id)
Exemplo n.º 7
0
def article_list_revisions(context, request):
    """
    Show a list of article revisions, every time a change is made, 
    a revision is added
    """
    c = ArticleLib()
    page_id = request.matchdict.get('page_id')
    try:
        page = c.show_page(page_id)
    except PageNotFound:
        request.session.flash(
            s.show_setting("ERROR_NOT_FOUND") % page_id, ERROR)
        return redirect(request, "article_list")
    return {'page': page}
Exemplo n.º 8
0
def article_delete(context, request):
    """
    Delete an article
    """
    check_owner(context, request)
    c = ArticleLib()
    page_id = request.matchdict.get('page_id')
    try:
        c.delete(request, c.show_page(page_id))
        request.session.flash(s.show_setting("INFO_DELETED") % page_id, INFO)
        return redirect(request, "article_list")
    except PageNotFound:
        request.session.flash(
            s.show_setting("ERROR_NOT_FOUND") % page_id, ERROR)
        return redirect(request, "article_list")
Exemplo n.º 9
0
def article_update(context, request):
    """
    Display edit article form
    """
    check_owner(context, request)
    c = ArticleLib()

    def article_update_submit(context, request, deserialized, bind_params):
        """
        Add a article revision to the database
        """
        page = bind_params.get("page")
        name = request.matchdict.get("page_id")
        article = deserialized.get("article")
        summary = deserialized.get("summary")
        tags = deserialized.get("tags")
        page.display_name = deserialized.get("display_name")
        c.update(request, page, article, summary,
                 u.show(get_username(request)), tags)
        return redirect(request, "article_read", page_id=name)

    page_id = request.matchdict.get('page_id')
    page = c.show_page(page_id)
    revision = c.show_revision(page, request.matchdict.get('revision'))
    t = TagLib(ArticleTags, ARTICLE)
    display_name = page_id
    article = ""
    tags = ""
    if page:
        display_name = page.display_name
        article = page.revisions[0].article
        tags = t.get_tags(page)
    return rapid_deform(context,
                        request,
                        EditArticleSchema,
                        article_update_submit,
                        page=page,
                        revision=revision,
                        article=article,
                        display_name=display_name,
                        tags=tags)
Exemplo n.º 10
0
def article_create(context, request):
    """
    Display create a new article form
    """
    c = ArticleLib()

    def article_create_submit(context, request, deserialized, bind_params):
        """
        Save new article to the database
        """
        name = request.matchdict.get("page_id")
        display_name = deserialized.get("display_name")
        article = deserialized.get("article")
        summary = deserialized.get("summary")
        tags = deserialized.get("tags")
        c.create(request, name, display_name, article, summary,
                 u.show(get_username(request)), tags)
        return redirect(request, "article_read", page_id=name)

    return rapid_deform(context, request, EditArticleSchema,
                        article_create_submit,
                        page_id=request.matchdict.get("page_id"))
Exemplo n.º 11
0
def article_revert(context, request):
    """
    Revert an old revision, basically makes a new revision with old contents
    """
    check_owner(context, request)
    c = ArticleLib()
    matchdict_get = request.matchdict.get
    try:
        page = c.show_page(matchdict_get('page_id'))
        c.revert(request, page, c.show_revision(page,
                                                matchdict_get('revision')),
                 u.show(get_username(request)))
        request.session.flash(s.show_setting("INFO_REVERT") % page.name, INFO)
        return redirect(request, "article_read", page_id=page.name)
    except PageNotFound:
        request.session.flash(
            s.show_setting("ERROR_NOT_FOUND") % matchdict_get('page_id'),
            ERROR)
        return redirect(request, "article_list")
Exemplo n.º 12
0
def article_list(context, request):
    """
    Show a list of articles
    """
    c = ArticleLib()
    return {'pages': c.list()}
Exemplo n.º 13
0
 def restore_backup_submit(context, request, deserialized, bind_params):
     a = ArticleLib()
     a.from_json(
         request,
         deserialized['restore_backup_json_file']['fp'].read().decode())
     return redirect(request, "article_list")
Exemplo n.º 14
0
def userarea_admin_backup_articles(context, request):
    a = ArticleLib()
    return display_json(request, a.to_json())