179 lines
5.8 KiB
Python
179 lines
5.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from django import forms
|
|
from frontend.models import Project, PersonGlobalIdentity, PresentationPerson, Presentation
|
|
from crispy_forms.helper import FormHelper
|
|
from crispy_forms.layout import Submit, Layout
|
|
|
|
from django.forms.models import inlineformset_factory
|
|
|
|
class NewProjectForm(forms.ModelForm):
|
|
def __init__(self, *args, **kwargs):
|
|
super(NewProjectForm, 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'name',
|
|
u'description',
|
|
Submit(u'send', u'Create', css_class=u'btn-default')
|
|
)
|
|
|
|
name = forms.CharField(
|
|
label=u"Name",
|
|
max_length=255,
|
|
required=True,
|
|
)
|
|
|
|
description = forms.CharField(
|
|
label=u"Description",
|
|
required=True,
|
|
)
|
|
|
|
class Meta:
|
|
model = Project
|
|
fields = [u'name', u'description']
|
|
|
|
class FileUploadForm(forms.Form):
|
|
def __init__(self, *args, **kwargs):
|
|
super(FileUploadForm, 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'file',
|
|
Submit(u'send', u'Upload', css_class=u'btn-default')
|
|
)
|
|
|
|
file = forms.FileField()
|
|
|
|
|
|
class PersonMapForm(forms.Form):
|
|
""" Form containing the person mapping 'wizard'. """
|
|
def __init__(self, *args, **kwargs):
|
|
super(PersonMapForm, 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'action',
|
|
u'global_identity',
|
|
u'preferred_identity',
|
|
Submit(u'skip', u'Skip', css_class=u'btn-default'),
|
|
Submit(u'save-continue', u'Save and continue', css_class=u'btn-default'),
|
|
)
|
|
|
|
def clean(self):
|
|
""" Make sure the submitted data is okay. """
|
|
cleaned_data = super(PersonMapForm, self).clean()
|
|
action = cleaned_data.get(u'action')
|
|
global_identity = cleaned_data.get(u'global_identity')
|
|
if action == u'existing' and not global_identity:
|
|
msg = u"Cannot map to non-existing global identity!"
|
|
self._errors["global_identity"] = self.error_class([msg])
|
|
return cleaned_data
|
|
|
|
action = forms.ChoiceField(choices=[(u'new', u'Create new global Identity'), (u'existing', u'Map to existing identity')], initial=u'new', widget=forms.RadioSelect())
|
|
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False)
|
|
preferred_identity = forms.BooleanField(initial=False, required=False)
|
|
|
|
|
|
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']
|
|
|
|
PresentationPersonFormSet = inlineformset_factory(Presentation, PresentationPerson)
|
|
|
|
|
|
class PresentationForm(forms.Form):
|
|
""" Big form containing all the stuff about the things. """
|
|
def __init__(self, *args, **kwargs):
|
|
super(PresentationForm, 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'title',
|
|
u'event_type',
|
|
u'abstract',
|
|
u'date',
|
|
u'rahmen',
|
|
u'workshop',
|
|
u'place',
|
|
u'startdate',
|
|
u'enddate',
|
|
u'comments',
|
|
u'email',
|
|
Submit(u'send', u'Abschicken', css_class=u'btn-default')
|
|
)
|
|
pass
|
|
|
|
title = forms.CharField()
|
|
event_type = forms.ChoiceField(choices=[(u'new', u'Hauptvortrag'), (u'existing', u'andere Veranstaltung')], initial=u'new', widget=forms.RadioSelect())
|
|
abstract = forms.CharField()
|
|
|
|
# Event (other event)
|
|
date = forms.DateField()
|
|
rahmen = forms.CharField()
|
|
workshop = forms.BooleanField()
|
|
place = forms.CharField()
|
|
startdate = forms.DateField()
|
|
enddate = forms.DateField()
|
|
|
|
comments = forms.CharField()
|
|
email = forms.EmailField()
|
|
|