citavi_mapper/frontend/forms.py

229 lines
7.7 KiB
Python

# -*- coding: utf-8 -*-
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):
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)
""" FormHelper for the PresentationPersonForm"""
PresentationPersonFormHelper = FormHelper()
PresentationPersonFormHelper.form_tag = False
PresentationPersonFormHelper.label_class = u'col-lg-2'
PresentationPersonFormHelper.field_class = u'col-lg-4'
PresentationPersonFormHelper.layout = Layout(
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"""
PresentationEventFormHelper = FormHelper()
PresentationEventFormHelper.form_tag = False
PresentationEventFormHelper.label_class = u'col-lg-2'
PresentationEventFormHelper.field_class = u'col-lg-4'
PresentationEventFormHelper.layout = Layout(
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"""
def __init__(self, *args, **kwargs):
super(PresentationSubmissionForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.layout = Layout(
u'comment',
u'email',
)
comment = forms.CharField(label='Kommentar')
email = forms.EmailField(label='E-Mail Adresse')
class Meta:
model = PresentationSubmission
fields = [u'comment', u'email']
class PresentationForm(forms.ModelForm):
""" 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_tag = False
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.layout = Layout(
u'title',
u'type',
u'abstract'
)
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()
class Meta:
model = Presentation
fields = [u'title', u'type', u'abstract']