def onerror(request): if request.method != 'POST': ret = HttpResponse(content="Sorry, we accept POST only", status=400) else: form = ErrorReportForm(request.POST) if form.is_valid(): report = form.save(commit=False) report.remote_addr = request.META['REMOTE_ADDR'] report.user_agent = request.META['HTTP_USER_AGENT'] report.save() ret = HttpResponse(content='Thanks for reporting', status=201) else: ret = HttpResponse(content=form._errors, status=400) return ret
def report(request, molecule): if request.user.is_authenticated(): email = request.user.email else: email = "" if request.method == "POST": report = ErrorReport(molecule=molecule) form = ErrorReportForm(request.POST, instance=report, initial={"email": email}) if form.is_valid(): form.save() logger.info("'%s' was reported as having an error by %s." % (molecule, email)) return redirect(molecule_detail, molecule) else: form = ErrorReportForm(initial={"email": email}) c = { "form": form, "molecule": molecule } return render(request, "chem/report.html", c)
def report(request, molecule): if request.user.is_authenticated(): email = request.user.email else: email = "" if request.method == "POST": report = ErrorReport(molecule=molecule) form = ErrorReportForm(request.POST, instance=report, initial={"email": email}) if form.is_valid(): form.save() logger.info("'%s' was reported as having an error by %s." % (molecule, email)) return redirect(molecule_detail, molecule) else: form = ErrorReportForm(initial={"email": email}) c = {"form": form, "molecule": molecule} return render(request, "chem/report.html", c)