added new modell field Project.end_mail_send to assure that mails will be only send once

This commit is contained in:
Benni Baermann 2020-10-22 11:36:16 +02:00
parent 2bb8ee517d
commit 73b41066e9
6 changed files with 54 additions and 5 deletions

View file

@ -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

View file

@ -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(),}

View file

@ -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.')

View file

@ -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),
),
]

View file

@ -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',
),
]

View file

@ -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)