Ejemplo 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)
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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}
Ejemplo n.º 5
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")
Ejemplo n.º 6
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")
Ejemplo n.º 7
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)