From e0c20c5d64dba6929422a37a6f1a9fef3968c61a Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 20 Oct 2020 09:35:04 +0200 Subject: [PATCH] authorize/deny Links in IF Mail should work now --- README.md | 2 +- input/forms.py | 4 +-- input/migrations/0014_auto_20201020_0714.py | 38 +++++++++++++++++++++ input/models.py | 4 ++- input/views.py | 23 +++++++++++-- 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 input/migrations/0014_auto_20201020_0714.py diff --git a/README.md b/README.md index b3d2aa7..95a065c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # foerderbarometer -purpose: gather data from intern(WMDE) and extern(volonteers) forms to create a database ('förderdatenbank') and send emails with links for a questionary. +purpose: gather data from intern(WMDE) and extern(volunteers) forms to create a database ('förderdatenbank') and send emails with links for a questionary. used versions: diff --git a/input/forms.py b/input/forms.py index 191aff7..4043a7f 100644 --- a/input/forms.py +++ b/input/forms.py @@ -20,13 +20,13 @@ class VolunteerForm(ModelForm): class Meta: model = Volunteer - fields = '__all__' + exclude = ('granted',) class LibraryForm(ModelForm): class Meta: model = Library - exclude = ('realname', 'email', 'username', 'type') + exclude = ('realname', 'email', 'username', 'type', 'granted') class IFGForm(ModelForm): class Meta: diff --git a/input/migrations/0014_auto_20201020_0714.py b/input/migrations/0014_auto_20201020_0714.py new file mode 100644 index 0000000..d6d409b --- /dev/null +++ b/input/migrations/0014_auto_20201020_0714.py @@ -0,0 +1,38 @@ +# Generated by Django 3.1.1 on 2020-10-20 07:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0013_library_type'), + ] + + operations = [ + migrations.AddField( + model_name='honorarycertificate', + name='granted', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='ifg', + name='granted', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='library', + name='granted', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='project', + name='granted', + field=models.BooleanField(null=True), + ), + migrations.AlterField( + model_name='library', + name='type', + field=models.CharField(choices=[('BIB', 'Bibliotheksstipendium'), ('ELIT', 'eLiteraturstipendium'), ('SOFT', 'Softwarestipendium'), ('VIS', 'Visitenkarten'), ('LIST', 'Mailingliste'), ('MAIL', 'E-Mail-Adresse'), ('IFG', 'Kostenübernahme IFG-Anfrage'), ('LIT', 'Literaturstipendium')], default='LIB', max_length=4), + ), + ] diff --git a/input/models.py b/input/models.py index 198ae21..88327f3 100644 --- a/input/models.py +++ b/input/models.py @@ -5,6 +5,7 @@ class Volunteer(models.Model): realname = models.CharField(max_length=200, null=True) email = models.CharField(max_length=200, null=True) username = models.CharField(max_length=200, null=True) + granted = models.BooleanField(null=True) class Meta: abstract = True @@ -39,7 +40,7 @@ class Grant(Volunteer): class Meta: abstract = True -# same model is used for Library, ELitStip and Software! + TYPE_CHOICES = [('BIB', 'Bibliotheksstipendium'), ('ELIT', 'eLiteraturstipendium'), ('SOFT', 'Softwarestipendium'), @@ -49,6 +50,7 @@ TYPE_CHOICES = [('BIB', 'Bibliotheksstipendium'), ('IFG', 'Kostenübernahme IFG-Anfrage'), ('LIT', 'Literaturstipendium'),] +# same model is used for Library, ELitStip and Software! class Library(Grant): type = models.CharField( diff --git a/input/views.py b/input/views.py index fba4f90..087476f 100644 --- a/input/views.py +++ b/input/views.py @@ -8,13 +8,30 @@ from django.template.loader import get_template from django.template import Context from .forms import ProjectForm, VolunteerForm, LibraryForm, IFGForm -from .models import Project, TYPE_CHOICES +from .models import Project, TYPE_CHOICES, Library + + +def set_granted_in_lib(key,b): + lib = Library.objects.get(pk=key) + lib.granted = b + lib.save() + def authorize(request, choice, pk): - return HttpResponse(f"AUTHORIZE! choice: {choice}, pk: {pk}") + if choice in ('BIB', 'ELIT', 'SOFT'): + set_granted_in_lib(pk,True) + return HttpResponse(f"AUTHORIZED! choice: {choice}, pk: {pk}") + else: + return HttpResponse('ERROR! UNKNWON CHOICE TYPE!') + def deny(request, choice, pk): - return HttpResponse(f"DENY! choice: {choice}, pk: {pk}") + if choice in ('BIB', 'ELIT', 'SOFT'): + set_granted_in_lib(pk,False) + return HttpResponse(f"DENIED! choice: {choice}, pk: {pk}") + else: + return HttpResponse('ERROR! UNKNWON CHOICE TYPE!') + def project(request): # return HttpResponse("Hello, world. You're at the input form")