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 ...@@ -2,7 +2,7 @@ from forms import AddViolation, SearchViolation
from django.views.generic import ListView, FormView, DetailView from django.views.generic import ListView, FormView, DetailView
from django.views.generic.list import MultipleObjectMixin from django.views.generic.list import MultipleObjectMixin
from django.http import HttpResponse, HttpResponseRedirect, Http404 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.template import RequestContext, loader, Context
from django.core.files import File from django.core.files import File
from django.core.servers.basehttp import FileWrapper from django.core.servers.basehttp import FileWrapper
...@@ -192,6 +192,15 @@ class AddForm(FormView): ...@@ -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.')) 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) 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): def get_context_data(self, **kwargs):
context = super(AddForm, self).get_context_data(**kwargs) context = super(AddForm, self).get_context_data(**kwargs)
reports = sorted([(i['total'],i['id']) reports = sorted([(i['total'],i['id'])
......
...@@ -22,6 +22,13 @@ $('.metoo').submit(function(event) { ...@@ -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) { $("#lookup_btn").click(function(event) {
event.preventDefault(); event.preventDefault();
$.ajax({ $.ajax({
...@@ -74,6 +81,7 @@ $("#lookup_btn").click(function(event) { ...@@ -74,6 +81,7 @@ $("#lookup_btn").click(function(event) {
} }
}); });
}); });
{% endif %}
$("#btn_dismiss").click(function(event) { $("#btn_dismiss").click(function(event) {
event.preventDefault(); event.preventDefault();
...@@ -81,6 +89,7 @@ $("#btn_dismiss").click(function(event) { ...@@ -81,6 +89,7 @@ $("#btn_dismiss").click(function(event) {
$("#lookup_btn").parent().parent().hide(); $("#lookup_btn").parent().parent().hide();
$("#collapseField").collapse('show'); $("#collapseField").collapse('show');
}); });
</script> </script>
{% endblock %} {% endblock %}
...@@ -158,14 +167,15 @@ $("#btn_dismiss").click(function(event) { ...@@ -158,14 +167,15 @@ $("#btn_dismiss").click(function(event) {
<h2>{% trans "Add New Case" %}</h2> <h2>{% trans "Add New Case" %}</h2>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if forms.error %} {% if form.errors %}
{% for field in form %} {% for error, message in form.errors.items %}
{% for error in field.error %} <div class="alert alert-danger">
<div class="alert alert-error"> <button type="button" class="close" data-dismiss="alert" aria-label="close">
{{ error|escape }} <span aria-hidden="true">&times;</span>
</button>
<strong>{{ error }}</strong>: {{ message|striptags }}
</div> </div>
{% endfor %} {% endfor %}
{% endfor %}
{% endif %} {% 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>." %} <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"> <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