Exemple #1
0
    def post(self, request):
        form = FlagForm(request.POST)

        if not form.is_valid():
            return HttpResponseBadRequest()

        user = None
        if request.user.is_authenticated():
            user = request.user

        utils.flag(form.cleaned_data['object'], user,
                   request.META['REMOTE_ADDR'], form.cleaned_data['comment'])

        if 'next' in request.GET:
            return HttpResponseRedirect(request.GET.get('next'))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
Exemple #2
0
    def post(self, request):
        form = FlagForm(request.POST)

        if not form.is_valid():
            return HttpResponseBadRequest()

        user = None
        if request.user.is_authenticated():
            user = request.user

        utils.flag(form.cleaned_data['object'], user, request.META['REMOTE_ADDR'],
            form.cleaned_data['comment'])

        if 'next' in request.GET:
            return HttpResponseRedirect(request.GET.get('next'))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
Exemple #3
0
    def test_signals(self):
        Handler = type(
            'Handler', (object, ), {
                'inc': lambda self: setattr(self, 'i',
                                            getattr(self, 'i') + 1),
                'i': 0
            })
        flagged_handler = Handler()
        review_handler = Handler()
        rejected_handler = Handler()
        approved_handler = Handler()

        def handle_flagged(sender, flag, created=False, **kwargs):
            if created:
                flagged_handler.inc()

        def handle_review(sender, flag, **kwargs):
            review_handler.inc()

        def handle_rejected(sender, flag, **kwargs):
            rejected_handler.inc()

        def handle_approved(sender, flag, **kwargs):
            approved_handler.inc()

        flagged.connect(handle_flagged)
        review.connect(handle_review)
        rejected.connect(handle_rejected)
        approved.connect(handle_approved)

        utils.flag(self.lennon, user=self.hendrix)

        flag = Flag.objects.all()[0]

        flag.status = REVIEW
        flag.save()
        flag.status = CONTENT_APPROVED
        flag.save()
        flag.status = CONTENT_REJECTED
        flag.save()

        self.assertEqual(1, flagged_handler.i)
        self.assertEqual(1, review_handler.i)
        self.assertEqual(1, rejected_handler.i)
        self.assertEqual(1, approved_handler.i)
Exemple #4
0
    def test_signals(self):
        Handler = type('Handler', (object,), {
            'inc': lambda self: setattr(self, 'i', getattr(self, 'i') + 1),
            'i': 0
        })
        flagged_handler = Handler()
        review_handler = Handler()
        rejected_handler = Handler()
        approved_handler = Handler()
        
        def handle_flagged(sender, flag, created=False, **kwargs):
            if created:
                flagged_handler.inc()
        
        def handle_review(sender, flag, **kwargs):
            review_handler.inc()
            
        def handle_rejected(sender, flag, **kwargs):
            rejected_handler.inc()
        
        def handle_approved(sender, flag, **kwargs):
            approved_handler.inc()
        
        flagged.connect(handle_flagged)
        review.connect(handle_review)
        rejected.connect(handle_rejected)
        approved.connect(handle_approved)

        utils.flag(self.lennon, user=self.hendrix)
        
        flag = Flag.objects.all()[0]
        
        flag.status = REVIEW
        flag.save()
        flag.status = CONTENT_APPROVED
        flag.save()
        flag.status = CONTENT_REJECTED
        flag.save()
        
        self.assertEqual(1, flagged_handler.i)
        self.assertEqual(1, review_handler.i)
        self.assertEqual(1, rejected_handler.i)
        self.assertEqual(1, approved_handler.i)