175 lines
6.3 KiB
Python
Executable file
175 lines
6.3 KiB
Python
Executable file
from django.db import models
|
|
from django.forms import ModelForm, DateField, ChoiceField, RadioSelect, BooleanField
|
|
from django.contrib.admin.widgets import AdminDateWidget
|
|
from django.utils.html import format_html
|
|
|
|
from .models import Project, Volunteer, ConcreteVolunteer, Extern, ConcreteExtern, IFG, Library, TYPE_CHOICES,\
|
|
HonoraryCertificate, Travel, Email, Literature, List,\
|
|
BusinessCard
|
|
from .settings import DATAPROTECTION, FOERDERRICHTLINIEN, NUTZUNGSBEDINGUNGEN
|
|
|
|
|
|
|
|
class FdbForm(ModelForm):
|
|
'''this base class provides the required css class for all forms'''
|
|
required_css_class = 'required'
|
|
|
|
|
|
class ProjectForm(FdbForm):
|
|
|
|
# start = DateField(widget=AdminDateWidget())
|
|
|
|
class Meta:
|
|
model = Project
|
|
exclude = ('pid', 'project_of_year', 'finance_id','granted', 'granted_date', 'realname', 'email',\
|
|
'end_mail_send', 'status', 'persons', 'survey_mail_date', 'mail_state')
|
|
widgets = {'start': AdminDateWidget(),
|
|
'end': AdminDateWidget(),}
|
|
|
|
|
|
class ExternForm(FdbForm):
|
|
|
|
choice = ChoiceField(choices=TYPE_CHOICES.items(), widget=RadioSelect,
|
|
label='Was möchtest Du beantragen?')
|
|
|
|
check = BooleanField(required=True,
|
|
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",
|
|
DATAPROTECTION, FOERDERRICHTLINIEN))
|
|
|
|
class Meta:
|
|
model = ConcreteExtern
|
|
exclude = ('username', 'granted', 'granted_date', 'survey_mail_send', 'service_id', 'survey_mail_date', 'mail_state')
|
|
|
|
|
|
INTERN_CHOICES = {'PRO': 'Projektsteckbrief',
|
|
'HON': 'Ehrenamtsbescheinigung, Akkreditierung oder Redaktionsbestätigung',
|
|
'TRAV': 'Reisekostenerstattung'}
|
|
|
|
class InternForm(FdbForm):
|
|
choice = ChoiceField(choices = INTERN_CHOICES.items(), widget=RadioSelect,
|
|
label = 'Was möchtest Du eingeben?')
|
|
|
|
class Meta:
|
|
model = ConcreteVolunteer
|
|
exclude = ('granted', 'granted_date', 'survey_mail_send', 'survey_mail_date', 'mail_state')
|
|
|
|
|
|
HOTEL_CHOICES = {'TRUE': format_html('Hotelzimmer benötigt'),
|
|
'FALSE': format_html('Kein Hotelzimmer benötigt')
|
|
}
|
|
|
|
|
|
class TravelForm(FdbForm):
|
|
# TODO: add some javascript to show/hide other-field
|
|
|
|
# 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
|
|
self.fields['hotel'].required = True
|
|
|
|
class Meta:
|
|
model = Travel
|
|
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' )
|
|
widgets = {'checkin': AdminDateWidget(),
|
|
'checkout': AdminDateWidget(),}
|
|
fields = ['project_name', 'transport', 'travelcost', 'checkin', 'checkout', 'hotel', 'notes']
|
|
hotel = ChoiceField(label='Hotelzimmer benötigt:', choices=HOTEL_CHOICES.items(), widget=RadioSelect())
|
|
|
|
class Media:
|
|
css = {
|
|
'all': ('css/dateFieldNoNowShortcutInTravels.css',)
|
|
}
|
|
|
|
|
|
class LibraryForm(FdbForm):
|
|
|
|
class Meta:
|
|
model = Library
|
|
fields = ['cost', 'library', 'duration', 'notes', 'survey_mail_send']
|
|
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
|
|
|
|
class HonoraryCertificateForm(FdbForm):
|
|
|
|
class Meta:
|
|
model = HonoraryCertificate
|
|
fields = ['request_url', 'project']
|
|
exclude = ['intern_notes']
|
|
|
|
class IFGForm(FdbForm):
|
|
class Meta:
|
|
model = IFG
|
|
fields = ['cost', 'url', 'notes']
|
|
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
|
|
|
|
|
|
class CheckForm(FdbForm):
|
|
"""Baseclass for all classes which need a check for Nutzungsbedingungen"""
|
|
check = BooleanField(required=True,
|
|
label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
|
|
NUTZUNGSBEDINGUNGEN))
|
|
|
|
|
|
class LiteratureForm(CheckForm):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields['selfbuy_give_data'].required = True
|
|
class Meta:
|
|
model = Literature
|
|
fields = ['cost', 'info', 'source', 'notes', 'selfbuy', 'selfbuy_data', 'selfbuy_give_data']
|
|
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
|
|
class Media:
|
|
js = ('dropdown/js/literature.js',)
|
|
|
|
ADULT_CHOICES = {'TRUE': format_html('Ich bin volljährig.'),
|
|
'FALSE': format_html('Ich bin noch nicht volljährig.')
|
|
}
|
|
|
|
|
|
class EmailForm(CheckForm):
|
|
|
|
# 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
|
|
self.fields['other'].required = True
|
|
|
|
adult = ChoiceField(label='Volljährigkeit', choices=ADULT_CHOICES.items(), widget=RadioSelect())
|
|
|
|
|
|
|
|
# TODO: add some javascript to show/hide other-field
|
|
class Meta:
|
|
model = Email
|
|
fields = ['domain', 'address', 'other', 'adult']
|
|
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
|
|
class Media:
|
|
js = ('dropdown/js/mail.js',)
|
|
|
|
|
|
|
|
class BusinessCardForm(CheckForm):
|
|
# 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
|
|
self.fields['send_data_to_print'].required = True
|
|
|
|
class Meta:
|
|
model = BusinessCard
|
|
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
|
|
fields = ['project', 'data', 'variant', 'url_of_pic', 'send_data_to_print', 'sent_to']
|
|
class Media:
|
|
js = ('dropdown/js/businessCard.js',)
|
|
|
|
|
|
class ListForm(CheckForm):
|
|
class Meta:
|
|
model = List
|
|
fields = ['domain', 'address']
|
|
exclude = ['intern_notes', 'survey_mail_send','mail_state']
|
|
|