From 5c4c3c745a79c62fa58ba77f26c8e1984551e400 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 10 Jan 2008 04:23:54 +0530 Subject: [PATCH] get form errors to get passed correctly --- itf/app/forms.py | 4 ++++ itf/insidepages/views.py | 12 +++++++++--- itf/itfprofiles/forms.py | 2 ++ itf/templates/test/person_form.html | 9 +++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/itf/app/forms.py b/itf/app/forms.py index db9c620..76767d3 100644 --- a/itf/app/forms.py +++ b/itf/app/forms.py @@ -20,11 +20,15 @@ def itf_inlineformset_factory(model, *args, **kwargs): class ItfForm(forms.ModelForm): + ''' + All Itf Forms inherit from this + ''' inlines = [] def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_tag = False + self.helper.form_show_errors = True super(ItfForm, self).__init__(*args, **kwargs) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 3480687..f939992 100755 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -13,7 +13,8 @@ def add_object(request, module_slug, tab_slug): form = model_class.get_forms()[add_form_name] if request.POST: f = form(request.POST, request.FILES) - + #import pdb + #pdb.set_trace() if f.is_valid(): instance = f.save(commit=False) if instance.__dict__.has_key('added_by_id'): @@ -27,16 +28,21 @@ def add_object(request, module_slug, tab_slug): else: all_valid = False if all_valid: - return HttpResponseRedirect(instance.get_absolute_url()) #TODO: get the saved object and redirect to .get_absolute_url() + return HttpResponseRedirect(instance.get_absolute_url()) +# else: +# inlines = [inline(instance=instance) for inline in f.inlines] else: inlines = [inline() for inline in f.inlines] else: f = form() inlines = [inline() for inline in f.inlines] +# import pdb +# pdb.set_trace() context = RequestContext(request, { 'form': f, - 'inlines': inlines + 'inlines': inlines, + 'errors': f.errors }) return render_to_response("test/person_form.html", context) diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index a6f1c63..2722f66 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -46,6 +46,8 @@ class PadmaClipForm(ItfForm): PadmaClipsInline = itf_inlineformset_factory(PadmaClip, extra=1, is_generic=True, form=PadmaClipForm, title="Videos") + + #Popup Form Classes: class PopupPersonForm(PopupForm): diff --git a/itf/templates/test/person_form.html b/itf/templates/test/person_form.html index 8e3a234..1139532 100644 --- a/itf/templates/test/person_form.html +++ b/itf/templates/test/person_form.html @@ -164,13 +164,18 @@ $(function(){
+ {% if form.errors %} +
+ Please correct the errors below and re-submit. +
+ {% endif %}
{% csrf_token %}
- {{ form|crispy }} - + {% crispy form form.helper %} + {% for inline in inlines %}

{{inline.title }}

{% if inline.help_text %}