[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', 'django.contrib.staticfiles',
'pipeline', 'pipeline',
'crispy_forms', 'crispy_forms',
'fancy_formsets',
'bootstrap3_datetime', 'bootstrap3_datetime',
'django_bootstrap_breadcrumbs', 'django_bootstrap_breadcrumbs',
'frontend', 'frontend',
'debug_toolbar' # 'debug_toolbar'
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (

View File

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

View File

@ -1,26 +1,19 @@
from django import forms
from frontend.models import Presentation, PresentationEvent, PresentationPerson from frontend.models import Presentation, PresentationEvent, PresentationPerson
from frontend.forms import PresentationEventForm, PresentationPersonForm
from django.forms.models import inlineformset_factory from django.forms.models import inlineformset_factory
from bootstrap3_datetime.widgets import DateTimePicker
PresentationPersonInlineFormset = inlineformset_factory( PresentationPersonInlineFormset = inlineformset_factory(
Presentation, Presentation,
PresentationPerson, PresentationPerson,
form=PresentationPersonForm,
extra=1, extra=1,
can_delete=False, can_delete=False
widgets={'hshmembership': forms.RadioSelect}
) )
PresentationEventInlineFormset = inlineformset_factory( PresentationEventInlineFormset = inlineformset_factory(
Presentation, Presentation,
PresentationEvent, PresentationEvent,
form=PresentationEventForm,
extra=1, extra=1,
can_delete=False, 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})
}
) )

View File

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