Пример #1
0
    with request.db_session.no_autoflush:
        request.query(CommentNotification).filter(
            CommentNotification.user == request.user,
            CommentNotification.comment == comment,
            CommentNotification.is_unread == True,  # noqa
        ).update({"is_unread": False}, synchronize_session=False)


@ic_view_config(
    route_name="topic_comments",
    request_method="POST",
    renderer="single_comment.jinja2",
    permission="comment",
)
@use_kwargs(CommentSchema(only=("markdown", )))
@rate_limit_view("comment_post")
def post_toplevel_comment(request: Request, markdown: str) -> dict:
    """Post a new top-level comment on a topic with Intercooler."""
    topic = request.context

    new_comment = Comment(topic=topic, author=request.user, markdown=markdown)
    request.db_session.add(new_comment)

    request.db_session.add(
        LogComment(LogEventType.COMMENT_POST, request, new_comment))

    if CommentNotification.should_create_reply_notification(new_comment):
        notification = CommentNotification(topic.user, new_comment,
                                           CommentNotificationType.TOPIC_REPLY)
        request.db_session.add(notification)
Пример #2
0
    CommentTag,
    CommentVote,
)
from tildes.models.topic import TopicVisit
from tildes.schemas.comment import CommentSchema, CommentTagSchema
from tildes.views import IC_NOOP
from tildes.views.decorators import ic_view_config


@ic_view_config(
    route_name='topic_comments',
    request_method='POST',
    renderer='single_comment.jinja2',
    permission='comment',
)
@use_kwargs(CommentSchema(only=('markdown', )))
def post_toplevel_comment(request: Request, markdown: str) -> dict:
    """Post a new top-level comment on a topic with Intercooler."""
    topic = request.context

    new_comment = Comment(
        topic=topic,
        author=request.user,
        markdown=markdown,
    )
    request.db_session.add(new_comment)

    if topic.user != request.user and not topic.is_deleted:
        notification = CommentNotification(
            topic.user,
            new_comment,
Пример #3
0
    with request.db_session.no_autoflush:
        request.query(CommentNotification).filter(
            CommentNotification.user == request.user,
            CommentNotification.comment == comment,
            CommentNotification.is_unread == True,  # noqa
        ).update({"is_unread": False}, synchronize_session=False)


@ic_view_config(
    route_name="topic_comments",
    request_method="POST",
    renderer="single_comment.jinja2",
    permission="comment",
)
@use_kwargs(CommentSchema(only=("markdown",)), location="form")
@rate_limit_view("comment_post")
def post_toplevel_comment(request: Request, markdown: str) -> dict:
    """Post a new top-level comment on a topic with Intercooler."""
    topic = request.context

    new_comment = Comment(topic=topic, author=request.user, markdown=markdown)
    request.db_session.add(new_comment)

    request.db_session.add(LogComment(LogEventType.COMMENT_POST, request, new_comment))

    if CommentNotification.should_create_reply_notification(new_comment):
        notification = CommentNotification(
            topic.user, new_comment, CommentNotificationType.TOPIC_REPLY
        )
        request.db_session.add(notification)
Пример #4
0
"""Root factories for comments."""

from pyramid.request import Request
from webargs.pyramidparser import use_kwargs

from tildes.lib.id import id36_to_id
from tildes.models.comment import Comment
from tildes.resources import get_resource
from tildes.schemas.comment import CommentSchema


@use_kwargs(
    CommentSchema(only=('comment_id36',)),
    locations=('matchdict',),
)
def comment_by_id36(request: Request, comment_id36: str) -> Comment:
    """Get a comment specified by {comment_id36} in the route (or 404)."""
    comment_id = id36_to_id(comment_id36)
    query = request.query(Comment).filter_by(comment_id=comment_id)

    return get_resource(request, query)
Пример #5
0
# Copyright (c) 2018 Tildes contributors <*****@*****.**>
# SPDX-License-Identifier: AGPL-3.0-or-later

"""Root factories for comments."""

from pyramid.httpexceptions import HTTPForbidden, HTTPNotFound
from pyramid.request import Request

from tildes.lib.id import id36_to_id
from tildes.models.comment import Comment, CommentNotification
from tildes.resources import get_resource
from tildes.schemas.comment import CommentSchema
from tildes.views.decorators import use_kwargs


@use_kwargs(CommentSchema(only=("comment_id36",)), location="matchdict")
def comment_by_id36(request: Request, comment_id36: str) -> Comment:
    """Get a comment specified by {comment_id36} in the route (or 404)."""
    query = (
        request.query(Comment)
        .include_removed()
        .filter_by(comment_id=id36_to_id(comment_id36))
    )

    try:
        return get_resource(request, query)
    except HTTPNotFound as exc:
        raise HTTPNotFound("Comment not found (or it was deleted)") from exc


@use_kwargs(CommentSchema(only=("comment_id36",)), location="matchdict")