1
0
Fork 0

code duplication removed

This commit is contained in:
Benni Bärmann 2020-10-26 13:55:36 +01:00
parent 1458a1cb6b
commit 0c44eb8224
1 changed files with 19 additions and 39 deletions

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_object(self, supported, name, type='LIB'):
mytype=type
for item in supported:
if type == 'LIB':
mytype = item.type
self.survey_link(email=item.email,
type=mytype,
pid=9999, ## TODO
name=getattr(item,name),
realname=item.realname)
item.survey_mail_send = True
item.save()
self.stdout.write(self.style.SUCCESS(f'surveymails for object type {type} send'))
def surveymails_to_lib(self): def surveymails_to_lib(self):
'''get all library objects which where granted two weeks ago''' '''get all library objects which where granted two weeks ago'''
supported = Library.objects.filter(granted=True)\ supported = Library.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) self.surveymails_to_object(supported,name='name')
for item in supported:
self.survey_link(email=item.email,
type=item.type,
pid=9999, ## TODO
name=item.library,
realname=item.realname)
item.survey_mail_send = True
item.save()
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) self.surveymails_to_object(supported, type='HON', name='request_url')
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()
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) self.surveymails_to_object(supported, type='PRO', name='realname')
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()
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) self.surveymails_to_object(supported, type='TRAV', name='request_url')
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
def handle(self, *args, **options): def handle(self, *args, **options):