Example #1
0
def flag(request, content_type=None, object_id=None, **kwargs):
    if not content_type:
        content_type = request.POST.get('content_type')
    if not object_id:
        object_id = int(request.POST.get('object_id'))
    reason = request.POST.get('reason')
    notes = request.POST.get('other', '')
    next = request.POST.get('next')

    content_type = get_object_or_404(ContentType, id=int(content_type))
    object_id = int(object_id)
    content_object = get_object_or_404(content_type.model_class(),
                                       id=object_id)

    # Check that this user hasn't already flagged the object
    try:
        FlaggedObject.objects.get(content_type=content_type,
                                  object_id=object_id,
                                  creator=request.user)
        msg = _('You already flagged this content.')
    except FlaggedObject.DoesNotExist:
        flag = FlaggedObject(content_object=content_object,
                             reason=reason,
                             creator=request.user,
                             notes=notes)
        flag.save()
        msg = _('You have flagged this content. A moderator will review ' +
                'your submission shortly.')

    if request.is_ajax():
        return HttpResponse(json.dumps({'message': msg}))
    elif next:
        return HttpResponseRedirect(next)

    return HttpResponse(msg)
Example #2
0
def flag(request, content_type=None, object_id=None, **kwargs):
    if not content_type:
        content_type = request.POST.get('content_type')
    if not object_id:
        object_id = int(request.POST.get('object_id'))
    reason = request.POST.get('reason')
    notes = request.POST.get('other', '')
    next = request.POST.get('next')

    content_type = get_object_or_404(ContentType, id=int(content_type))
    object_id = int(object_id)
    content_object = get_object_or_404(content_type.model_class(),
                                       pk=object_id)

    # Check that this user hasn't already flagged the object
    try:
        FlaggedObject.objects.get(content_type=content_type,
                                  object_id=object_id, creator=request.user)
        msg = _('You already flagged this content.')
    except FlaggedObject.DoesNotExist:
        flag = FlaggedObject(content_object=content_object, reason=reason,
                             creator=request.user, notes=notes)
        flag.save()
        msg = _('You have flagged this content. A moderator will review ' +
                'your submission shortly.')

    if request.is_ajax():
        return HttpResponse(json.dumps({'message': msg}))
    elif next:
        messages.add_message(request, messages.INFO, msg)
        return HttpResponseRedirect(next)

    return HttpResponse(msg)
Example #3
0
 def test_flag_kbforum_post(self):
     p = Post.objects.all()[0]
     f = FlaggedObject(content_object=p, reason='spam', creator_id=118577)
     f.save()
     # Make sure flagit queue page works
     u = user(save=True)
     add_permission(u, FlaggedObject, 'can_moderate')
     self.client.login(username=u.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
Example #4
0
 def test_flag_kbforum_post(self):
     p = Post.objects.all()[0]
     f = FlaggedObject(content_object=p, reason='spam', creator_id=118577)
     f.save()
     # Make sure flagit queue page works
     u = user(save=True)
     add_permission(u, FlaggedObject, 'can_moderate')
     self.client.login(username=u.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
Example #5
0
 def test_flag_kbforum_post(self):
     u = user(save=True)
     t = thread(save=True)
     p = t.new_post(creator=u, content='foo')
     f = FlaggedObject(content_object=p, reason='spam', creator_id=u.id)
     f.save()
     # Make sure flagit queue page works
     u2 = user(save=True)
     add_permission(u2, FlaggedObject, 'can_moderate')
     self.client.login(username=u2.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
Example #6
0
    def test_flagged_and_deleted_profile(self):
        # Flag a profile and delete it
        p = User.objects.get(id=47963).get_profile()
        f = FlaggedObject(content_object=p, reason='spam', creator_id=118577)
        f.save()
        p.delete()

        # Verify flagit queue
        u = user(save=True)
        add_permission(u, FlaggedObject, 'can_moderate')
        self.client.login(username=u.username, password='******')
        response = get(self.client, 'flagit.queue')
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(1, len(doc('#flagged-queue form.update')))
Example #7
0
    def test_flagged_and_deleted_profile(self):
        # Flag a profile and delete it
        p = User.objects.get(id=47963).get_profile()
        f = FlaggedObject(content_object=p, reason='spam', creator_id=118577)
        f.save()
        p.delete()

        # Verify flagit queue
        u = user(save=True)
        add_permission(u, FlaggedObject, 'can_moderate')
        self.client.login(username=u.username, password='******')
        response = get(self.client, 'flagit.queue')
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(1, len(doc('#flagged-queue form.update')))
Example #8
0
    def test_flagged_and_deleted_profile(self):
        u = user(save=True)
        p = profile(user=u)
        flag_user = user(save=True)
        # Flag a profile and delete it
        f = FlaggedObject(content_object=p, reason="spam", creator_id=flag_user.id)
        f.save()
        p.delete()

        # Verify flagit queue
        u = user(save=True)
        add_permission(u, FlaggedObject, "can_moderate")
        self.client.login(username=u.username, password="******")
        response = get(self.client, "flagit.queue")
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(1, len(doc("#flagged-queue form.update")))
Example #9
0
    def test_queue(self):
        # Flag all answers
        num_answers = Answer.objects.count()
        for a in Answer.objects.all():
            f = FlaggedObject(content_object=a, reason='spam',
                                 creator_id=118577)
            f.save()

        # Verify number of flagged objects
        response = get(self.client, 'flagit.queue')
        doc = pq(response.content)
        eq_(num_answers, len(doc('#flagged-queue li')))

        # Reject one flag
        flag = FlaggedObject.objects.all()[0]
        response = post(self.client, 'flagit.update',
                        {'status': 2},
                        args=[flag.id])
        doc = pq(response.content)
        eq_(num_answers - 1, len(doc('#flagged-queue li')))
Example #10
0
    def test_queue(self):
        # Flag all answers
        num_answers = Answer.objects.count()
        for a in Answer.objects.all():
            f = FlaggedObject(content_object=a,
                              reason='spam',
                              creator_id=self.flagger.id)
            f.save()

        # Verify number of flagged objects
        response = get(self.client, 'flagit.queue')
        doc = pq(response.content)
        eq_(num_answers, len(doc('#flagged-queue li')))

        # Reject one flag
        flag = FlaggedObject.objects.all()[0]
        response = post(self.client,
                        'flagit.update', {'status': 2},
                        args=[flag.id])
        doc = pq(response.content)
        eq_(num_answers - 1, len(doc('#flagged-queue li')))