コード例 #1
0
ファイル: articles.py プロジェクト: ondratu/morias
def articles_comment_internal(req, uri=None, id=None):
    if not uri and not id:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    article = Article(id)
    article.uri = uri
    if uri and not article.get(req, key='uri'):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    if id and not article.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    comment = ArticleComment()
    comment.bind(req.form, user_agent=req.user_agent, ip=req.remote_addr)

    robot = True if req.form.getfirst("robot", "", str) else False
    qid = int(req.form.getfirst("qid", '0', str), 16)
    question, answer = robot_questions[qid]
    check = req.form.getfirst("answer", "", str) == answer

    if robot or not check:
        rv = RobotError(comment=comment, check=check)
        return (article, rv)

    if req.login:
        comment.author_id = req.login.id
    rv = comment.add(req, parent=req.form.getfirst('parent', '', str))
    return (article, rv)
コード例 #2
0
ファイル: articles.py プロジェクト: ondratu/morias
def admin_articles_mod(req, id):
    check_login(req)
    match_right(req, module_rights)

    article = Article(id)
    if not article.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    if (not do_check_right(req, right_editor)
            and article.author_id != req.login.id):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    Codebook = build_class('tags')
    pager = Pager(order='value', limit=-1)
    tags = Codebook.list(req, Codebook, pager)

    if req.method == 'POST':
        article.bind(req.form)
        error = article.mod(req)
        if error != article:
            return generate_page(req, "admin/articles_mod.html",
                                 article=article, error=error)

        if not article.get(req):
            raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    return generate_page(req, "admin/articles_mod.html", article=article,
                         token=create_token(req), tags=tags)
コード例 #3
0
ファイル: articles.py プロジェクト: ondratu/morias
def articles_detail(req, arg):
    id = arg if isinstance(arg, int) else None
    uri = arg if isinstance(arg, unicode) else None

    article = Article(id)
    article.uri = uri

    if uri and not article.get(req, key='uri'):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    if id and not article.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    if article.public_date.year == 1970:
        if req.login is None:
            raise SERVER_RETURN(state.HTTP_FORBIDDEN)
        if not do_match_right(req, module_rights):
            raise SERVER_RETURN(state.HTTP_FORBIDDEN)
        if (not do_check_right(req, right_editor)
                and article.author_id != req.login.id):
            raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    return articles_detail_internal(req, article)
コード例 #4
0
ファイル: articles.py プロジェクト: ondratu/morias
def admin_articles_enable(req, id):
    check_login(req, '/log_in?referer=/admin/articles')
    match_right(req, module_rights)
    check_referer(req, '/admin/articles')

    article = Article(id)
    if not article.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    if (not do_check_right(req, right_editor)) \
            and (not (article.author_id == req.login.id
                 and article.public_date.year == 1970)):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    n_state = int(req.uri.endswith('/enable'))
    n_state = (n_state * 2) if article.public_date.year > 1970 else n_state
    article.set_state(req, n_state)

    redirect(req, '/admin/articles')