From 73b41066e950d39421ba53a0b2c0c2f3e4a4d92c Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 22 Oct 2020 11:36:16 +0200 Subject: [PATCH] added new modell field Project.end_mail_send to assure that mails will be only send once --- README.md | 2 +- input/forms.py | 2 +- input/management/commands/sendmails.py | 7 ++++++- .../0020_project_project_end_mail.py | 18 ++++++++++++++++++ input/migrations/0021_auto_20201022_0934.py | 18 ++++++++++++++++++ input/models.py | 12 ++++++++++-- 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 input/migrations/0020_project_project_end_mail.py create mode 100644 input/migrations/0021_auto_20201022_0934.py diff --git a/README.md b/README.md index 95a065c..cd11125 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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: +versions used in development: python 3.8.2 django 3.1.1 diff --git a/input/forms.py b/input/forms.py index c7d71e3..b348afd 100644 --- a/input/forms.py +++ b/input/forms.py @@ -13,7 +13,7 @@ class ProjectForm(ModelForm): class Meta: model = Project - exclude = ('pid', 'granted', 'username', 'realname', 'email') + exclude = ('pid', 'granted', 'username', 'realname', 'email', 'project_end_mail') widgets = {'start': AdminDateWidget(), 'end': AdminDateWidget(),} diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index 35112ce..6d4c4fd 100644 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -26,7 +26,10 @@ class Command(BaseCommand): def handle(self, *args, **options): # get all projects which ended 3 weeks ago - old = Project.objects.filter(end__lt = date.today() - timedelta(days=30)) + old = Project.objects.filter(end__lt = date.today() - timedelta(days=21))\ + .exclude(end_mail_send = True) + + print(old) mail_template = get_template('input/if_end_of_project.txt') for project in old: @@ -39,6 +42,8 @@ class Command(BaseCommand): IF_EMAIL, [IF_EMAIL], fail_silently=False) + project.end_mail_send = True + project.save() except BadHeaderError: return HttpResponse('Invalid header found.') diff --git a/input/migrations/0020_project_project_end_mail.py b/input/migrations/0020_project_project_end_mail.py new file mode 100644 index 0000000..465e443 --- /dev/null +++ b/input/migrations/0020_project_project_end_mail.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.1 on 2020-10-22 09:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0019_auto_20201021_1148'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='project_end_mail', + field=models.BooleanField(null=True), + ), + ] diff --git a/input/migrations/0021_auto_20201022_0934.py b/input/migrations/0021_auto_20201022_0934.py new file mode 100644 index 0000000..e9f3f61 --- /dev/null +++ b/input/migrations/0021_auto_20201022_0934.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.1 on 2020-10-22 09:34 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0020_project_project_end_mail'), + ] + + operations = [ + migrations.RenameField( + model_name='project', + old_name='project_end_mail', + new_name='end_mail_send', + ), + ] diff --git a/input/models.py b/input/models.py index dfa3145..fb169b6 100644 --- a/input/models.py +++ b/input/models.py @@ -2,6 +2,7 @@ from django.db import models from .settings import ACCOUNTS + class Volunteer(models.Model): realname = models.CharField(max_length=200, null=True) email = models.CharField(max_length=200, null=True) @@ -17,6 +18,7 @@ class Volunteer(models.Model): class Meta: abstract = True + class Project(Volunteer): name = models.CharField(max_length=200) start = models.DateField('Startdatum', null=True) @@ -24,7 +26,9 @@ class Project(Volunteer): account = models.CharField('Kostenstelle', max_length=5, choices=ACCOUNTS.items(), null=True,) - pid = models.IntegerField(null=True, blank=True) # automaticly generated + # the following Fields are not supposed to be editet by users + pid = models.IntegerField(null=True, blank=True) + end_mail_send = models.BooleanField(null=True) def save(self,*args,**kwargs): # is there a way to call super().save() only once? @@ -35,6 +39,7 @@ class Project(Volunteer): def __str__(self): return f"{self.pid} {self.name}" + class HonoraryCertificate(Volunteer): request_url = models.CharField(max_length=2000) project = models.ForeignKey(Project, null = True, on_delete = models.SET_NULL) @@ -42,7 +47,8 @@ class HonoraryCertificate(Volunteer): def __str__(self): return "Certificate for " + self.realname -#abstract class for Library, IFG, ... + +#abstract base class for Library, IFG, ... class Grant(Volunteer): cost = models.CharField(max_length=10) notes = models.CharField(max_length=500) @@ -60,6 +66,7 @@ TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium', 'IFG': 'Kostenübernahme IFG-Anfrage', 'LIT': 'Literaturstipendium',} + # same model is used for Library, ELitStip and Software! class Library(Grant): @@ -74,6 +81,7 @@ class Library(Grant): def __str__(self): return self.library + class IFG(Grant): url = models.CharField(max_length=2000)