Example #1
0
def topic_show_post(request):
    """Handle form posting for replying to a topic.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict
    """
    board = board_get(request)
    topic = topic_get(request)
    override = _get_override(request, board=board)

    if not topic.board_id == board.id:
        raise HTTPNotFound(request.path)

    form = SecurePostForm(request.params, request=request)

    try:
        task = topic_posts_post(request, board=board, topic=topic, form=form)
    except RateLimitedError as e:
        timeleft = e.timeleft
        response = render_to_response('topics/error_rate.mako', locals())
        response.status = e.http_status
        return response
    except ParamsInvalidError as e:
        request.response.status = e.http_status
        return locals()

    return HTTPFound(location=request.route_path(
        route_name='topic',
        board=topic.board.slug,
        topic=topic.id,
        _query={'task': task.id}))
Example #2
0
def board_new_post(request):
    """Handle form posting for creating new topic in a board.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict
    """
    board = board_get(request)
    form = SecureTopicForm(request.params, request=request)
    override = _get_override(request, board=board)

    try:
        task = board_topics_post(request, board=board, form=form)
    except RateLimitedError as e:
        timeleft = e.timeleft
        response = render_to_response('boards/error_rate.mako', locals())
        response.status = e.http_status
        return response
    except ParamsInvalidError as e:
        request.response.status = e.http_status
        return locals()

    return HTTPFound(location=request.route_path(
        route_name='board_new',
        board=board.slug,
        _query={'task': task.id}))
Example #3
0
def board_all(request):
    """Display a single board with a list of all its topic.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict
    """
    board = board_get(request)
    topics = board_topics_get(request).all()
    override = _get_override(request, board=board)
    return locals()
Example #4
0
def board_show(request):
    """Display a single board with its related topics.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict
    """
    board = board_get(request)
    topics = board_topics_get(request).limit(10)
    override = _get_override(request, board=board)
    return locals()
Example #5
0
def topic_show_get(request):
    """Display a single topic with its related posts. If a `task` query string
    is given, the function will try to retrieve and process that task in topic
    context instead.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict | pyramid.response.Response
    """
    board = board_get(request)
    topic = topic_get(request)
    override = _get_override(request, board=board)

    if request.params.get('task'):
        try:
            task_result = celery.AsyncResult(request.params['task'])
            task = task_get(request, task_result)
        except SpamRejectedError as e:
            response = render_to_response('topics/error_spam.mako', locals())
            response.status = e.http_status
            return response
        except DnsblRejectedError as e:
            response = render_to_response('topics/error_dnsbl.mako', locals())
            response.status = e.http_status
            return response
        except BanRejectedError as e:
            response = render_to_response('topics/error_ban.mako', locals())
            response.status = e.http_status
            return response
        except StatusRejectedError as e:
            status = e.status
            response = render_to_response('topics/error_status.mako', locals())
            response.status = e.http_status
            return response
        except ProxyRejectedError as e:
            response = render_to_response('topics/error_proxy.mako', locals())
            response.status = e.http_status
            return response

        if task.success():
            return HTTPFound(location=request.route_path(
                route_name='topic_scoped',
                board=board.slug,
                topic=topic.id,
                query='l10'))
        return render_to_response('topics/show_wait.mako', locals())

    posts = topic_posts_get(request, topic=topic)
    if not topic.board_id == board.id or not posts:
        raise HTTPNotFound(request.path)
    form = SecurePostForm(request=request)
    return locals()
Example #6
0
def board_new_get(request):
    """Display a form for creating new topic in a board. If a `task` query
    string is given, the function will try to retrieve and process that task
    in board context instead.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: dict | pyramid.response.Response
    """
    board = board_get(request)
    override = _get_override(request, board=board)

    if override.get('status', board.status) != 'open':
        raise HTTPNotFound(request.path)

    if request.params.get('task'):
        try:
            task_result = celery.AsyncResult(request.params['task'])
            task = task_get(request, task_result)
        except SpamRejectedError as e:
            response = render_to_response('boards/error_spam.mako', locals())
            response.status = e.http_status
            return response
        except DnsblRejectedError as e:
            response = render_to_response('boards/error_dnsbl.mako', locals())
            response.status = e.http_status
            return response
        except BanRejectedError as e:
            response = render_to_response('boards/error_ban.mako', locals())
            response.status = e.http_status
            return response
        except StatusRejectedError as e:
            status = e.status
            response = render_to_response('boards/error_status.mako', locals())
            response.status = e.http_status
            return response
        except ProxyRejectedError as e:
            response = render_to_response('boards/error_proxy.mako', locals())
            response.status = e.http_status
            return response

        if task.success():
            topic = task.object
            return HTTPFound(location=request.route_path(
                route_name='topic',
                board=board.slug,
                topic=topic.id))
        return render_to_response('boards/new_wait.mako', locals())

    form = SecureTopicForm(request=request)
    return locals()