Browse Source

code duplication removed

master
Benni Baermann 4 years ago
parent
commit
0c44eb8224
1 changed files with 19 additions and 39 deletions
  1. +19
    -39
      input/management/commands/sendmails.py

+ 19
- 39
input/management/commands/sendmails.py View File

@ -53,7 +53,6 @@ class Command(BaseCommand):
for project in old: for project in old:
context = {'project': project} context = {'project': project}
context['URLPREFIX'] = URLPREFIX context['URLPREFIX'] = URLPREFIX
print(context)
try: try:
send_mail('Projektende erreicht', send_mail('Projektende erreicht',
mail_template.render(context), mail_template.render(context),
@ -67,21 +66,28 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.')) self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.'))
def surveymails_to_lib(self):
'''get all library objects which where granted two weeks ago'''
supported = Library.objects.filter(granted=True)\
.filter(granted_date__lt = date.today() - timedelta(days=14))\
.exclude(survey_mail_send=True)
print(supported)
def surveymails_to_object(self, supported, name, type='LIB'):
mytype=type
for item in supported: for item in supported:
if type == 'LIB':
mytype = item.type
self.survey_link(email=item.email, self.survey_link(email=item.email,
type=item.type,
type=mytype,
pid=9999, ## TODO pid=9999, ## TODO
name=item.library,
name=getattr(item,name),
realname=item.realname) realname=item.realname)
item.survey_mail_send = True item.survey_mail_send = True
item.save() item.save()
self.stdout.write(self.style.SUCCESS(f'surveymails for object type {type} send'))
def surveymails_to_lib(self):
'''get all library objects which where granted two weeks ago'''
supported = Library.objects.filter(granted=True)\
.filter(granted_date__lt = date.today() - timedelta(days=14))\
.exclude(survey_mail_send=True)
self.surveymails_to_object(supported,name='name')
def surveymails_to_hon(self): def surveymails_to_hon(self):
'''get all HonoraryCertificate objects which where granted two weeks ago''' '''get all HonoraryCertificate objects which where granted two weeks ago'''
@ -89,30 +95,14 @@ class Command(BaseCommand):
supported = HonoraryCertificate.objects.filter(granted=True)\ supported = HonoraryCertificate.objects.filter(granted=True)\
.filter(granted_date__lt = date.today() - timedelta(days=14))\ .filter(granted_date__lt = date.today() - timedelta(days=14))\
.exclude(survey_mail_send=True) .exclude(survey_mail_send=True)
print(supported)
for item in supported:
self.survey_link(email=item.email,
type='HON',
pid=9999, ## TODO
name=item.request_url,
realname=item.realname)
item.survey_mail_send = True
item.save()
self.surveymails_to_object(supported, type='HON', name='request_url')
def surveymails_to_project(self): def surveymails_to_project(self):
'''send survey link 4 weeks after end of project reached''' '''send survey link 4 weeks after end of project reached'''
supported = Project.objects.filter(granted=True)\ supported = Project.objects.filter(granted=True)\
.filter(granted_date__lt = date.today() - timedelta(days=28))\ .filter(granted_date__lt = date.today() - timedelta(days=28))\
.exclude(survey_mail_send=True) .exclude(survey_mail_send=True)
print(supported)
for item in supported:
self.survey_link(email=item.email,
type='PRO',
pid=9999, ## TODO
name=item.name,
realname=item.realname)
item.survey_mail_send = True
item.save()
self.surveymails_to_object(supported, type='PRO', name='realname')
def surveymails_to_travel(self): def surveymails_to_travel(self):
'''send survey link 3 weeks after end of project reached''' '''send survey link 3 weeks after end of project reached'''
@ -120,17 +110,7 @@ class Command(BaseCommand):
supported = Travel.objects.filter(project__granted=True)\ supported = Travel.objects.filter(project__granted=True)\
.filter(project__granted_date__lt = date.today() - timedelta(days=21))\ .filter(project__granted_date__lt = date.today() - timedelta(days=21))\
.exclude(survey_mail_send=True) .exclude(survey_mail_send=True)
print(supported)
for item in supported:
self.survey_link(email=item.email,
type='TRAV',
pid=9999, ## TODO
name=item.request_url,
realname=item.realname)
item.survey_mail_send = True
item.save()
pass
self.surveymails_to_object(supported, type='TRAV', name='request_url')
def handle(self, *args, **options): def handle(self, *args, **options):

Loading…
Cancel
Save