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.

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