[TASK] Correctly render the forms/formsets within ONE form tag.

This commit is contained in:
Jan Philipp Timme 2014-12-08 12:21:13 +01:00
parent a374ba960a
commit 32862dbde2
4 changed files with 40 additions and 35 deletions

View File

@ -87,16 +87,14 @@ class PresentationPersonForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PresentationPersonForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = u'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.form_method = u'post'
self.helper.layout = Layout(
u'given_name',
u'additional_name',
u'family_name',
u'hshmembership',
Submit(u'send', u'Create', css_class=u'btn-default')
u'hshmembership'
)
given_name = forms.CharField(
@ -134,20 +132,18 @@ class PresentationPersonForm(forms.ModelForm):
class PresentationEventForm(forms.ModelForm):
""" Form for the PresentationEventModel"""
def __init__(self, *args, **kwargs):
super(PresentationPersonForm, self).__init__(*args, **kwargs)
super(PresentationEventForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = u'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.form_method = u'post'
self.helper.layout = Layout(
u'date',
u'name',
u'workshop',
u'place',
u'start_date',
u'end_date',
Submit(u'send', u'Create', css_class=u'btn-default')
u'end_date'
)
date = forms.DateField(
label=u"Datum",
@ -184,15 +180,13 @@ class PresentationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PresentationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = u'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.form_method = u'post'
self.helper.layout = Layout(
u'title',
u'type',
u'abstract',
Submit(u'send', u'Abschicken', css_class=u'btn-default')
u'abstract'
)
title = forms.CharField()

View File

@ -1,19 +1,16 @@
from fancy_formsets.forms import FancyBaseInlineFormSet
from frontend.models import Presentation, PresentationEvent, PresentationPerson
from django.forms.models import inlineformset_factory
PresentationPersonInlineFormset = inlineformset_factory(
Presentation,
PresentationPerson,
formset=FancyBaseInlineFormSet,
extra=1
extra=1,
can_delete=False
)
PresentationEventInlineFormset = inlineformset_factory(
Presentation,
PresentationEvent,
formset=FancyBaseInlineFormSet,
extra=1
)
extra=1,
can_delete=False
)

View File

@ -3,10 +3,30 @@
{% load crispy_forms_tags %}
{% endblock %}
{% block content %}
hallo <br>
<a href="{% url 'frontend-index' %}">zurück</a>
<p>{% crispy presentation_form %}</p>
<p>{% crispy person_formset %}</p>
<p>{% crispy event_formset %}</p>
<a href="{% url 'frontend-index' %}">zurück</a><br>
<h2>Vortrag anlegen</h2>
<form method="POST" action="" class="form-horizontal" id="presentationform">
{% crispy presentation_form %}
<h3>Personen</h3>
<p id="presentationpersonformset">
{% for form in person_formset.forms %}
<div class="person_form">
{% crispy form person_form.helper %}
</div>
{% endfor %}
[+]<br>
</p>
<h3>Veranstaltungen</h3>
<p id="presentationeventformset">
{% for form in event_formset.forms %}
<div class="event_form">
{% crispy form event_form.helper %}
</div>
{% endfor %}
[+]<br>
</p>
<input type="submit" class="btn btn-primary btn-default" value="Submit">
</form>
{% endblock %}

View File

@ -111,16 +111,8 @@ class IndexView(ProtectedTemplateView):
template_name = u'index.html'
page_title = u'Index'
# TODO: Make this work!
"""
class PresentationPersonInline(InlineFormSet):
model = PresentationPerson
class PresentationEventInline(InlineFormSet):
model = PresentationEvent
"""
class HelloView(ProtectedFormSetView):
class HelloView(ProtectedTemplateView):
template_name = u'hello.html'
page_title = u'Hello'
success_url = u'/hello'
@ -133,6 +125,8 @@ class HelloView(ProtectedFormSetView):
kwargs[u'presentation_form'] = PresentationForm();
kwargs[u'person_formset'] = PresentationPersonInlineFormset(prefix='person');
kwargs[u'event_formset'] = PresentationEventInlineFormset(prefix='event');
kwargs[u'person_form'] = PresentationPersonForm();
kwargs[u'event_form'] = PresentationEventForm();
return super(HelloView, self).get_context_data(**kwargs)