From 33387f7648ae0fe5558fc8eae365c300a8f9df9e Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 27 Oct 2020 13:47:46 +0100 Subject: [PATCH] more work on LIT and VIS, some restructuring --- input/forms.py | 18 ++++++++- input/management/commands/sendmails.py | 11 +++++- input/migrations/0029_auto_20201027_1247.py | 42 +++++++++++++++++++++ input/models.py | 5 ++- input/views.py | 42 +++++++++++++++------ 5 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 input/migrations/0029_auto_20201027_1247.py diff --git a/input/forms.py b/input/forms.py index 15ad72d..16da3a3 100644 --- a/input/forms.py +++ b/input/forms.py @@ -4,7 +4,8 @@ from django.contrib.admin.widgets import AdminDateWidget from django.utils.html import format_html from .models import Project, Volunteer, Extern, IFG, Library, TYPE_CHOICES,\ - HonoraryCertificate, Travel, Email + HonoraryCertificate, Travel, Email, Literature, List,\ + BusinessCard from .settings import DATAPROTECTION, FOERDERRICHTLINIEN, NUTZUNGSBEDINGUNGEN @@ -66,6 +67,11 @@ class HonoraryCertificateForm(ModelForm): fields = ['request_url', 'project'] # exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send') +class LiteratureForm(ModelForm): + class Meta: + model = Literature + fields = ['cost', 'notes', 'info', 'source'] + class EmailForm(ModelForm): # TODO: add some javascript to show/hide other-field check = BooleanField(required=True, @@ -76,3 +82,13 @@ class EmailForm(ModelForm): model = Email fields = ['domain', 'address', 'other'] # exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send') + +class BusinessCardForm(ModelForm): + class Meta: + model = BusinessCard + fields = ['project', 'data', 'variant', 'sent_to'] + +class ListForm(ModelForm): + class Meta: + model = List + fields = ['domain', 'address'] diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index 1086e93..8bce578 100644 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -6,7 +6,7 @@ from django.template.loader import get_template from django.core.mail import send_mail, BadHeaderError from input.models import Project, Library, HonoraryCertificate, Travel, Email,\ - BusinessCard, List, IFG + BusinessCard, List, IFG, Literature from input.settings import URLPREFIX, IF_EMAIL, SURVEYPREFIX class Command(BaseCommand): @@ -112,6 +112,14 @@ class Command(BaseCommand): .exclude(survey_mail_send=True) self.surveymails_to_object(supported, type='IFG', name='url') + def surveymails_to_lit(self): + '''get all Litearure objects which where granted two weeks ago''' + + supported = Literature.objects.filter(granted=True)\ + .filter(granted_date__lt = date.today() - timedelta(days=14))\ + .exclude(survey_mail_send=True) + self.surveymails_to_object(supported, type='LIT', name='info') + def surveymails_to_project(self): '''send survey link 4 weeks after end of project reached''' supported = Project.objects.filter(granted=True)\ @@ -149,6 +157,7 @@ class Command(BaseCommand): self.surveymails_to_lib() self.surveymails_to_hon() self.surveymails_to_ifg() + self.surveymails_to_lit() self.surveymails_to_project() self.surveymails_to_travel() self.surveymails_to_mail_vis_lis() diff --git a/input/migrations/0029_auto_20201027_1247.py b/input/migrations/0029_auto_20201027_1247.py new file mode 100644 index 0000000..b509f37 --- /dev/null +++ b/input/migrations/0029_auto_20201027_1247.py @@ -0,0 +1,42 @@ +# Generated by Django 3.1.1 on 2020-10-27 12:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0028_auto_20201027_1131'), + ] + + operations = [ + migrations.CreateModel( + name='Literature', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('realname', models.CharField(max_length=200, null=True)), + ('email', models.CharField(max_length=200, null=True)), + ('granted', models.BooleanField(null=True)), + ('granted_date', models.DateField(null=True)), + ('survey_mail_send', models.BooleanField(null=True)), + ('username', models.CharField(max_length=200, null=True)), + ('cost', models.CharField(max_length=10)), + ('notes', models.CharField(blank=True, max_length=500)), + ('info', models.CharField(max_length=500)), + ('source', models.CharField(max_length=200)), + ], + options={ + 'abstract': False, + }, + ), + migrations.AlterField( + model_name='ifg', + name='notes', + field=models.CharField(blank=True, max_length=500), + ), + migrations.AlterField( + model_name='library', + name='notes', + field=models.CharField(blank=True, max_length=500), + ), + ] diff --git a/input/models.py b/input/models.py index ee444aa..fa1cce9 100644 --- a/input/models.py +++ b/input/models.py @@ -80,7 +80,7 @@ class Travel(Intern): #abstract base class for Library and IFG class Grant(Extern): cost = models.CharField(max_length=10) - notes = models.CharField(max_length=500) + notes = models.CharField(max_length=500, blank=True) class Meta: abstract = True @@ -110,6 +110,9 @@ class Library(Grant): def __str__(self): return self.library +class Literature(Grant): + info = models.CharField(max_length=500) + source = models.CharField(max_length=200) class IFG(Grant): url = models.CharField(max_length=2000) diff --git a/input/views.py b/input/views.py index a4f26c4..1c5480a 100644 --- a/input/views.py +++ b/input/views.py @@ -9,33 +9,45 @@ from django.conf import settings from django.template.loader import get_template from django.template import Context -from .forms import ProjectForm, ExternForm, LibraryForm, IFGForm,\ - HonoraryCertificateForm, InternForm, TravelForm, EmailForm -from .models import Project, TYPE_CHOICES, Library +from .forms import ProjectForm, ExternForm, LibraryForm, IFGForm, LiteratureForm,\ + HonoraryCertificateForm, InternForm, TravelForm, EmailForm,\ + ListForm, BusinessCardForm +from .models import Project, TYPE_CHOICES, Library, Literature from .settings import URLPREFIX, IF_EMAIL +def auth_deny(choice,pk,auth): + if choice in ('BIB', 'ELIT', 'SOFT'): + Library.set_granted(pk,auth) + if choice == 'LIT': + Literature.set_granted(pk,auth) + if choice == 'IFG': + IFG.set_granted(pk,auth) + else: + return HttpResponse(f'ERROR! UNKNWON CHOICE TYPE! {choice}') + return False + + def authorize(request, choice, pk): '''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}") + ret = auth_deny(choice, pk, True) + if ret: + return ret else: - return HttpResponse(f'ERROR! UNKNWON CHOICE TYPE! {choice}') + return HttpResponse(f"AUTHORIZED! choice: {choice}, pk: {pk}") def deny(request, choice, pk): '''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) - return HttpResponse(f"DENIED! choice: {choice}, pk: {pk}") + ret = auth_deny(choice, pk, False) + if ret: + return ret else: - return HttpResponse(f'ERROR! UNKNWON CHOICE TYPE {choice}!') + return HttpResponse(f"DENIED! choice: {choice}, pk: {pk}") def done(request): @@ -119,6 +131,12 @@ class ExternView(CookieWizardView): form.fields['library'].label = TYPE_CHOICES[choice] elif choice == 'MAIL': form = EmailForm(data) + elif choice == 'LIT': + form = LiteratureForm(data) + elif choice == 'VIS': + form = BusinessCardForm(data) + elif choice == 'LIST': + form = ListForm(data) else: raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in ExternView') else: