get form errors to get passed correctly

This commit is contained in:
Sanj 2008-01-10 04:23:54 +05:30
parent b48887e449
commit 5c4c3c745a
4 changed files with 22 additions and 5 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -164,13 +164,18 @@ $(function(){
<div id="shadow">
</div>
<div id="searchContainer">
{% if form.errors %}
<div class="topFormErrors">
Please correct the errors below and re-submit.
</div>
{% endif %}
<form id="formItf" action="" class="uniForm" method="POST">
{% csrf_token %}
<div>
<!-- <input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" /> -->
</div>
{{ form|crispy }}
{% crispy form form.helper %}
{% for inline in inlines %}
<h3> {{inline.title }} </h3>
{% if inline.help_text %}