Exemple #1
0
    def save(self):

        UserFollow.objects.filter(
            follower=self.follower, target=self.target).delete()

        if self.action == 'follow':
            UserFollow.objects.create(
                follower=self.follower, target=self.target)

        if self.action == 'block':
            UserFollow.objects.create(
                follower=self.follower, target=self.target, status=2)
        if self.action in ('unfollow', 'block', 'unblock'):
            follower_count_changed.send(sender=self.target)
            following_count_changed.send(sender=self.follower)
Exemple #2
0
    def save(self):

        UserFollow.objects.filter(
            follower=self.follower, target=self.target).delete()

        if self.action == 'follow':
            UserFollow.objects.create(
                follower=self.follower, target=self.target)

        if self.action == 'block':
            UserFollow.objects.create(
                follower=self.follower, target=self.target, status=2)
        if self.action in ('unfollow', 'block', 'unblock'):
            follower_count_changed.send(sender=self.target)
            following_count_changed.send(sender=self.follower)
Exemple #3
0
def pending_follow_request_action(request):
    if request.method == 'POST':

        frpk = request.POST.get('pk')
        try:
            frpk = int(frpk)
        except ValueError:
            return render_to_json(
                {'errMsg': 'Invalida data'}, HttpResponseBadRequest)

        action = request.POST['action']

        follow_request = get_object_or_404(
            UserFollow, pk=frpk, target=request.user)

        if action == 'accept':
            follow_request.status = UserFollow.FOLLOWING
            follow_request.save()
            follower_count_changed.send(sender=request.user)
            notify(ntype_slug='user_accepted_my_follow_request',
                   sub=follow_request.target,
                   obj=follow_request,
                   recipient=follow_request.follower,
                   url=follow_request.target.get_absolute_url())
            return render_to_json({'success': True})
        elif action == 'accept-restricted':
            follow_request.status = UserFollow.FOLLOWING_RESTRICTED
            follow_request.save()
            follower_count_changed.send(sender=request.user)
            notify(ntype_slug='user_accepted_my_follow_request',
                   sub=follow_request.target,
                   obj=follow_request,
                   recipient=follow_request.follower,
                   url=follow_request.target.get_absolute_url())
        if action == 'decline':
            follow_request.delete()
            return render_to_json({'success': True})
    return render_to_json({'success': False,
                           'message': 'Invalida data'})
Exemple #4
0
def pending_follow_request_action(request):
    if request.method == 'POST':

        frpk = request.POST.get('pk')
        try:
            frpk = int(frpk)
        except ValueError:
            return render_to_json({'errMsg': 'Invalida data'},
                                  HttpResponseBadRequest)

        action = request.POST['action']

        follow_request = get_object_or_404(UserFollow,
                                           pk=frpk,
                                           target=request.user)

        if action == 'accept':
            follow_request.status = UserFollow.FOLLOWING
            follow_request.save()
            follower_count_changed.send(sender=request.user)
            notify(ntype_slug='user_accepted_my_follow_request',
                   sub=follow_request.target,
                   obj=follow_request,
                   recipient=follow_request.follower,
                   url=follow_request.target.get_absolute_url())
            return render_to_json({'success': True})
        elif action == 'accept-restricted':
            follow_request.status = UserFollow.FOLLOWING_RESTRICTED
            follow_request.save()
            follower_count_changed.send(sender=request.user)
            notify(ntype_slug='user_accepted_my_follow_request',
                   sub=follow_request.target,
                   obj=follow_request,
                   recipient=follow_request.follower,
                   url=follow_request.target.get_absolute_url())
        if action == 'decline':
            follow_request.delete()
            return render_to_json({'success': True})
    return render_to_json({'success': False, 'message': 'Invalida data'})