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.

140 lines
4.7 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')
  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 = ('granted', 'granted_date', 'survey_mail_send', 'service_id', 'survey_mail_date')
  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')
  38. class TravelForm(FdbForm):
  39. # TODO: add some javascript to show/hide other-field
  40. class Meta:
  41. model = Travel
  42. 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' )
  43. widgets = {'checkin': AdminDateWidget(),
  44. 'checkout': AdminDateWidget(),}
  45. class LibraryForm(FdbForm):
  46. class Meta:
  47. model = Library
  48. fields = ['cost', 'library', 'duration', 'notes']
  49. exclude = ['intern_notes']
  50. class HonoraryCertificateForm(FdbForm):
  51. class Meta:
  52. model = HonoraryCertificate
  53. fields = ['request_url', 'project']
  54. exclude = ['intern_notes']
  55. class IFGForm(FdbForm):
  56. class Meta:
  57. model = IFG
  58. fields = ['cost', 'url', 'notes']
  59. exclude = ['intern_notes']
  60. class CheckForm(FdbForm):
  61. """Baseclass for all classes which need a check for Nutzungsbedingungen"""
  62. check = BooleanField(required=True,
  63. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  64. NUTZUNGSBEDINGUNGEN))
  65. class LiteratureForm(CheckForm):
  66. def __init__(self, *args, **kwargs):
  67. super().__init__(*args, **kwargs)
  68. self.fields['selfbuy_give_data'].required = True
  69. class Meta:
  70. model = Literature
  71. fields = ['cost', 'info', 'source', 'notes', 'selfbuy', 'selfbuy_give_data']
  72. exclude = ['intern_notes']
  73. class Media:
  74. js = ('dropdown/js/base.js',)
  75. class EmailForm(CheckForm):
  76. # this is the code, to change required to false if needed
  77. def __init__(self, *args, **kwargs):
  78. super().__init__(*args, **kwargs)
  79. self.fields['adult'].required = True
  80. # TODO: add some javascript to show/hide other-field
  81. class Meta:
  82. model = Email
  83. fields = ['domain', 'address', 'other', 'adult']
  84. exclude = ['intern_notes']
  85. class Media:
  86. js = ('dropdown/js/base.js',)
  87. class BusinessCardForm(CheckForm):
  88. # this is the code, to change required to false if needed
  89. def __init__(self, *args, **kwargs):
  90. super().__init__(*args, **kwargs)
  91. self.fields['url_of_pic'].required = True
  92. class Meta:
  93. model = BusinessCard
  94. exclude = ['intern_notes']
  95. fields = ['project', 'data', 'variant', 'url_of_pic', 'sent_to']
  96. class Media:
  97. js = ('dropdown/js/base.js',)
  98. class ListForm(CheckForm):
  99. class Meta:
  100. model = List
  101. fields = ['domain', 'address']
  102. exclude = ['intern_notes']