def report(request, id): vandalism = get_object_or_404(Vandalism, id=id) try: report = Report.objects.get(vandalism=vandalism) except Report.DoesNotExist: report = None if request.method == 'POST' and request.user.has_perm( 'cbng_report.can_comment'): form = CommentForm(request.POST) if form.is_valid(): c = Comment() c.vandalism = vandalism c.timestamp = datetime.now c.userid = request.user.id c.comment = form.cleaned_data['comment'] c.save() messages.add_message(request, messages.SUCCESS, 'Added comment') return render( request, 'cbng_report/report.html', { 'vandalism': vandalism, 'report': report, 'comments': Comment.objects.filter(vandalism=vandalism).order_by('-timestamp'), 'form': CommentForm() })
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()})
def report(request, id): vandalism = get_object_or_404(Vandalism, id=id) try: report = Report.objects.get(vandalism=vandalism) except Report.DoesNotExist: report = None if request.method == "POST" and request.user.has_perm("cbng_report.can_comment"): form = CommentForm(request.POST) if form.is_valid(): c = Comment() c.vandalism = vandalism c.timestamp = datetime.now c.userid = request.user.id c.comment = form.cleaned_data["comment"] c.save() messages.add_message(request, messages.SUCCESS, "Added comment") return render( request, "cbng_report/report.html", { "vandalism": vandalism, "report": report, "comments": Comment.objects.filter(vandalism=vandalism).order_by("-timestamp"), "form": CommentForm(), }, )
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()})