From d3ba817b09686a67daf5953b8632469f1803f6fc Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 22 Oct 2020 14:38:23 +0200 Subject: [PATCH] new modell field survey_mail_send to make sure every mail is sendet only once --- input/forms.py | 12 ++++---- input/management/commands/sendmails.py | 17 ++++++----- input/migrations/0022_auto_20201022_1233.py | 33 +++++++++++++++++++++ input/models.py | 1 + 4 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 input/migrations/0022_auto_20201022_1233.py diff --git a/input/forms.py b/input/forms.py index b348afd..6c2d8c7 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', 'project_end_mail') + exclude = ('pid', 'granted', 'username', 'realname', 'email', 'project_end_mail', 'survey_mail_send') widgets = {'start': AdminDateWidget(), 'end': AdminDateWidget(),} @@ -28,7 +28,7 @@ class VolunteerForm(ModelForm): class Meta: model = Volunteer - exclude = ('granted',) + exclude = ('granted','survey_mail_send') INTERN_CHOICES = [('PRO', 'Projektsteckbrief'), ('HON', 'Ehrenamtsbescheinigung'), @@ -41,21 +41,21 @@ class InternForm(ModelForm): class Meta: model = Volunteer - exclude = ('granted',) + exclude = ('granted','survey_mail_send') class LibraryForm(ModelForm): class Meta: model = Library - exclude = ('realname', 'email', 'username', 'type', 'granted') + exclude = ('realname', 'email', 'username', 'type', 'granted', 'survey_mail_send') class IFGForm(ModelForm): class Meta: model = IFG - exclude = ('realname', 'email', 'username', 'granted') + exclude = ('realname', 'email', 'username', 'granted', 'survey_mail_send') class HonoraryCertificateForm(ModelForm): class Meta: model = HonoraryCertificate - exclude = ('realname', 'email', 'username', 'granted') + exclude = ('realname', 'email', 'username', 'granted', 'survey_mail_send') diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index c822ae5..49ced69 100644 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -64,7 +64,7 @@ class Command(BaseCommand): project.end_mail_send = True project.save() except BadHeaderError: - return HttpResponse('Invalid header found.') + self.stdout.write(self.style.ERROR('Invalid header found.')) self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.')) @@ -73,15 +73,16 @@ class Command(BaseCommand): self.end_of_projects_reached() - supported = Library.objects.filter(granted=True) + supported = Library.objects.filter(granted=True)\ + .exclude(survey_mail_send=True) print(supported) for item in supported: self.survey_link(email=item.email, - type=item.type, - pid=9999, ## TODO - name=item.library, - realname=item.realname) -# project.end_mail_send = True -# project.save() + type=item.type, + pid=9999, ## TODO + name=item.library, + realname=item.realname) + item.survey_mail_send = True + item.save() self.stdout.write(self.style.SUCCESS('sendmails custom command executed')) diff --git a/input/migrations/0022_auto_20201022_1233.py b/input/migrations/0022_auto_20201022_1233.py new file mode 100644 index 0000000..3ec91cf --- /dev/null +++ b/input/migrations/0022_auto_20201022_1233.py @@ -0,0 +1,33 @@ +# Generated by Django 3.1.1 on 2020-10-22 12:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0021_auto_20201022_0934'), + ] + + operations = [ + migrations.AddField( + model_name='honorarycertificate', + name='survey_mail_send', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='ifg', + name='survey_mail_send', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='library', + name='survey_mail_send', + field=models.BooleanField(null=True), + ), + migrations.AddField( + model_name='project', + name='survey_mail_send', + field=models.BooleanField(null=True), + ), + ] diff --git a/input/models.py b/input/models.py index fb169b6..7f9a9ec 100644 --- a/input/models.py +++ b/input/models.py @@ -8,6 +8,7 @@ class Volunteer(models.Model): email = models.CharField(max_length=200, null=True) username = models.CharField(max_length=200, null=True) granted = models.BooleanField(null=True) + survey_mail_send = models.BooleanField(null=True) @classmethod def set_granted(cl, key, b):