[TASK] Use the form param in the inline_formsetfactory... :|

This commit is contained in:
Jan Philipp Timme 2014-12-15 09:27:21 +01:00
parent 8d66c77a1b
commit eadfd5d167
4 changed files with 86 additions and 83 deletions

View File

@ -47,11 +47,10 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'pipeline',
'crispy_forms',
'fancy_formsets',
'bootstrap3_datetime',
'django_bootstrap_breadcrumbs',
'frontend',
'debug_toolbar'
# 'debug_toolbar'
)
MIDDLEWARE_CLASSES = (

View File

@ -4,6 +4,7 @@ from django import forms
from frontend.models import Project, PersonGlobalIdentity, PresentationPerson, Presentation, PresentationEvent, PresentationSubmission
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
from bootstrap3_datetime.widgets import DateTimePicker
class NewProjectForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
@ -93,40 +94,41 @@ PresentationPersonFormHelper.layout = Layout(
u'hshmembership'
)
# class PresentationPersonForm(forms.ModelForm):
# """ Modelform for PresentationPerson """
# def __init__(self, *args, **kwargs):
# super(PresentationPersonForm, self).__init__(*args, **kwargs)
# self.helper = PresentationPersonFormHelper
#
# given_name = forms.CharField(
# label=u"Vorname",
# max_length=255,
# required=True,
# )
#
# additional_name = forms.CharField(
# label=u"Zweiter Vorname/Zusatz",
# max_length=255,
# required=False,
# )
#
# family_name = forms.CharField(
# label=u"Nachname",
# max_length=255,
# required=True,
# )
#
# hshmembership = forms.TypedChoiceField(
# choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')),
# initial=u'maybe',
# required=True,
# widget=forms.RadioSelect()
# )
#
# class Meta:
# model = PresentationPerson
# fields = [u'given_name', u'additional_name', u'family_name', u'hshmembership']
class PresentationPersonForm(forms.ModelForm):
""" Modelform for PresentationPerson """
def __init__(self, *args, **kwargs):
super(PresentationPersonForm, self).__init__(*args, **kwargs)
self.helper = PresentationPersonFormHelper
given_name = forms.CharField(
label=u"Vorname",
max_length=255,
required=True,
)
additional_name = forms.CharField(
label=u"Zweiter Vorname/Zusatz",
max_length=255,
required=False,
)
family_name = forms.CharField(
label=u"Nachname",
max_length=255,
required=True,
)
hshmembership = forms.TypedChoiceField(
choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Vielleicht')),
initial=u'maybe',
label=u'Hochschulangehörigkeit',
required=True,
widget=forms.RadioSelect()
)
class Meta:
model = PresentationPerson
fields = [u'given_name', u'additional_name', u'family_name', u'hshmembership']
""" FormHelper for the PresentationEventForm"""
@ -143,39 +145,43 @@ PresentationEventFormHelper.layout = Layout(
u'end_date'
)
# class PresentationEventForm(forms.ModelForm):
# """ Form for the PresentationEventModel"""
# def __init__(self, *args, **kwargs):
# super(PresentationEventForm, self).__init__(*args, **kwargs)
# self.helper = PresentationEventFormHelper
#
# date = forms.DateField(
# label=u"Datum",
# required=True ,
# )
# name = forms.CharField(
# label=u"Rahmen der Veranstaltung",
# max_length=255,
# required=True,
# )
# workshop = forms.BooleanField(
# label=u"Veranstaltung ist ein Workshop",
# required=False,
# )
# place = forms.CharField(
# label=u"Ort",
# max_length=255 ,
# required=True,
# )
# start_date = forms.DateField(
# label=u"Startdatum"
# )
# end_date = forms.DateField(
# label=u"Enddatum"
# )
# class Meta:
# model = PresentationEvent
# fields = [u'date', u'name', u'workshop', u'place', u'start_date', u'end_date']
class PresentationEventForm(forms.ModelForm):
""" Form for the PresentationEventModel"""
def __init__(self, *args, **kwargs):
super(PresentationEventForm, self).__init__(*args, **kwargs)
self.helper = PresentationEventFormHelper
date = forms.DateField(
label=u"Datum",
required=True,
help_text='Geben Sie hier das Datum des Vortrags (wenigstens das Jahr) an',
widget=DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False})
)
name = forms.CharField(
label=u"Rahmen der Veranstaltung",
max_length=255,
required=True,
)
workshop = forms.BooleanField(
label=u"Veranstaltung ist ein Workshop",
required=False,
)
place = forms.CharField(
label=u"Ort",
max_length=255 ,
required=True,
)
start_date = forms.DateField(
label=u"Startdatum",
widget=DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False})
)
end_date = forms.DateField(
label=u"Enddatum",
widget=DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False})
)
class Meta:
model = PresentationEvent
fields = [u'date', u'name', u'workshop', u'place', u'start_date', u'end_date']
class PresentationSubmissionForm(forms.ModelForm):
""" Form for the PresentationSubmission"""
@ -213,7 +219,7 @@ class PresentationForm(forms.ModelForm):
u'abstract'
)
title = forms.CharField(label='Titel')
title = forms.CharField(label='Titel', help_text='Geben Sie bitte hier den vollständigen Titel des Vortrags an')
type = forms.ChoiceField(choices=[(u'main', u'Hauptvortrag'), (u'other', u'andere Veranstaltung')], initial=u'main', widget=forms.RadioSelect(), label='Veranstaltungstyp')
abstract = forms.TextInput()

View File

@ -1,26 +1,19 @@
from django import forms
from frontend.models import Presentation, PresentationEvent, PresentationPerson
from frontend.forms import PresentationEventForm, PresentationPersonForm
from django.forms.models import inlineformset_factory
from bootstrap3_datetime.widgets import DateTimePicker
PresentationPersonInlineFormset = inlineformset_factory(
Presentation,
PresentationPerson,
form=PresentationPersonForm,
extra=1,
can_delete=False,
widgets={'hshmembership': forms.RadioSelect}
can_delete=False
)
PresentationEventInlineFormset = inlineformset_factory(
Presentation,
PresentationEvent,
form=PresentationEventForm,
extra=1,
can_delete=False,
widgets={
'date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False}),
'start_date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False}),
'end_date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False})
}
can_delete=False
)

View File

@ -23,6 +23,11 @@
});
})
</script>
<style type="text/css">
.add-row, .delete-row, .submit-btn {
margin-left: 50%;
}
</style>
{{ event_formset.media }}
{% endblock %}
{% block content %}
@ -72,7 +77,7 @@
<hr>
{% crispy submission_form %}
<hr>
<input type="submit" class="btn btn-primary btn-default" value="Submit">
<input type="submit" class="btn btn-primary btn-default submit-btn" value="Submit">
</form>
<hr>
<a href="{% url 'frontend-index' %}">zurück zum Index</a><br>