diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index e513c95c..b65d259e 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -19,14 +19,17 @@ from compensation.managers import CompensationManager from compensation.models import CompensationState, CompensationAction from compensation.utils.quality import CompensationQualityChecker from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \ - GeoReferencedMixin, DeadlineType + GeoReferencedMixin, DeadlineType, ResubmitableObjectMixin from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \ DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \ COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE from user.models import UserActionLogEntry -class AbstractCompensation(BaseObject, GeoReferencedMixin): +class AbstractCompensation(BaseObject, + GeoReferencedMixin, + ResubmitableObjectMixin + ): """ Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation, EMA or EcoAccount. diff --git a/intervention/models/intervention.py b/intervention/models/intervention.py index dd15beb1..ea561c5b 100644 --- a/intervention/models/intervention.py +++ b/intervention/models/intervention.py @@ -26,14 +26,19 @@ from intervention.models.revocation import RevocationDocument, Revocation from intervention.utils.quality import InterventionQualityChecker from konova.models import generate_document_file_upload_path, AbstractDocument, BaseObject, \ ShareableObjectMixin, \ - RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin -from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP + RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin, ResubmitableObjectMixin from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE, \ PAYMENT_REMOVED, PAYMENT_ADDED, REVOCATION_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE from user.models import UserActionLogEntry -class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin): +class Intervention(BaseObject, + ShareableObjectMixin, + RecordableObjectMixin, + CheckableObjectMixin, + GeoReferencedMixin, + ResubmitableObjectMixin + ): """ Interventions are e.g. construction sites where nature used to be. """ diff --git a/konova/models/__init__.py b/konova/models/__init__.py index c9156061..ba9de1d5 100644 --- a/konova/models/__init__.py +++ b/konova/models/__init__.py @@ -10,3 +10,4 @@ from .deadline import * from .document import * from .geometry import * from .parcel import * +from .resubmission import * diff --git a/konova/models/object.py b/konova/models/object.py index b468932a..0fbd6e8b 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -743,4 +743,24 @@ class GeoReferencedMixin(models.Model): zoom_lvl, x, y, - ) \ No newline at end of file + ) + + +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) diff --git a/konova/models/resubmission.py b/konova/models/resubmission.py new file mode 100644 index 00000000..ca97ebbf --- /dev/null +++ b/konova/models/resubmission.py @@ -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() diff --git a/konova/utils/mailer.py b/konova/utils/mailer.py index 92bd2b60..8de91198 100644 --- a/konova/utils/mailer.py +++ b/konova/utils/mailer.py @@ -398,3 +398,26 @@ class Mailer: msg ) + def send_mail_resubmission(self, obj_identifier, resubmission): + """ Send a resubmission mail for a user + + Args: + obj_identifier (str): The (resubmitted) object's identifier + resubmission (Resubmission): The resubmission + + Returns: + + """ + context = { + "obj_identifier": obj_identifier, + "resubmission": resubmission, + "EMAIL_REPLY_TO": EMAIL_REPLY_TO, + } + msg = render_to_string("email/resubmission/resubmission.html", context) + user_mail_address = [SUPPORT_MAIL_RECIPIENT] + self.send( + user_mail_address, + _("Resubmission - {}").format(obj_identifier), + msg + ) + diff --git a/templates/email/resubmission/resubmission.html b/templates/email/resubmission/resubmission.html new file mode 100644 index 00000000..25848f55 --- /dev/null +++ b/templates/email/resubmission/resubmission.html @@ -0,0 +1,29 @@ +{% load i18n %} + +
+

{% trans 'Resubmission' %}

+

{{obj_identifier}}

+
+
+ {% trans 'Hello ' %} {{resubmission.user.username}}, +
+
+ {% trans 'you wanted to be reminded on this entry.' %} +
+ {% if resubmission.comment %} +
+ {% trans 'Your personal comment:' %} +
+
"{{resubmission.comment}}"
+ {% endif %} +
+
+ {% trans 'Best regards' %} +
+ KSP +
+
+ {% include 'email/signature.html' %} +
+
+