You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.3 KiB

4 years ago
4 years ago
  1. from django.db import models
  2. from django.forms import ModelForm, DateField, ChoiceField, RadioSelect, BooleanField
  3. from django.contrib.admin.widgets import AdminDateWidget
  4. from django.utils.html import format_html
  5. from .models import Project, Volunteer, ConcreteVolunteer, Extern, ConcreteExtern, IFG, Library, TYPE_CHOICES,\
  6. HonoraryCertificate, Travel, Email, Literature, List,\
  7. BusinessCard
  8. from .settings import DATAPROTECTION, FOERDERRICHTLINIEN, NUTZUNGSBEDINGUNGEN
  9. class FdbForm(ModelForm):
  10. '''this base class provides the required css class for all forms'''
  11. required_css_class = 'required'
  12. class ProjectForm(FdbForm):
  13. # start = DateField(widget=AdminDateWidget())
  14. class Meta:
  15. model = Project
  16. exclude = ('pid', 'project_of_year', 'finance_id','granted', 'granted_date', 'realname', 'email',\
  17. 'end_mail_send', 'status', 'persons', 'survey_mail_date', 'mail_state')
  18. widgets = {'start': AdminDateWidget(),
  19. 'end': AdminDateWidget(),}
  20. class ExternForm(FdbForm):
  21. choice = ChoiceField(choices=TYPE_CHOICES.items(), widget=RadioSelect,
  22. label='Was möchtest Du beantragen?')
  23. check = BooleanField(required=True,
  24. 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",
  25. DATAPROTECTION, FOERDERRICHTLINIEN))
  26. class Meta:
  27. model = ConcreteExtern
  28. exclude = ('username', 'granted', 'granted_date', 'survey_mail_send', 'service_id', 'survey_mail_date', 'mail_state')
  29. INTERN_CHOICES = {'PRO': 'Projektsteckbrief',
  30. 'HON': 'Ehrenamtsbescheinigung, Akkreditierung oder Redaktionsbestätigung',
  31. 'TRAV': 'Reisekostenerstattung'}
  32. class InternForm(FdbForm):
  33. choice = ChoiceField(choices = INTERN_CHOICES.items(), widget=RadioSelect,
  34. label = 'Was möchtest Du eingeben?')
  35. class Meta:
  36. model = ConcreteVolunteer
  37. exclude = ('granted', 'granted_date', 'survey_mail_send', 'survey_mail_date', 'mail_state')
  38. HOTEL_CHOICES = {'TRUE': format_html('Hotelzimmer benötigt'),
  39. 'FALSE': format_html('Kein Hotelzimmer benötigt')
  40. }
  41. class TravelForm(FdbForm):
  42. # TODO: add some javascript to show/hide other-field
  43. # this is the code, to change required to false if needed
  44. def __init__(self, *args, **kwargs):
  45. super().__init__(*args, **kwargs)
  46. self.fields['project_name'].required = True
  47. self.fields['transport'].required = True
  48. self.fields['travelcost'].required = True
  49. self.fields['checkin'].required = True
  50. self.fields['checkout'].required = True
  51. self.fields['hotel'].required = True
  52. class Meta:
  53. model = Travel
  54. 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' )
  55. widgets = {'checkin': AdminDateWidget(),
  56. 'checkout': AdminDateWidget(),}
  57. fields = ['project_name', 'transport', 'travelcost', 'checkin', 'checkout', 'hotel', 'notes']
  58. hotel = ChoiceField(label='Hotelzimmer benötigt:', choices=HOTEL_CHOICES.items(), widget=RadioSelect())
  59. class Media:
  60. css = {
  61. 'all': ('css/dateFieldNoNowShortcutInTravels.css',)
  62. }
  63. class LibraryForm(FdbForm):
  64. class Meta:
  65. model = Library
  66. fields = ['cost', 'library', 'duration', 'notes', 'survey_mail_send']
  67. exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
  68. class HonoraryCertificateForm(FdbForm):
  69. class Meta:
  70. model = HonoraryCertificate
  71. fields = ['request_url', 'project']
  72. exclude = ['intern_notes']
  73. class IFGForm(FdbForm):
  74. class Meta:
  75. model = IFG
  76. fields = ['cost', 'url', 'notes']
  77. exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
  78. class CheckForm(FdbForm):
  79. """Baseclass for all classes which need a check for Nutzungsbedingungen"""
  80. check = BooleanField(required=True,
  81. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  82. NUTZUNGSBEDINGUNGEN))
  83. class LiteratureForm(CheckForm):
  84. def __init__(self, *args, **kwargs):
  85. super().__init__(*args, **kwargs)
  86. self.fields['selfbuy_give_data'].required = True
  87. class Meta:
  88. model = Literature
  89. fields = ['cost', 'info', 'source', 'notes', 'selfbuy', 'selfbuy_data', 'selfbuy_give_data']
  90. exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
  91. class Media:
  92. js = ('dropdown/js/literature.js',)
  93. ADULT_CHOICES = {'TRUE': format_html('Ich bin volljährig.'),
  94. 'FALSE': format_html('Ich bin noch nicht volljährig.')
  95. }
  96. class EmailForm(CheckForm):
  97. # this is the code, to change required to false if needed
  98. def __init__(self, *args, **kwargs):
  99. super().__init__(*args, **kwargs)
  100. self.fields['adult'].required = True
  101. self.fields['other'].required = True
  102. adult = ChoiceField(label='Volljährigkeit', choices=ADULT_CHOICES.items(), widget=RadioSelect())
  103. # TODO: add some javascript to show/hide other-field
  104. class Meta:
  105. model = Email
  106. fields = ['domain', 'address', 'other', 'adult']
  107. exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
  108. class Media:
  109. js = ('dropdown/js/mail.js',)
  110. class BusinessCardForm(CheckForm):
  111. # this is the code, to change required to false if needed
  112. def __init__(self, *args, **kwargs):
  113. super().__init__(*args, **kwargs)
  114. self.fields['url_of_pic'].required = True
  115. self.fields['send_data_to_print'].required = True
  116. class Meta:
  117. model = BusinessCard
  118. exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
  119. fields = ['project', 'data', 'variant', 'url_of_pic', 'send_data_to_print', 'sent_to']
  120. class Media:
  121. js = ('dropdown/js/businessCard.js',)
  122. class ListForm(CheckForm):
  123. class Meta:
  124. model = List
  125. fields = ['domain', 'address']
  126. exclude = ['intern_notes', 'survey_mail_send','mail_state']