Ejemplo n.º 1
0
    def test_sticker_from_user(self):
        user = create_user()
        comment = create_comment()
        self.assertFalse(CommentSticker.get_sticker_from_user(comment.id, user))

        self.api_post('/api/sticker/comment', {'type_id': '1', 'comment_id': comment.id}, user=user)
        self.assertTrue(CommentSticker.get_sticker_from_user(comment.id, user))
Ejemplo n.º 2
0
    def test_sticker_from_user(self):
        user = create_user()
        comment = create_comment()
        self.assertFalse(CommentSticker.get_sticker_from_user(comment.id, user))

        self.api_post("/api/sticker/comment", {"type_id": "1", "comment_id": comment.id}, user=user)
        self.assertTrue(CommentSticker.get_sticker_from_user(comment.id, user))
Ejemplo n.º 3
0
    def test_sticker_from_user(self):
        user = create_user()
        comment = create_comment()
        self.assertFalse(CommentSticker.get_sticker_from_user(
            comment.id, user))

        self.api_post('/api/sticker/comment', {
            'type_id': '1',
            'comment_id': comment.id
        },
                      user=user)
        self.assertTrue(CommentSticker.get_sticker_from_user(comment.id, user))
Ejemplo n.º 4
0
def thread_new_comment(context, comment, is_op=False, is_current=False, is_first_reply_with_content=False, is_last_reply_with_content=False, ignore_lazy_load=False):
    from canvas.templatetags.helpers import TemplateComment
    from canvas.models import CommentSticker

    request = context['request']
    comment = TemplateComment(comment, request_context=context, is_op=is_op)

    try:
        sticker_name = comment.top_sticker()['name']
    except TypeError:
        sticker_name = None

    try:
        viewer_following_thread = request.user.redis.followed_threads.sismember(comment.id)
    except AttributeError:
        viewer_following_thread = False

    ctx = {
        'request': request,
        'short_id': context.get('short_id'),
        'comment': comment,
        'can_edit_tags': request.user.is_staff or comment.is_author(request.user),
        'lazy_content': features.lazy_content(request),
        'is_current':is_current,
        'ignore_lazy_load': ignore_lazy_load,
        'is_first_reply_with_content': is_first_reply_with_content,
        'is_last_reply_with_content': is_last_reply_with_content,
        'my_post': comment.is_author(request.user),
        'stickered_by_viewer': bool(CommentSticker.get_sticker_from_user(comment.id, request.user)),
        'sticker_name': sticker_name,
        'has_content': bool(comment.reply_content_id),
        'viewer_following_thread': viewer_following_thread,
    }

    return Markup(render_jinja_to_string('threads_new/_thread_comment.html', ctx))
Ejemplo n.º 5
0
def thread_new_comment(context,
                       comment,
                       is_op=False,
                       is_current=False,
                       is_first_reply_with_content=False,
                       is_last_reply_with_content=False,
                       ignore_lazy_load=False):
    from canvas.templatetags.helpers import TemplateComment
    from canvas.models import CommentSticker

    request = context['request']
    comment = TemplateComment(comment, request_context=context, is_op=is_op)

    try:
        sticker_name = comment.top_sticker()['name']
    except TypeError:
        sticker_name = None

    try:
        viewer_following_thread = request.user.redis.followed_threads.sismember(
            comment.id)
    except AttributeError:
        viewer_following_thread = False

    ctx = {
        'request':
        request,
        'short_id':
        context.get('short_id'),
        'comment':
        comment,
        'can_edit_tags':
        request.user.is_staff or comment.is_author(request.user),
        'lazy_content':
        features.lazy_content(request),
        'is_current':
        is_current,
        'ignore_lazy_load':
        ignore_lazy_load,
        'is_first_reply_with_content':
        is_first_reply_with_content,
        'is_last_reply_with_content':
        is_last_reply_with_content,
        'my_post':
        comment.is_author(request.user),
        'stickered_by_viewer':
        bool(CommentSticker.get_sticker_from_user(comment.id, request.user)),
        'sticker_name':
        sticker_name,
        'has_content':
        bool(comment.reply_content_id),
        'viewer_following_thread':
        viewer_following_thread,
    }

    return Markup(
        render_jinja_to_string('threads_new/_thread_comment.html', ctx))
Ejemplo n.º 6
0
    def test_notifies_author(self):
        author = utils.create_user()
        comment = utils.create_comment()
        comment.author = author
        comment.save()
        another_user = utils.create_user()

        comment_sticker = CommentSticker(comment=comment,
                                         type_id=stickers.get("num1").type_id,
                                         timestamp=time.time(),
                                         ip="127.0.0.1",
                                         user=another_user)
        pn = Actions.stickered(another_user, comment_sticker)

        ex = expander.get_expander(pn)()
        recipients = ex.decide_recipients(pn)
        self.assertEqual(len(recipients), 1)
        self.assertIn(author, recipients)
Ejemplo n.º 7
0
def thread_new_comment(
    context,
    comment,
    is_op=False,
    is_current=False,
    is_first_reply_with_content=False,
    is_last_reply_with_content=False,
    ignore_lazy_load=False,
):
    from canvas.templatetags.helpers import TemplateComment
    from canvas.models import CommentSticker

    request = context["request"]
    comment = TemplateComment(comment, request_context=context, is_op=is_op)

    try:
        sticker_name = comment.top_sticker()["name"]
    except TypeError:
        sticker_name = None

    try:
        viewer_following_thread = request.user.redis.followed_threads.sismember(comment.id)
    except AttributeError:
        viewer_following_thread = False

    ctx = {
        "request": request,
        "comment": comment,
        "can_edit_tags": request.user.is_staff or comment.is_author(request.user),
        "lazy_content": features.lazy_content(request),
        "is_current": is_current,
        "ignore_lazy_load": ignore_lazy_load,
        "is_first_reply_with_content": is_first_reply_with_content,
        "is_last_reply_with_content": is_last_reply_with_content,
        "my_post": comment.is_author(request.user),
        "stickered_by_viewer": bool(CommentSticker.get_sticker_from_user(comment.id, request.user)),
        "sticker_name": sticker_name,
        "has_content": bool(comment.reply_content_id),
        "viewer_following_thread": viewer_following_thread,
    }

    return Markup(render_jinja_to_string("threads_new/_thread_comment.html", ctx))
Ejemplo n.º 8
0
def _add_viewer_sticker_to_item(item, user):
    from canvas.models import CommentSticker
    item['viewer_sticker'] = CommentSticker.get_sticker_from_user(
        item['comment'].id, user)
Ejemplo n.º 9
0
def _add_viewer_sticker_to_item(item, user):
    from canvas.models import CommentSticker
    item['viewer_sticker'] = CommentSticker.get_sticker_from_user(item['comment'].id, user)