From 32862dbde2f4069e9daebacc74848cf1ca692f01 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 8 Dec 2014 12:21:13 +0100 Subject: [PATCH] [TASK] Correctly render the forms/formsets within ONE form tag. --- frontend/forms.py | 20 +++++++------------- frontend/formsets.py | 13 +++++-------- frontend/templates/hello.html | 30 +++++++++++++++++++++++++----- frontend/views.py | 12 +++--------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index cb23e8b..ee0761e 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -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() diff --git a/frontend/formsets.py b/frontend/formsets.py index 1124ab7..eaf793c 100644 --- a/frontend/formsets.py +++ b/frontend/formsets.py @@ -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 +) \ No newline at end of file diff --git a/frontend/templates/hello.html b/frontend/templates/hello.html index ce06c09..841d1ec 100644 --- a/frontend/templates/hello.html +++ b/frontend/templates/hello.html @@ -3,10 +3,30 @@ {% load crispy_forms_tags %} {% endblock %} {% block content %} - hallo
- zurück -

{% crispy presentation_form %}

-

{% crispy person_formset %}

-

{% crispy event_formset %}

+ zurück
+

Vortrag anlegen

+
+ {% crispy presentation_form %} +

Personen

+

+ {% for form in person_formset.forms %} +

+ {% crispy form person_form.helper %} +
+ {% endfor %} + [+]
+ +

+

Veranstaltungen

+

+ {% for form in event_formset.forms %} +

+ {% crispy form event_form.helper %} +
+ {% endfor %} + [+]
+

+ +
{% endblock %} \ No newline at end of file diff --git a/frontend/views.py b/frontend/views.py index d613e2b..b94227e 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -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)