Compare commits

...

2 Commits

3 changed files with 77 additions and 17 deletions

View File

@ -3,7 +3,7 @@ from django.forms import ModelForm, DateField, ChoiceField, RadioSelect, Boolean
from django.contrib.admin.widgets import AdminDateWidget
from django.utils.html import format_html
from .models import Project, Volunteer, IFG, Library, TYPE_CHOICES
from .models import Project, Volunteer, IFG, Library, TYPE_CHOICES, HonoraryCertificate
from .settings import DATAPROTECTION, FOERDERRICHTLINIEN
@ -29,6 +29,20 @@ class VolunteerForm(ModelForm):
model = Volunteer
exclude = ('granted',)
INTERN_CHOICES = [('PRO', 'Projektsteckbrief'),
('HON', 'Eherenamtsbescheinigung'),
('AKK', 'Akkreditierung oder Redaktionsbestätigung'),
('TRAV', 'Reisekostenerstattung')]
class InternForm(ModelForm):
choice = ChoiceField(choices = INTERN_CHOICES, widget=RadioSelect,
label = 'Was möchtest Du eingeben?')
class Meta:
model = Volunteer
exclude = ('granted',)
class LibraryForm(ModelForm):
class Meta:
@ -38,4 +52,9 @@ class LibraryForm(ModelForm):
class IFGForm(ModelForm):
class Meta:
model = IFG
exclude = ('realname', 'email', 'username')
exclude = ('realname', 'email', 'username', 'granted')
class HonoraryCertificateForm(ModelForm):
class Meta:
model = HonoraryCertificate
exclude = ('realname', 'email', 'username', 'granted')

View File

@ -1,6 +1,7 @@
from django.urls import path
from .views import project, accreditation, travel, certificate, ExternView, done, authorize, deny
from .views import project, accreditation, travel, certificate, ExternView, \
done, authorize, deny, InternView
urlpatterns = [
path('project', project, name='project'),
@ -8,6 +9,7 @@ urlpatterns = [
path('travel', travel, name='travel'),
path('certificate', certificate, name='certificate'),
path('extern', ExternView.as_view(), name='extern'),
path('intern', InternView.as_view(), name='intern'),
path('saved', done, name='done'),
path('authorize/<str:choice>/<int:pk>', authorize, name='authorize'),
path('deny/<str:choice>/<int:pk>', deny, name='deny')

View File

@ -8,15 +8,17 @@ from django.template.loader import get_template
from django.template import Context
# from django.contrib.sites.models import Site
from .forms import ProjectForm, VolunteerForm, LibraryForm, IFGForm
from .forms import ProjectForm, VolunteerForm, LibraryForm, IFGForm,\
HonoraryCertificateForm, InternForm
from .models import Project, TYPE_CHOICES, Library
from .settings import URLPREFIX, IF_EMAIL
def authorize(request, choice, pk):
'''If IF grant a support they click a link in a mail which leads here'''
'''If IF grant a support they click a link in a mail which leads here.
We write the granted field in the database here and set a timestamp.'''
# TODO: write a timestamp which is needed to determine time of next mail
if choice in ('BIB', 'ELIT', 'SOFT'):
Library.set_granted(pk,True)
return HttpResponse(f"AUTHORIZED! choice: {choice}, pk: {pk}")
@ -25,7 +27,8 @@ def authorize(request, choice, pk):
def deny(request, choice, pk):
'''If IF denies a support they click a link in a mail which leads here'''
'''If IF denies a support they click a link in a mail which leads here
We write the granted field in the database here.'''
if choice in ('BIB', 'ELIT', 'SOFT'):
Library.set_granted(pk,False)
@ -68,17 +71,56 @@ def done(request):
def extern(request):
return HttpResponse("The world out there is large and dangerous")
class InternView(CookieWizardView):
'''This View is for the WMDE-employees only'''
template_name = 'input/extern.html'
form_list = [InternForm, ProjectForm]
def get_form(self, step=None, data=None, files=None):
if step is None:
step = self.steps.current
print ("get_form() step " + step)
if step == '1':
prev_data = self.get_cleaned_data_for_step('0')
choice = prev_data.get('choice')
if choice == 'HON':
print ('Ehrenamtsbescheinigung detected!')
form = HonoraryCertificateForm(data)
else:
print('ERROR! UNKNOWN FORMTYPE!')
else:
form = super().get_form(step, data, files)
return form
def done(self, form_list, **kwargs):
print('ExternView.done() reached')
# gather data from all forms
data = {}
for form in form_list:
data = {**data, **form.cleaned_data}
print(data)
# write data to database
form = form.save(commit=False)
# we have to copy the data from the first form here
# this is ugly code. how can we copy this without explicit writing?
# i found no way to access the ModelForm.Meta.exclude-tupel
form.realname = data['realname']
form.username = data['username']
form.email = data['email']
form.save()
return done(self.request)
class ExternView(CookieWizardView):
'''This View is for Volunteers'''
template_name = "input/extern.html"
form_list = [VolunteerForm, LibraryForm]
# def process_step(self, form):
# if form.cleaned_data.get('choice') == 'IFG':
# print ('IFG detected!')
# self.form_list = [VolunteerForm, IFGForm]
# print('leaving process_step()')
# return self.get_form_step_data(form)
def get_form(self, step=None, data=None, files=None):
if step is None:
step = self.steps.current
@ -154,6 +196,3 @@ class ExternView(CookieWizardView):
return HttpResponse('Invalid header found.')
return done(self.request)
# return render(self.request, 'saved', {
# 'form_data': [form.cleaned_data for form in form_list],
# })