Model
* adds new model and mixin * adds new functionality for Mailer class for sending resubmission mails
This commit is contained in:
@@ -10,3 +10,4 @@ from .deadline import *
|
||||
from .document import *
|
||||
from .geometry import *
|
||||
from .parcel import *
|
||||
from .resubmission import *
|
||||
|
||||
@@ -743,4 +743,24 @@ class GeoReferencedMixin(models.Model):
|
||||
zoom_lvl,
|
||||
x,
|
||||
y,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ResubmitableObjectMixin(models.Model):
|
||||
resubmissions = models.ManyToManyField(
|
||||
"konova.Resubmission",
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="+",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def resubmit(self):
|
||||
""" Run resubmit check and run for all related resubmissions
|
||||
|
||||
"""
|
||||
resubmissions = self.resubmissions.all()
|
||||
for resubmission in resubmissions:
|
||||
resubmission.send_resubmission_mail(self.identifier)
|
||||
|
||||
46
konova/models/resubmission.py
Normal file
46
konova/models/resubmission.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
|
||||
|
||||
"""
|
||||
from dateutil.utils import today
|
||||
from django.db import models
|
||||
|
||||
from konova.models import BaseResource
|
||||
from konova.utils.mailer import Mailer
|
||||
|
||||
|
||||
class Resubmission(BaseResource):
|
||||
user = models.ForeignKey(
|
||||
"user.User",
|
||||
on_delete=models.CASCADE,
|
||||
help_text="The user who wants to be notifed"
|
||||
)
|
||||
resubmit_on = models.DateField(
|
||||
help_text="On which date the resubmission should be performed"
|
||||
)
|
||||
resubmission_sent = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Whether a resubmission has been sent or not"
|
||||
)
|
||||
comment = models.TextField(
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Optional comment for the user itself"
|
||||
)
|
||||
|
||||
def send_resubmission_mail(self, obj_identifier):
|
||||
""" Sends a resubmission mail
|
||||
|
||||
"""
|
||||
_today = today()
|
||||
resubmission_handled = _today.__ge__(self.resubmit_on) and self.resubmission_sent
|
||||
if resubmission_handled:
|
||||
return
|
||||
|
||||
mailer = Mailer()
|
||||
mailer.send_mail_resubmission(obj_identifier, self)
|
||||
self.resubmission_sent = True
|
||||
self.save()
|
||||
Reference in New Issue
Block a user