Ejemplo n.º 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(),
                                       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)
Ejemplo n.º 2
0
 def test_flag_kbforum_post(self):
     u = UserFactory()
     t = ThreadFactory()
     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 = UserFactory()
     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")))
Ejemplo n.º 3
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')))
Ejemplo n.º 4
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')))
Ejemplo n.º 5
0
    def test_flagged_and_deleted_ProfileFactory(self):
        u = UserFactory()
        p = u.profile
        flag_user = UserFactory()
        # 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 = UserFactory()
        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")))
Ejemplo n.º 6
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')))
Ejemplo n.º 7
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')))
Ejemplo n.º 8
0
def _add_to_moderation_queue(request, instance):
    instance.is_spam = True
    instance.save()

    flag = FlaggedObject(
        content_type=ContentType.objects.get_for_model(instance),
        object_id=instance.id,
        reason="spam",
        notes="Automatically flagged at creation and marked as spam.",
        creator=request.user,
    )
    flag.save()

    messages.add_message(
        request,
        messages.WARNING,
        _("A moderator must manually approve your post before it will be visible."),
    )
Ejemplo n.º 9
0
def flag(request, content_type=None, model=None, object_id=None, **kwargs):
    if not content_type:
        if model:
            content_type = ContentType.objects.get_for_model(model).id
        else:
            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)
Ejemplo n.º 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')))