Ejemplo n.º 1
0
def comment_review_like(request):
    id_comment = request.POST.get('id_comment', False)
    response_data = {}
    if id_comment:
        obj, create = LikeComment.objects.get_or_create(user_profile=request.user.user_profile,
                                                        comment=CommentReview.objects.get(pk=id_comment))
        obj.save()
        try:
            """ Install activity in database """
            create_activity(request.user.pk, 'like_comment', id_comment,
                            'Like comment ' + CommentReview.objects.get(pk=id_comment).content)
        except:
            pass

        try:
            """ Change level follow """
            change_follow_level(follower=request.user.user_profile,
                                followee=CommentReview.objects.get(pk=id_comment).user_profile)
        except:
            pass
        response_data['result'] = True
        response_data['like'] = CommentReview.objects.get(id=id_comment).get_total_like()
        return JsonResponse(response_data)
    else:
        response_data['result'] = False
Ejemplo n.º 2
0
def review_like(request):
    review_id = request.POST.get('review_id', False)
    user_id = request.POST.get('user_id', False)
    response_data = {}
    if review_id and request.user:
        obj, create = LikeReview.objects.get_or_create(user_profile=User.objects.get(id=user_id).user_profile,
                                                       review=Review.objects.get(pk=review_id))
        obj.save()
        try:
            """ Install activity in database """
            create_activity(request.user.pk, 'like_review', review_id,
                            'Like review ' + Review.objects.get(pk=review_id).content)
        except:
            pass
        try:
            """ Change the follow level """
            change_follow_level(follower=request.user.user_profile,
                                followee=Review.objects.get(pk=review_id).user_profile)
        except:
            pass
        response_data['result'] = True
        response_data['like'] = Review.objects.get(id=review_id).like_review.all().count()
        return JsonResponse(response_data)
    elif request.user:
        response_data['result'] = False
        return JsonResponse(response_data)
    else:
        response_data['result'] = False
        return JsonResponse(response_data)
Ejemplo n.º 3
0
def comment_create(request):
    review_id = request.POST.get('review_id', '')
    content_comment = request.POST.get('content_comment', False)
    response_data = {}
    if review_id and request.user:
        obj = CommentReview.objects.create(user_profile=request.user.user_profile,
                                           review=Review.objects.get(pk=review_id.strip()))
        obj.content = content_comment
        obj.save()
        try:
            """ Install activity in database """
            user_id = request.user.pk
            content_review = Review.objects.get(pk=review_id).content
            create_activity(user_id, 'write_comment', review_id,
                            'Write comment ' + content_review)
        except:
            pass
        try:
            """ Change the follow level """
            change_follow_level(follower=request.user.user_profile,
                                followee=Review.objects.get(pk=review_id).user_profile)
        except:
            pass
        html = render_to_string('book/comment_review.html', {'review': obj.review, 'comment': obj})
        res = {'html': html}
        return JsonResponse(res)
    else:
        response_data['result'] = 'error'
        return JsonResponse(response_data)
Ejemplo n.º 4
0
 def get_object(self, queryset=None):
     self.object = User.objects.get(username=self.kwargs['username'])
     if self.object in return_list_following_of_user(self.request.user):
         """ Change the follow level """
         change_follow_level(follower=self.request.user.user_profile, followee=self.object.user_profile)
     return self.object