2014-07-28 15:13:55 +02:00
# -*- coding: utf-8 -*-
from django import forms
2014-12-03 09:59:44 +01:00
from frontend . models import Project , PersonGlobalIdentity , PresentationPerson , Presentation , PresentationEvent
2014-07-28 15:13:55 +02:00
from crispy_forms . helper import FormHelper
from crispy_forms . layout import Submit , Layout
2014-12-03 09:59:44 +01:00
2014-11-26 11:56:18 +01:00
from django . forms . models import inlineformset_factory
2014-11-26 11:28:56 +01:00
2014-08-07 14:47:59 +02:00
class NewProjectForm ( forms . ModelForm ) :
2014-07-28 15:13:55 +02:00
def __init__ ( self , * args , * * kwargs ) :
2014-08-07 14:47:59 +02:00
super ( NewProjectForm , self ) . __init__ ( * args , * * kwargs )
2014-07-28 15:13:55 +02:00
self . helper = FormHelper ( )
2014-09-29 15:01:35 +02:00
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 '
2014-07-28 15:13:55 +02:00
self . helper . layout = Layout (
2014-09-29 15:01:35 +02:00
u ' name ' ,
u ' description ' ,
Submit ( u ' send ' , u ' Create ' , css_class = u ' btn-default ' )
2014-07-29 14:48:09 +02:00
)
2014-07-28 15:13:55 +02:00
2014-07-29 14:48:09 +02:00
name = forms . CharField (
2014-09-29 15:01:35 +02:00
label = u " Name " ,
2014-09-25 17:36:42 +02:00
max_length = 255 ,
required = True ,
2014-07-28 15:13:55 +02:00
)
2014-07-29 14:48:09 +02:00
description = forms . CharField (
2014-09-29 15:01:35 +02:00
label = u " Description " ,
2014-09-25 17:36:42 +02:00
required = True ,
2014-07-28 15:13:55 +02:00
)
2014-07-29 14:48:09 +02:00
class Meta :
2014-08-11 16:01:03 +02:00
model = Project
2014-09-29 15:01:35 +02:00
fields = [ u ' name ' , u ' description ' ]
2014-08-11 16:01:03 +02:00
class FileUploadForm ( forms . Form ) :
def __init__ ( self , * args , * * kwargs ) :
super ( FileUploadForm , self ) . __init__ ( * args , * * kwargs )
self . helper = FormHelper ( )
2014-09-29 15:01:35 +02:00
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 '
2014-08-11 16:01:03 +02:00
self . helper . layout = Layout (
2014-09-29 15:01:35 +02:00
u ' file ' ,
Submit ( u ' send ' , u ' Upload ' , css_class = u ' btn-default ' )
2014-08-11 16:01:03 +02:00
)
2014-09-25 17:36:42 +02:00
file = forms . FileField ( )
class PersonMapForm ( forms . Form ) :
2014-10-01 11:26:11 +02:00
""" Form containing the person mapping ' wizard ' . """
2014-09-25 17:36:42 +02:00
def __init__ ( self , * args , * * kwargs ) :
super ( PersonMapForm , self ) . __init__ ( * args , * * kwargs )
self . helper = FormHelper ( )
2014-09-29 15:01:35 +02:00
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 '
2014-09-25 17:36:42 +02:00
self . helper . layout = Layout (
2014-09-29 15:01:35 +02:00
u ' action ' ,
u ' global_identity ' ,
2014-09-29 16:51:50 +02:00
u ' preferred_identity ' ,
2014-09-29 15:01:35 +02:00
Submit ( u ' skip ' , u ' Skip ' , css_class = u ' btn-default ' ) ,
Submit ( u ' save-continue ' , u ' Save and continue ' , css_class = u ' btn-default ' ) ,
2014-09-25 17:36:42 +02:00
)
2014-10-01 11:26:11 +02:00
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
2014-09-29 15:01:35 +02:00
action = forms . ChoiceField ( choices = [ ( u ' new ' , u ' Create new global Identity ' ) , ( u ' existing ' , u ' Map to existing identity ' ) ] , initial = u ' new ' , widget = forms . RadioSelect ( ) )
2014-09-29 13:40:07 +02:00
global_identity = forms . ModelChoiceField ( queryset = PersonGlobalIdentity . objects . all ( ) , required = False )
2014-09-29 16:51:50 +02:00
preferred_identity = forms . BooleanField ( initial = False , required = False )
2014-10-01 11:26:11 +02:00
2014-11-26 10:20:46 +01:00
2014-11-26 11:28:56 +01:00
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 ' ]
2014-12-03 09:59:44 +01:00
class PresentationEventForm ( forms . ModelForm ) :
""" Form for the PresentationEventModel """
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 ' date ' ,
u ' name ' ,
u ' workshop ' ,
u ' place ' ,
u ' start_date ' ,
u ' end_date ' ,
Submit ( u ' send ' , u ' Create ' , css_class = u ' btn-default ' )
)
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 " Workshop? " ,
required = False ,
)
place = forms . CharField (
label = u " Ort " ,
max_length = 255 ,
required = True ,
)
start_date = forms . DateField (
label = u " Startdatum " ,
max_length = 255 ,
required = False ,
)
end_date = forms . DateField (
label = u " Enddatum " ,
max_length = 255 ,
required = False ,
)
class Meta :
model = PresentationEvent
fields = [ u ' date ' , u ' name ' , u ' workshop ' , u ' place ' , u ' start_date ' , u ' end_date ' ]
2014-11-26 11:56:18 +01:00
2014-12-03 09:59:44 +01:00
2014-11-26 11:28:56 +01:00
2014-12-03 09:59:44 +01:00
class PresentationForm ( forms . ModelForm ) :
2014-11-26 11:28:56 +01:00
""" Big form containing all the stuff about the things. """
2014-11-26 10:20:46 +01:00
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 ' ,
2014-12-03 09:59:44 +01:00
u ' type ' ,
2014-11-26 10:20:46 +01:00
u ' abstract ' ,
Submit ( u ' send ' , u ' Abschicken ' , css_class = u ' btn-default ' )
)
pass
title = forms . CharField ( )
2014-12-03 09:59:44 +01:00
type = forms . ChoiceField ( choices = [ ( u ' new ' , u ' Hauptvortrag ' ) , ( u ' existing ' , u ' andere Veranstaltung ' ) ] , initial = u ' new ' , widget = forms . RadioSelect ( ) )
2014-11-26 10:20:46 +01:00
abstract = forms . CharField ( )
# Event (other event)
comments = forms . CharField ( )
email = forms . EmailField ( )
2014-12-03 09:59:44 +01:00
class Meta :
model = Presentation
fields = [ u ' title ' , u ' type ' , u ' abstract ' ]