Пример #1
0
 def create(self, request):
     if self.check_valid_vote(self.request.user,
                              self.request.POST['comment']):
         vote = CommentVote(
             vote=True if self.request.POST.get('vote') == 'up' else False,
             user=self.request.user,
             date_voted=timezone.now(),
             comment=CustomComment.objects.get(
                 pk=self.request.POST['comment']))
         vote.save()
         action.send(
             request.user,
             action_object=vote.comment,
             verb=_(u"voted on"),
             vote=True if request.POST.get('vote') == 'up' else False)
         suff = "up" if vote.vote else "down"
         notify(request.user,
                vote.comment.user,
                action_object=vote,
                action_target=vote.comment,
                verb=_(u"voted {} for your comment".format(suff)),
                key="vote")
         return Response({'success': True, 'message': _('Vote saved')})
     else:
         return Response({
             'success': False,
             'message': _('Already voted on this comment')
         })
Пример #2
0
 def create(self, request):
     if self.check_valid_vote(self.request.user, self.request.POST['comment']):
         vote = CommentVote(vote=True if self.request.POST.get('vote') == 'up' else False,
                            user=self.request.user,
                            date_voted = timezone.now(),
                            comment=CustomComment.objects.get(pk=self.request.POST['comment']))
         vote.save()
         action.send(
             request.user,
             action_object=vote.comment,
             verb= _(u"voted on"),
             vote = True if request.POST.get('vote') == 'up' else False
         )
         suff = "up" if vote.vote else "down"
         notify(
             request.user,
             vote.comment.user,
             action_object=vote,
             action_target=vote.comment,
             verb=_(u"voted {} for your comment".format(suff)),
             key="vote"
         )
         return Response({
             'success': True,
             'message': _('Vote saved')
         })
     else:
         return Response({
             'success': False,
             'message': _('Already voted on this comment')
         })
Пример #3
0
 def create(self, request):
     if self.check_valid_vote(self.request.user,
                              self.request.POST['comment']):
         vote = CommentVote(
             vote=True if self.request.POST.get('vote') == 'up' else False,
             user=self.request.user,
             date_voted=timezone.now(),
             comment=CustomComment.objects.get(
                 pk=self.request.POST['comment']))
         vote.save()
         action.send(
             request.user,
             action_object=vote.comment,
             verb=_(u"voted on"),
             vote=True if request.POST.get('vote') == 'up' else False)
         return Response({'success': True, 'message': _('Vote saved')})
     else:
         return Response({
             'success': False,
             'message': _('Already voted on this comment')
         })
Пример #4
0
def upvote_comment(request, comment_id):
    if request.method != "POST":
        raise Http404()

    comment = get_object_or_404(Comment, id=comment_id)

    _, is_created = CommentVote.upvote(
        request=request,
        user=request.me,
        comment=comment,
    )

    return {"comment": {"upvotes": comment.upvotes + (1 if is_created else 0)}}
Пример #5
0
def retract_comment_vote(request, comment_id):
    if request.method != "POST":
        raise Http404()

    comment = get_object_or_404(Comment, id=comment_id)

    is_retracted = CommentVote.retract_vote(
        request=request,
        user=request.me,
        comment=comment,
    )

    return {
        "success": is_retracted,
        "comment": {
            "upvotes": comment.upvotes - (1 if is_retracted else 0)
        }
    }
Пример #6
0
def upvote_comment(request, comment_id):
    if request.method != "POST":
        raise Http404()

    comment = get_object_or_404(Comment, id=comment_id)

    post_vote, is_created = CommentVote.upvote(
        request=request,
        user=request.me,
        comment=comment,
    )

    return {
        "comment": {
            "upvotes": comment.upvotes + (1 if is_created else 0)
        },
        "upvoted_timestamp": int(post_vote.created_at.timestamp() * 1000)
    }
Пример #7
0
def upvote_comment(update: Update, context: CallbackContext) -> None:
    user = get_club_user(update)
    if not user:
        return None

    comment = get_club_comment(update)
    if not comment:
        return None

    _, is_created = CommentVote.upvote(
        user=user,
        comment=comment,
    )

    if is_created:
        update.message.reply_text(f"Заплюсовано 👍")
    else:
        update.message.reply_text(f"Ты уже плюсовал, поц")