Command
* adds new command to be used with cron for periodic checkin of resubmissions * updates translations
This commit is contained in:
@@ -145,7 +145,8 @@ class ResubmissionAdmin(BaseResourceAdmin):
|
||||
]
|
||||
fields = [
|
||||
"comment",
|
||||
"resubmit_on"
|
||||
"resubmit_on",
|
||||
"resubmission_sent",
|
||||
]
|
||||
|
||||
|
||||
|
||||
46
konova/management/commands/handle_resubmissions.py
Normal file
46
konova/management/commands/handle_resubmissions.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 15.08.22
|
||||
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from ema.models import Ema
|
||||
from intervention.models import Intervention
|
||||
from konova.management.commands.setup import BaseKonovaCommand
|
||||
from konova.models import Resubmission
|
||||
|
||||
|
||||
class Command(BaseKonovaCommand):
|
||||
help = "Checks for resubmissions due now"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
resubmitable_models = [
|
||||
Intervention,
|
||||
Compensation,
|
||||
Ema,
|
||||
EcoAccount,
|
||||
]
|
||||
today = datetime.date.today()
|
||||
resubmissions = Resubmission.objects.filter(
|
||||
resubmit_on__lte=today,
|
||||
resubmission_sent=False,
|
||||
)
|
||||
self._write_warning(f"Found {resubmissions.count()} resubmission. Process now...")
|
||||
for model in resubmitable_models:
|
||||
all_objs = model.objects.filter(
|
||||
resubmissions__in=resubmissions
|
||||
)
|
||||
self._write_warning(f"Process resubmissions for {all_objs.count()} {model.__name__} entries")
|
||||
for obj in all_objs:
|
||||
obj.resubmit()
|
||||
self._write_success("Mails have been sent.")
|
||||
resubmissions.delete()
|
||||
self._write_success("Resubmissions have been deleted.")
|
||||
except KeyboardInterrupt:
|
||||
self._break_line()
|
||||
exit(-1)
|
||||
@@ -35,7 +35,7 @@ class Resubmission(BaseResource):
|
||||
""" Sends a resubmission mail
|
||||
|
||||
"""
|
||||
_today = today()
|
||||
_today = today().date()
|
||||
resubmission_handled = _today.__ge__(self.resubmit_on) and self.resubmission_sent
|
||||
if resubmission_handled:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user