[TASK] Correctly render the forms/formsets within ONE form tag.
This commit is contained in:
parent
a374ba960a
commit
32862dbde2
|
@ -87,16 +87,14 @@ class PresentationPersonForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PresentationPersonForm, self).__init__(*args, **kwargs)
|
super(PresentationPersonForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
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.label_class = u'col-lg-2'
|
||||||
self.helper.field_class = u'col-lg-4'
|
self.helper.field_class = u'col-lg-4'
|
||||||
self.helper.form_method = u'post'
|
|
||||||
self.helper.layout = Layout(
|
self.helper.layout = Layout(
|
||||||
u'given_name',
|
u'given_name',
|
||||||
u'additional_name',
|
u'additional_name',
|
||||||
u'family_name',
|
u'family_name',
|
||||||
u'hshmembership',
|
u'hshmembership'
|
||||||
Submit(u'send', u'Create', css_class=u'btn-default')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
given_name = forms.CharField(
|
given_name = forms.CharField(
|
||||||
|
@ -134,20 +132,18 @@ class PresentationPersonForm(forms.ModelForm):
|
||||||
class PresentationEventForm(forms.ModelForm):
|
class PresentationEventForm(forms.ModelForm):
|
||||||
""" Form for the PresentationEventModel"""
|
""" Form for the PresentationEventModel"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PresentationPersonForm, self).__init__(*args, **kwargs)
|
super(PresentationEventForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
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.label_class = u'col-lg-2'
|
||||||
self.helper.field_class = u'col-lg-4'
|
self.helper.field_class = u'col-lg-4'
|
||||||
self.helper.form_method = u'post'
|
|
||||||
self.helper.layout = Layout(
|
self.helper.layout = Layout(
|
||||||
u'date',
|
u'date',
|
||||||
u'name',
|
u'name',
|
||||||
u'workshop',
|
u'workshop',
|
||||||
u'place',
|
u'place',
|
||||||
u'start_date',
|
u'start_date',
|
||||||
u'end_date',
|
u'end_date'
|
||||||
Submit(u'send', u'Create', css_class=u'btn-default')
|
|
||||||
)
|
)
|
||||||
date = forms.DateField(
|
date = forms.DateField(
|
||||||
label=u"Datum",
|
label=u"Datum",
|
||||||
|
@ -184,15 +180,13 @@ class PresentationForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PresentationForm, self).__init__(*args, **kwargs)
|
super(PresentationForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
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.label_class = u'col-lg-2'
|
||||||
self.helper.field_class = u'col-lg-4'
|
self.helper.field_class = u'col-lg-4'
|
||||||
self.helper.form_method = u'post'
|
|
||||||
self.helper.layout = Layout(
|
self.helper.layout = Layout(
|
||||||
u'title',
|
u'title',
|
||||||
u'type',
|
u'type',
|
||||||
u'abstract',
|
u'abstract'
|
||||||
Submit(u'send', u'Abschicken', css_class=u'btn-default')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
title = forms.CharField()
|
title = forms.CharField()
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
from fancy_formsets.forms import FancyBaseInlineFormSet
|
|
||||||
|
|
||||||
|
|
||||||
from frontend.models import Presentation, PresentationEvent, PresentationPerson
|
from frontend.models import Presentation, PresentationEvent, PresentationPerson
|
||||||
from django.forms.models import inlineformset_factory
|
from django.forms.models import inlineformset_factory
|
||||||
|
|
||||||
PresentationPersonInlineFormset = inlineformset_factory(
|
PresentationPersonInlineFormset = inlineformset_factory(
|
||||||
Presentation,
|
Presentation,
|
||||||
PresentationPerson,
|
PresentationPerson,
|
||||||
formset=FancyBaseInlineFormSet,
|
extra=1,
|
||||||
extra=1
|
can_delete=False
|
||||||
)
|
)
|
||||||
|
|
||||||
PresentationEventInlineFormset = inlineformset_factory(
|
PresentationEventInlineFormset = inlineformset_factory(
|
||||||
Presentation,
|
Presentation,
|
||||||
PresentationEvent,
|
PresentationEvent,
|
||||||
formset=FancyBaseInlineFormSet,
|
extra=1,
|
||||||
extra=1
|
can_delete=False
|
||||||
)
|
)
|
|
@ -3,10 +3,30 @@
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
hallo <br>
|
<a href="{% url 'frontend-index' %}">zurück</a><br>
|
||||||
<a href="{% url 'frontend-index' %}">zurück</a>
|
|
||||||
<p>{% crispy presentation_form %}</p>
|
|
||||||
<p>{% crispy person_formset %}</p>
|
|
||||||
<p>{% crispy event_formset %}</p>
|
|
||||||
|
|
||||||
|
<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 %}
|
{% endblock %}
|
|
@ -111,16 +111,8 @@ class IndexView(ProtectedTemplateView):
|
||||||
template_name = u'index.html'
|
template_name = u'index.html'
|
||||||
page_title = u'Index'
|
page_title = u'Index'
|
||||||
|
|
||||||
# TODO: Make this work!
|
|
||||||
"""
|
|
||||||
class PresentationPersonInline(InlineFormSet):
|
|
||||||
model = PresentationPerson
|
|
||||||
|
|
||||||
class PresentationEventInline(InlineFormSet):
|
class HelloView(ProtectedTemplateView):
|
||||||
model = PresentationEvent
|
|
||||||
"""
|
|
||||||
|
|
||||||
class HelloView(ProtectedFormSetView):
|
|
||||||
template_name = u'hello.html'
|
template_name = u'hello.html'
|
||||||
page_title = u'Hello'
|
page_title = u'Hello'
|
||||||
success_url = u'/hello'
|
success_url = u'/hello'
|
||||||
|
@ -133,6 +125,8 @@ class HelloView(ProtectedFormSetView):
|
||||||
kwargs[u'presentation_form'] = PresentationForm();
|
kwargs[u'presentation_form'] = PresentationForm();
|
||||||
kwargs[u'person_formset'] = PresentationPersonInlineFormset(prefix='person');
|
kwargs[u'person_formset'] = PresentationPersonInlineFormset(prefix='person');
|
||||||
kwargs[u'event_formset'] = PresentationEventInlineFormset(prefix='event');
|
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)
|
return super(HelloView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue