[TASK] Begin implementing the big form with formsets. :|
This commit is contained in:
parent
63ecd5f4aa
commit
a7a8601566
@ -1,10 +1,12 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from frontend.models import Project, PersonGlobalIdentity
|
from frontend.models import Project, PersonGlobalIdentity, PresentationPerson
|
||||||
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 django.forms.formsets import BaseFormSet
|
||||||
|
|
||||||
class NewProjectForm(forms.ModelForm):
|
class NewProjectForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(NewProjectForm, self).__init__(*args, **kwargs)
|
super(NewProjectForm, self).__init__(*args, **kwargs)
|
||||||
@ -82,7 +84,79 @@ class PersonMapForm(forms.Form):
|
|||||||
preferred_identity = forms.BooleanField(initial=False, required=False)
|
preferred_identity = forms.BooleanField(initial=False, required=False)
|
||||||
|
|
||||||
|
|
||||||
|
class PresentationFormSet(BaseFormSet):
|
||||||
|
""" This can be done better, but i don't know how yet. """
|
||||||
|
def add_fields(self, form, index):
|
||||||
|
""" Add fields for Presentation to the FormSet. """
|
||||||
|
super(PresentationFormSet, self).add_fields(form, index)
|
||||||
|
# Additional fields for the actual presentation
|
||||||
|
form.fields["title"] = forms.CharField()
|
||||||
|
form.fields["event_type"] = forms.ChoiceField(choices=[(u'new', u'Hauptvortrag'), (u'existing', u'andere Veranstaltung')], initial=u'new', widget=forms.RadioSelect())
|
||||||
|
form.fields["abstract"] = forms.CharField()
|
||||||
|
# Event (other event)
|
||||||
|
form.fields["date"] = forms.DateField()
|
||||||
|
form.fields["rahmen"] = forms.CharField()
|
||||||
|
form.fields["workshop"] = forms.BooleanField()
|
||||||
|
form.fields["place"] = forms.CharField()
|
||||||
|
form.fields["startdate"] = forms.DateField()
|
||||||
|
form.fields["enddate"] = forms.DateField()
|
||||||
|
# additional comment + email
|
||||||
|
form.fields["comments"] = forms.CharField()
|
||||||
|
form.fields["email"] = forms.EmailField()
|
||||||
|
|
||||||
|
|
||||||
|
class PresentationPersonForm(forms.ModelForm):
|
||||||
|
""" Modelform for PresentationPerson """
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(PresentationPersonForm, self).__init__(*args, **kwargs)
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.form_class = u'form-horizontal'
|
||||||
|
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')
|
||||||
|
)
|
||||||
|
|
||||||
|
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.ChoiceField(
|
||||||
|
choices=[
|
||||||
|
(u'yes', u'Ja'), #
|
||||||
|
(u'no', u'Nein'),
|
||||||
|
(u'maybe', u'Unbekannt'),
|
||||||
|
],
|
||||||
|
initial=u'yes',
|
||||||
|
widget=forms.RadioSelect()
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PresentationPerson
|
||||||
|
fields = [u'given_name', u'additional_name', u'family_name', u'hshmembership']
|
||||||
|
|
||||||
|
|
||||||
class PresentationForm(forms.Form):
|
class PresentationForm(forms.Form):
|
||||||
|
""" Big form containing all the stuff about the things. """
|
||||||
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()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-2
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@ -16,6 +16,12 @@ class Project(models.Model):
|
|||||||
temp += u" (No project file)"
|
temp += u" (No project file)"
|
||||||
return temp
|
return temp
|
||||||
|
|
||||||
|
class PresentationPerson(models.Model):
|
||||||
|
""" Person Model for PresentationForm"""
|
||||||
|
given_name = models.CharField(max_length=255)
|
||||||
|
additional_name = models.CharField(max_length=255)
|
||||||
|
family_name = models.CharField(max_length=255)
|
||||||
|
hshmembership = models.CharField(max_length=255)
|
||||||
|
|
||||||
class PersonGlobalIdentity(models.Model):
|
class PersonGlobalIdentity(models.Model):
|
||||||
""" Model representing a global person identity in django. Can be used to link any foreign identity to it. """
|
""" Model representing a global person identity in django. Can be used to link any foreign identity to it. """
|
||||||
|
@ -14,10 +14,13 @@ from django.contrib.auth.views import login, logout
|
|||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm, PresentationForm
|
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm, PresentationPersonForm, PresentationFormSet
|
||||||
|
from django.forms.formsets import formset_factory
|
||||||
|
|
||||||
from frontend.models import Project
|
from frontend.models import Project
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FRONTEND_PAGE_NAME = u'Citavi Mapper'
|
FRONTEND_PAGE_NAME = u'Citavi Mapper'
|
||||||
|
|
||||||
from service.Mapper import person_mapper
|
from service.Mapper import person_mapper
|
||||||
@ -105,9 +108,14 @@ class IndexView(ProtectedTemplateView):
|
|||||||
class HelloView(ProtectedFormView):
|
class HelloView(ProtectedFormView):
|
||||||
template_name = u'hello.html'
|
template_name = u'hello.html'
|
||||||
page_title = u'Hello'
|
page_title = u'Hello'
|
||||||
form_class = PresentationForm
|
form_class = None
|
||||||
success_url = u'/hello'
|
success_url = u'/hello'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(HelloView, self).__init__()
|
||||||
|
PresentationPersonFormFactory = formset_factory(PresentationPersonForm, formset=PresentationFormSet)
|
||||||
|
self.form_class = PresentationPersonFormFactory(prefix='person')
|
||||||
|
print self.form_class
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user