2020-09-29 09:54:31 +02:00
from django . db import models
2020-10-20 13:16:03 +02:00
from django . forms import ModelForm , DateField , ChoiceField , RadioSelect , BooleanField
2020-09-29 12:16:10 +02:00
from django . contrib . admin . widgets import AdminDateWidget
2020-10-20 14:12:12 +02:00
from django . utils . html import format_html
2020-09-29 12:16:10 +02:00
2021-07-07 09:42:51 +02:00
from . models import Project , Volunteer , ConcreteVolunteer , Extern , ConcreteExtern , IFG , Library , TYPE_CHOICES , \
2020-10-27 13:47:46 +01:00
HonoraryCertificate , Travel , Email , Literature , List , \
BusinessCard
2020-10-27 11:00:58 +01:00
from . settings import DATAPROTECTION , FOERDERRICHTLINIEN , NUTZUNGSBEDINGUNGEN
2020-10-20 14:12:12 +02:00
2020-09-29 09:54:31 +02:00
2020-11-17 16:11:10 +01:00
class FdbForm ( ModelForm ) :
''' this base class provides the required css class for all forms '''
required_css_class = ' required '
class ProjectForm ( FdbForm ) :
2020-09-29 12:16:10 +02:00
2020-10-21 13:53:39 +02:00
# start = DateField(widget=AdminDateWidget())
2020-09-29 12:16:10 +02:00
2020-09-29 09:54:31 +02:00
class Meta :
model = Project
2021-10-04 15:45:51 +02:00
exclude = ( ' pid ' , ' project_of_year ' , ' finance_id ' , ' granted ' , ' granted_date ' , ' realname ' , ' email ' , \
2022-12-05 11:19:03 +01:00
' end_mail_send ' , ' status ' , ' persons ' , ' survey_mail_date ' , ' mail_state ' )
2020-10-21 13:53:39 +02:00
widgets = { ' start ' : AdminDateWidget ( ) ,
' end ' : AdminDateWidget ( ) , }
2020-10-01 10:51:19 +02:00
2022-11-17 17:22:18 +01:00
2020-11-17 16:11:10 +01:00
class ExternForm ( FdbForm ) :
2020-10-01 10:51:19 +02:00
2020-10-21 13:27:05 +02:00
choice = ChoiceField ( choices = TYPE_CHOICES . items ( ) , widget = RadioSelect ,
2020-10-19 14:46:58 +02:00
label = ' Was möchtest Du beantragen? ' )
2020-10-01 10:51:19 +02:00
2020-10-20 14:12:12 +02:00
check = BooleanField ( required = True ,
2022-11-01 11:35:42 +01:00
label = format_html ( " Ich stimme den <a href= ' {} ' target= ' _blank ' rel= ' noopener ' >Datenschutzbestimmungen</a> und den <a href= ' {} ' target= ' _blank ' rel= ' noopener ' >Förderrichtlinen</a> zu " ,
2020-10-20 14:12:12 +02:00
DATAPROTECTION , FOERDERRICHTLINIEN ) )
2020-10-20 13:16:03 +02:00
2020-10-01 10:51:19 +02:00
class Meta :
2021-07-06 13:00:34 +02:00
model = ConcreteExtern
2022-12-05 11:19:03 +01:00
exclude = ( ' granted ' , ' granted_date ' , ' survey_mail_send ' , ' service_id ' , ' survey_mail_date ' , ' mail_state ' )
2020-10-01 10:51:19 +02:00
2022-11-17 17:22:18 +01:00
2020-10-28 15:04:53 +01:00
INTERN_CHOICES = { ' PRO ' : ' Projektsteckbrief ' ,
' HON ' : ' Ehrenamtsbescheinigung, Akkreditierung oder Redaktionsbestätigung ' ,
' TRAV ' : ' Reisekostenerstattung ' }
2020-10-21 09:54:12 +02:00
2020-11-17 16:11:10 +01:00
class InternForm ( FdbForm ) :
2020-10-28 15:04:53 +01:00
choice = ChoiceField ( choices = INTERN_CHOICES . items ( ) , widget = RadioSelect ,
2020-10-21 09:54:12 +02:00
label = ' Was möchtest Du eingeben? ' )
class Meta :
2021-07-07 09:42:51 +02:00
model = ConcreteVolunteer
2022-12-05 11:19:03 +01:00
exclude = ( ' granted ' , ' granted_date ' , ' survey_mail_send ' , ' survey_mail_date ' , ' mail_state ' )
2020-10-21 09:54:12 +02:00
2022-11-17 17:22:18 +01:00
2022-12-08 22:32:17 +01:00
HOTEL_CHOICES = { ' TRUE ' : format_html ( ' Hotelzimmer benötigt ' ) ,
' FALSE ' : format_html ( ' Kein Hotelzimmer benötigt ' )
}
2020-11-17 16:11:10 +01:00
class TravelForm ( FdbForm ) :
2020-11-03 12:56:40 +01:00
# TODO: add some javascript to show/hide other-field
2022-11-21 14:09:12 +01:00
# this is the code, to change required to false if needed
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
self . fields [ ' project_name ' ] . required = True
self . fields [ ' transport ' ] . required = True
self . fields [ ' travelcost ' ] . required = True
self . fields [ ' checkin ' ] . required = True
self . fields [ ' checkout ' ] . required = True
2022-12-08 22:32:17 +01:00
self . fields [ ' hotel ' ] . required = True
2022-11-21 14:09:12 +01:00
2020-10-26 11:38:56 +01:00
class Meta :
model = Travel
2022-12-05 11:19:03 +01:00
exclude = ( ' granted ' , ' granted_date ' , ' survey_mail_send ' , ' realname ' , ' email ' , ' survey_mail_date ' , ' project ' , ' request_url ' , ' payed_for_hotel_by ' , ' payed_for_travel_by ' , ' intern_notes ' , ' mail_state ' )
2020-11-02 14:04:01 +01:00
widgets = { ' checkin ' : AdminDateWidget ( ) ,
' checkout ' : AdminDateWidget ( ) , }
2022-12-05 11:19:03 +01:00
fields = [ ' project_name ' , ' transport ' , ' travelcost ' , ' checkin ' , ' checkout ' , ' hotel ' , ' notes ' ]
2022-12-08 22:32:17 +01:00
hotel = ChoiceField ( label = ' Hotelzimmer benötigt: ' , choices = HOTEL_CHOICES . items ( ) , widget = RadioSelect ( ) )
2020-10-21 09:54:12 +02:00
2022-12-07 15:08:23 +01:00
class Media :
css = {
2022-12-09 18:20:03 +01:00
' all ' : ( ' css/dateFieldNoNowShortcutInTravels.css ' , )
2022-12-07 15:08:23 +01:00
}
2020-11-17 16:11:10 +01:00
class LibraryForm ( FdbForm ) :
2020-10-19 13:29:36 +02:00
2020-10-01 10:51:19 +02:00
class Meta :
model = Library
2022-11-30 01:09:10 +01:00
fields = [ ' cost ' , ' library ' , ' duration ' , ' notes ' , ' survey_mail_send ' ]
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
2020-10-01 10:51:19 +02:00
2020-11-18 18:02:23 +01:00
class HonoraryCertificateForm ( FdbForm ) :
2022-12-05 11:19:03 +01:00
2020-11-18 18:02:23 +01:00
class Meta :
model = HonoraryCertificate
fields = [ ' request_url ' , ' project ' ]
2022-11-17 19:19:18 +01:00
exclude = [ ' intern_notes ' ]
2020-11-18 18:02:23 +01:00
2020-11-17 16:11:10 +01:00
class IFGForm ( FdbForm ) :
2020-10-01 10:51:19 +02:00
class Meta :
2020-10-01 12:08:02 +02:00
model = IFG
2020-11-02 15:41:08 +01:00
fields = [ ' cost ' , ' url ' , ' notes ' ]
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
2020-10-21 09:54:12 +02:00
2020-10-27 11:00:58 +01:00
2020-11-18 18:06:00 +01:00
class CheckForm ( FdbForm ) :
""" Baseclass for all classes which need a check for Nutzungsbedingungen """
2020-11-18 18:02:23 +01:00
check = BooleanField ( required = True ,
label = format_html ( " Ich stimme den <a href= ' {} ' >Nutzungsbedingungen</a> zu " ,
NUTZUNGSBEDINGUNGEN ) )
2022-11-17 17:22:18 +01:00
2020-11-18 18:06:00 +01:00
class LiteratureForm ( CheckForm ) :
2022-11-15 17:57:01 +01:00
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
2022-12-09 17:55:26 +01:00
self . fields [ ' selfbuy_give_data ' ] . required = True
2020-10-27 13:47:46 +01:00
class Meta :
model = Literature
2022-11-21 16:30:01 +01:00
fields = [ ' cost ' , ' info ' , ' source ' , ' notes ' , ' selfbuy ' , ' selfbuy_data ' , ' selfbuy_give_data ' ]
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
2022-11-15 17:57:01 +01:00
class Media :
2022-12-05 11:19:03 +01:00
js = ( ' dropdown/js/literature.js ' , )
2020-10-27 13:47:46 +01:00
2022-12-06 18:39:25 +01:00
ADULT_CHOICES = { ' TRUE ' : format_html ( ' Ich bin volljährig. ' ) ,
' FALSE ' : format_html ( ' Ich bin noch nicht volljährig. ' )
}
2020-11-18 18:06:00 +01:00
class EmailForm ( CheckForm ) :
2022-11-17 17:46:58 +01:00
# this is the code, to change required to false if needed
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
self . fields [ ' adult ' ] . required = True
2022-12-05 11:19:03 +01:00
self . fields [ ' other ' ] . required = True
2022-11-17 17:46:58 +01:00
2022-12-06 18:39:25 +01:00
adult = ChoiceField ( label = ' Volljährigkeit ' , choices = ADULT_CHOICES . items ( ) , widget = RadioSelect ( ) )
2020-10-27 11:00:58 +01:00
# TODO: add some javascript to show/hide other-field
class Meta :
model = Email
2022-11-17 17:46:58 +01:00
fields = [ ' domain ' , ' address ' , ' other ' , ' adult ' ]
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
2022-11-15 17:57:01 +01:00
class Media :
2022-12-05 11:19:03 +01:00
js = ( ' dropdown/js/mail.js ' , )
2022-11-15 17:57:01 +01:00
2020-10-27 13:47:46 +01:00
2020-11-18 18:06:00 +01:00
class BusinessCardForm ( CheckForm ) :
2022-11-15 17:57:01 +01:00
# this is the code, to change required to false if needed
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
self . fields [ ' url_of_pic ' ] . required = True
2022-12-05 11:19:03 +01:00
self . fields [ ' send_data_to_print ' ] . required = True
2022-11-15 17:57:01 +01:00
class Meta :
2020-10-27 13:47:46 +01:00
model = BusinessCard
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
fields = [ ' project ' , ' data ' , ' variant ' , ' url_of_pic ' , ' send_data_to_print ' , ' sent_to ' ]
2022-11-15 17:57:01 +01:00
class Media :
2022-12-05 11:19:03 +01:00
js = ( ' dropdown/js/businessCard.js ' , )
2020-10-27 13:47:46 +01:00
2022-11-17 17:22:18 +01:00
2020-11-18 18:06:00 +01:00
class ListForm ( CheckForm ) :
2020-10-27 13:47:46 +01:00
class Meta :
model = List
fields = [ ' domain ' , ' address ' ]
2022-12-05 11:19:03 +01:00
exclude = [ ' intern_notes ' , ' survey_mail_send ' , ' mail_state ' ]
2022-11-17 17:22:18 +01:00