Ejemplo n.º 1
0
def home(request):
    if request.method == 'POST':
        form = ReportForm(request.POST)
        if form.is_valid():
            id = form.cleaned_data['id']
            comment = form.cleaned_data['comment']
            try:
                v = Vandalism.objects.get(id=id)
            except Vandalism.DoesNotExist:
                messages.add_message(request, messages.ERROR,
                                     'Could not find revert ID %d' % id)
            else:
                if not v.reverted:
                    messages.add_message(
                        request, messages.ERROR,
                        'Edit with revert ID %d was NOT reverted!' % id)
                else:
                    try:
                        r = Report.objects.get(vandalism=v)
                    except Report.DoesNotExist:
                        r = Report(vandalism=v,
                                   timestamp=datetime.now,
                                   status=0)

                        if request.user.is_authenticated():
                            r.reporterid = request.user.id
                            r.reporter = request.user.username
                        else:
                            r.reporterid = -1
                            r.reporter = 'Anonymous'

                        r.save()

                    if comment:
                        c = Comment()
                        c.vandalism = v
                        c.timestamp = datetime.now
                        if request.user.is_authenticated():
                            c.userid = request.user.id
                        else:
                            c.userid = -1
                        c.comment = comment
                        c.save()

                    send_msg_to_relay(
                        ('[[report:%(id)d]] comment ',
                         'http://tools.wmflabs.org/cluebotng/report/%(id)d',
                         '* %(user)s * New Report' % {
                             'id': r.id,
                             'user': request.user.username,
                         }))

                    return redirect('/report/%d' % r.revertid.id)

    return render(request, 'cbng_report/home.html', {'form': ReportForm()})
Ejemplo n.º 2
0
def report_status_change(request, revert_id, status_id):
    '''
    Crappy json 'API' for scoring a report.

    TODO - add 'redirect on score' functionality
    :param request:
    :param revert_id:
    :param status_id:
    :return:
    '''
    valid_statues = [x[0] for x in Report.STATUSES]
    if int(status_id) not in valid_statues:
        logger.error('Invalid status %s requested for %s by %s' %
                     (status_id, revert_id, request.user.username))
        return HttpResponse(json.dumps({'status': 'ERROR'}))

    try:
        v = Vandalism.objects.get(id=revert_id)
        r = Report.objects.get(vandalism=v)
        r.status = int(status_id)
        r.save()
    except Exception as e:
        logger.error('Failed to save status %d on %d' % (status_id, revert_id),
                     e)
    else:

        try:
            comment = '%s has marked this report as "%s".' % (
                request.user.username, r.get_status_display())
            Comment.objects.create(vandalism=v,
                                   timestamp=datetime.now(),
                                   user=request.user,
                                   comment=comment)

            send_msg_to_relay(
                ('[[report:%(id)d]] comment ',
                 'http://tools.wmflabs.org/cluebotng/report/%(id)d',
                 '* %(user)s * %(comment)s' % {
                     'id': r.id,
                     'user': request.user.username,
                     'comment': comment
                 }))
        except Exception as e:
            logger.error('Failed to save comment for change on %s' % revert_id,
                         e)

        return HttpResponse(
            json.dumps({
                'status': 'OK',
                'report_status': r.get_status_display(),
                'next': get_next_report(request.user)
            }))

    return HttpResponse(json.dumps({'status': 'ERROR'}))
Ejemplo n.º 3
0
def home(request):
    if request.method == "POST":
        form = ReportForm(request.POST)
        if form.is_valid():
            id = form.cleaned_data["id"]
            comment = form.cleaned_data["comment"]
            try:
                v = Vandalism.objects.get(id=id)
            except Vandalism.DoesNotExist:
                messages.add_message(request, messages.ERROR, "Could not find revert ID %d" % id)
            else:
                if not v.reverted:
                    messages.add_message(request, messages.ERROR, "Edit with revert ID %d was NOT reverted!" % id)
                else:
                    try:
                        r = Report.objects.get(vandalism=v)
                    except Report.DoesNotExist:
                        r = Report(vandalism=v, timestamp=datetime.now, status=0)

                        if request.user.is_authenticated():
                            r.reporterid = request.user.id
                            r.reporter = request.user.username
                        else:
                            r.reporterid = -1
                            r.reporter = "Anonymous"

                        r.save()

                    if comment:
                        c = Comment()
                        c.vandalism = v
                        c.timestamp = datetime.now
                        if request.user.is_authenticated():
                            c.userid = request.user.id
                        else:
                            c.userid = -1
                        c.comment = comment
                        c.save()

                    send_msg_to_relay(
                        (
                            "[[report:%(id)d]] comment ",
                            "http://tools.wmflabs.org/cluebotng/report/%(id)d",
                            "* %(user)s * New Report" % {"id": r.id, "user": request.user.username},
                        )
                    )

                    return redirect("/report/%d" % r.revertid.id)

    return render(request, "cbng_report/home.html", {"form": ReportForm()})
Ejemplo n.º 4
0
def report_status_change(request, revert_id, status_id):
    """
    Crappy json 'API' for scoring a report.

    TODO - add 'redirect on score' functionality
    :param request:
    :param revert_id:
    :param status_id:
    :return:
    """
    valid_statues = [x[0] for x in Report.STATUSES]
    if int(status_id) not in valid_statues:
        logger.error("Invalid status %s requested for %s by %s" % (status_id, revert_id, request.user.username))
        return HttpResponse(json.dumps({"status": "ERROR"}))

    try:
        v = Vandalism.objects.get(id=revert_id)
        r = Report.objects.get(vandalism=v)
        r.status = int(status_id)
        r.save()
    except Exception as e:
        logger.error("Failed to save status %d on %d" % (status_id, revert_id), e)
    else:

        try:
            comment = '%s has marked this report as "%s".' % (request.user.username, r.get_status_display())
            Comment.objects.create(vandalism=v, timestamp=datetime.now(), user=request.user, comment=comment)

            send_msg_to_relay(
                (
                    "[[report:%(id)d]] comment ",
                    "http://tools.wmflabs.org/cluebotng/report/%(id)d",
                    "* %(user)s * %(comment)s" % {"id": r.id, "user": request.user.username, "comment": comment},
                )
            )
        except Exception as e:
            logger.error("Failed to save comment for change on %s" % revert_id, e)

        return HttpResponse(
            json.dumps({"status": "OK", "report_status": r.get_status_display(), "next": get_next_report(request.user)})
        )

    return HttpResponse(json.dumps({"status": "ERROR"}))