Model
* adds new model and mixin * adds new functionality for Mailer class for sending resubmission mails
This commit is contained in:
parent
b2f29a3651
commit
7e05d05d97
@ -19,14 +19,17 @@ from compensation.managers import CompensationManager
|
|||||||
from compensation.models import CompensationState, CompensationAction
|
from compensation.models import CompensationState, CompensationAction
|
||||||
from compensation.utils.quality import CompensationQualityChecker
|
from compensation.utils.quality import CompensationQualityChecker
|
||||||
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
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, \
|
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
||||||
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
|
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
|
||||||
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
||||||
from user.models import UserActionLogEntry
|
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,
|
Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation,
|
||||||
EMA or EcoAccount.
|
EMA or EcoAccount.
|
||||||
|
@ -26,14 +26,19 @@ from intervention.models.revocation import RevocationDocument, Revocation
|
|||||||
from intervention.utils.quality import InterventionQualityChecker
|
from intervention.utils.quality import InterventionQualityChecker
|
||||||
from konova.models import generate_document_file_upload_path, AbstractDocument, BaseObject, \
|
from konova.models import generate_document_file_upload_path, AbstractDocument, BaseObject, \
|
||||||
ShareableObjectMixin, \
|
ShareableObjectMixin, \
|
||||||
RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin
|
RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin, ResubmitableObjectMixin
|
||||||
from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP
|
|
||||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE, \
|
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE, \
|
||||||
PAYMENT_REMOVED, PAYMENT_ADDED, REVOCATION_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
PAYMENT_REMOVED, PAYMENT_ADDED, REVOCATION_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
||||||
from user.models import UserActionLogEntry
|
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.
|
Interventions are e.g. construction sites where nature used to be.
|
||||||
"""
|
"""
|
||||||
|
@ -10,3 +10,4 @@ from .deadline import *
|
|||||||
from .document import *
|
from .document import *
|
||||||
from .geometry import *
|
from .geometry import *
|
||||||
from .parcel import *
|
from .parcel import *
|
||||||
|
from .resubmission import *
|
||||||
|
@ -744,3 +744,23 @@ class GeoReferencedMixin(models.Model):
|
|||||||
x,
|
x,
|
||||||
y,
|
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()
|
@ -398,3 +398,26 @@ class Mailer:
|
|||||||
msg
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
29
templates/email/resubmission/resubmission.html
Normal file
29
templates/email/resubmission/resubmission.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>{% trans 'Resubmission' %}</h2>
|
||||||
|
<h4>{{obj_identifier}}</h4>
|
||||||
|
<hr>
|
||||||
|
<article>
|
||||||
|
{% trans 'Hello ' %} {{resubmission.user.username}},
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% trans 'you wanted to be reminded on this entry.' %}
|
||||||
|
<br>
|
||||||
|
{% if resubmission.comment %}
|
||||||
|
<br>
|
||||||
|
{% trans 'Your personal comment:' %}
|
||||||
|
<br>
|
||||||
|
<article style="font: italic">"{{resubmission.comment}}"</article>
|
||||||
|
{% endif %}
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% trans 'Best regards' %}
|
||||||
|
<br>
|
||||||
|
KSP
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% include 'email/signature.html' %}
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user