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.

116 lines
4.0 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, Extern, 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', 'granted', 'granted_date', 'realname', 'email',\
  17. 'end_mail_send', 'status', 'persons')
  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='{}'>Datenschutzbestimmungen</a> und den <a href='{}'>Förderrichtlinen</a> zu",
  25. DATAPROTECTION, FOERDERRICHTLINIEN))
  26. class Meta:
  27. model = Extern
  28. exclude = ('granted', 'granted_date', 'survey_mail_send', 'service_id')
  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 = Volunteer
  37. exclude = ('granted', 'granted_date', 'survey_mail_send')
  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',)
  43. widgets = {'checkin': AdminDateWidget(),
  44. 'checkout': AdminDateWidget(),}
  45. class LibraryForm(FdbForm):
  46. class Meta:
  47. model = Library
  48. fields = ['cost', 'library', 'duration', 'notes']
  49. class HonoraryCertificateForm(FdbForm):
  50. class Meta:
  51. model = HonoraryCertificate
  52. fields = ['request_url', 'project']
  53. class IFGForm(FdbForm):
  54. class Meta:
  55. model = IFG
  56. fields = ['cost', 'url', 'notes']
  57. '''TODO: the next four classes could maybe have a common base class for the check field,
  58. but i am not sure about the sequence of fields. check should be always last'''
  59. class LiteratureForm(FdbForm):
  60. check = BooleanField(required=True,
  61. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  62. NUTZUNGSBEDINGUNGEN))
  63. class Meta:
  64. model = Literature
  65. fields = ['cost', 'info', 'source', 'notes']
  66. class EmailForm(FdbForm):
  67. # TODO: add some javascript to show/hide other-field
  68. check = BooleanField(required=True,
  69. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  70. NUTZUNGSBEDINGUNGEN))
  71. class Meta:
  72. model = Email
  73. fields = ['domain', 'address', 'other']
  74. class BusinessCardForm(FdbForm):
  75. check = BooleanField(required=True,
  76. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  77. NUTZUNGSBEDINGUNGEN))
  78. class Meta:
  79. model = BusinessCard
  80. fields = ['project', 'data', 'variant', 'sent_to']
  81. class ListForm(FdbForm):
  82. check = BooleanField(required=True,
  83. label=format_html("Ich stimme den <a href='{}'>Nutzungsbedingungen</a> zu",
  84. NUTZUNGSBEDINGUNGEN))
  85. class Meta:
  86. model = List
  87. fields = ['domain', 'address']