get form errors to get passed correctly
This commit is contained in:
parent
b48887e449
commit
5c4c3c745a
|
@ -20,11 +20,15 @@ def itf_inlineformset_factory(model, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
class ItfForm(forms.ModelForm):
|
class ItfForm(forms.ModelForm):
|
||||||
|
'''
|
||||||
|
All Itf Forms inherit from this
|
||||||
|
'''
|
||||||
inlines = []
|
inlines = []
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
self.helper.form_tag = False
|
self.helper.form_tag = False
|
||||||
|
self.helper.form_show_errors = True
|
||||||
super(ItfForm, self).__init__(*args, **kwargs)
|
super(ItfForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ def add_object(request, module_slug, tab_slug):
|
||||||
form = model_class.get_forms()[add_form_name]
|
form = model_class.get_forms()[add_form_name]
|
||||||
if request.POST:
|
if request.POST:
|
||||||
f = form(request.POST, request.FILES)
|
f = form(request.POST, request.FILES)
|
||||||
|
#import pdb
|
||||||
|
#pdb.set_trace()
|
||||||
if f.is_valid():
|
if f.is_valid():
|
||||||
instance = f.save(commit=False)
|
instance = f.save(commit=False)
|
||||||
if instance.__dict__.has_key('added_by_id'):
|
if instance.__dict__.has_key('added_by_id'):
|
||||||
|
@ -27,16 +28,21 @@ def add_object(request, module_slug, tab_slug):
|
||||||
else:
|
else:
|
||||||
all_valid = False
|
all_valid = False
|
||||||
if all_valid:
|
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:
|
else:
|
||||||
inlines = [inline() for inline in f.inlines]
|
inlines = [inline() for inline in f.inlines]
|
||||||
else:
|
else:
|
||||||
f = form()
|
f = form()
|
||||||
inlines = [inline() for inline in f.inlines]
|
inlines = [inline() for inline in f.inlines]
|
||||||
|
|
||||||
|
# import pdb
|
||||||
|
# pdb.set_trace()
|
||||||
context = RequestContext(request, {
|
context = RequestContext(request, {
|
||||||
'form': f,
|
'form': f,
|
||||||
'inlines': inlines
|
'inlines': inlines,
|
||||||
|
'errors': f.errors
|
||||||
})
|
})
|
||||||
return render_to_response("test/person_form.html", context)
|
return render_to_response("test/person_form.html", context)
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ class PadmaClipForm(ItfForm):
|
||||||
PadmaClipsInline = itf_inlineformset_factory(PadmaClip, extra=1, is_generic=True, form=PadmaClipForm, title="Videos")
|
PadmaClipsInline = itf_inlineformset_factory(PadmaClip, extra=1, is_generic=True, form=PadmaClipForm, title="Videos")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Popup Form Classes:
|
#Popup Form Classes:
|
||||||
class PopupPersonForm(PopupForm):
|
class PopupPersonForm(PopupForm):
|
||||||
|
|
||||||
|
|
|
@ -164,13 +164,18 @@ $(function(){
|
||||||
<div id="shadow">
|
<div id="shadow">
|
||||||
</div>
|
</div>
|
||||||
<div id="searchContainer">
|
<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">
|
<form id="formItf" action="" class="uniForm" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div>
|
<div>
|
||||||
<!-- <input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" /> -->
|
<!-- <input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" /> -->
|
||||||
</div>
|
</div>
|
||||||
{{ form|crispy }}
|
{% crispy form form.helper %}
|
||||||
|
|
||||||
{% for inline in inlines %}
|
{% for inline in inlines %}
|
||||||
<h3> {{inline.title }} </h3>
|
<h3> {{inline.title }} </h3>
|
||||||
{% if inline.help_text %}
|
{% if inline.help_text %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user