Commit 0332e33d authored by Okhin's avatar Okhin
Browse files

Fixing the form display after error

parent 170181cf
......@@ -2,7 +2,7 @@ from forms import AddViolation, SearchViolation
from django.views.generic import ListView, FormView, DetailView
from django.views.generic.list import MultipleObjectMixin
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.shortcuts import render_to_response, get_object_or_404, redirect, render
from django.template import RequestContext, loader, Context
from django.core.files import File
from django.core.servers.basehttp import FileWrapper
......@@ -192,6 +192,15 @@ class AddForm(FormView):
messages.add_message(self.request, messages.INFO, _('Thank you for submitting this report, you will receive a verification email immediately, if not check your spam folder.'))
return super(AddForm, self).form_valid(form)
def post(self, request, *args, **kwargs):
# We needto do special work with the form view
form = self.form_class(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect(self.success_url)
else:
return render(request, self.template_name, {'form': form})
def get_context_data(self, **kwargs):
context = super(AddForm, self).get_context_data(**kwargs)
reports = sorted([(i['total'],i['id'])
......
......@@ -22,6 +22,13 @@ $('.metoo').submit(function(event) {
}
});
});
{% if form.errors %}
console.log("Form state: {{ form.valid }}");
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
{% else %}
console.log("Form state: {{ form.valid }}");
$("#lookup_btn").click(function(event) {
event.preventDefault();
$.ajax({
......@@ -74,6 +81,7 @@ $("#lookup_btn").click(function(event) {
}
});
});
{% endif %}
$("#btn_dismiss").click(function(event) {
event.preventDefault();
......@@ -81,6 +89,7 @@ $("#btn_dismiss").click(function(event) {
$("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show');
});
</script>
{% endblock %}
......@@ -158,14 +167,15 @@ $("#btn_dismiss").click(function(event) {
<h2>{% trans "Add New Case" %}</h2>
</div>
<div class="panel-body">
{% if forms.error %}
{% for field in form %}
{% for error in field.error %}
<div class="alert alert-error">
{{ error|escape }}
{% if form.errors %}
{% for error, message in form.errors.items %}
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-label="close">
<span aria-hidden="true">&times;</span>
</button>
<strong>{{ error }}</strong>: {{ message|striptags }}
</div>
{% endfor %}
{% endfor %}
{% endif %}
<p>{% trans "Please report cases of zero-rating (services which are excluded from your download limit), specialised services or the blocking, throttling or prioritisation of online services. For a more detailed description of what to report, check our <a href='/about/#guidelines'>guidelines</a>." %}
<form name="addForm" enctype="multipart/form-data" action="/" method="post" class="form">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment