#300 Extend mail templates

* extends all relevant mail templates such that municipals of an entry will be shown in the mail
This commit is contained in:
2023-02-23 10:17:45 +01:00
parent e1259b276c
commit bf41559c56
23 changed files with 383 additions and 158 deletions

View File

@@ -276,6 +276,22 @@ class Geometry(BaseResource):
return parcels
def get_underlying_municipals(self, parcels=None):
""" Getter for related municipals
If no QuerySet of parcels is provided, the parcels will be fetched
Returns:
municipals (QuerySet): The related municipals as queryset
"""
from konova.models import Municipal
if parcels is None:
parcels = self.get_underlying_parcels()
municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
municipals = Municipal.objects.filter(id__in=municipals).order_by("name")
return municipals
def count_underlying_parcels(self):
""" Getter for number of underlying parcels

View File

@@ -120,13 +120,14 @@ class DeletableObjectMixin(models.Model):
if send_mail:
# Send mail
shared_users = self.shared_users.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id, municipals_names)
# Send mail
shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams:
celery_send_mail_shared_data_deleted_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_data_deleted_team.delay(self.identifier, self.title, team_id, municipals_names)
self.save()
@@ -277,12 +278,13 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.values_list("id", flat=True)
shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_unrecorded.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_data_unrecorded.delay(self.identifier, self.title, user_id, municipals_names)
for team_id in shared_teams:
celery_send_mail_shared_data_unrecorded_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_data_unrecorded_team.delay(self.identifier, self.title, team_id, municipals_names)
return action
@@ -307,12 +309,13 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.values_list("id", flat=True)
shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_recorded.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_data_recorded.delay(self.identifier, self.title, user_id, municipals_names)
for team_id in shared_teams:
celery_send_mail_shared_data_recorded_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_data_recorded_team.delay(self.identifier, self.title, team_id, municipals_names)
return action
@@ -404,15 +407,17 @@ class CheckableObjectMixin(models.Model):
self.checked = action
self.save()
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mail
shared_users = self.shared_users.values_list("id", flat=True)
for user_id in shared_users:
celery_send_mail_shared_data_checked.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_data_checked.delay(self.identifier, self.title, user_id, municipals_names)
# Send mail
shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams:
celery_send_mail_shared_data_checked_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_data_checked_team.delay(self.identifier, self.title, team_id, municipals_names)
self.log.add(action)
return action
@@ -574,10 +579,11 @@ class ShareableObjectMixin(models.Model):
id__in=shared_teams
).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for team_id in new_teams:
celery_send_mail_shared_access_given_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_access_given_team.delay(self.identifier, self.title, team_id, municipals_names)
for team_id in removed_teams:
celery_send_mail_shared_access_removed_team.delay(self.identifier, self.title, team_id)
celery_send_mail_shared_access_removed_team.delay(self.identifier, self.title, team_id, municipals_names)
self.share_with_team_list(accessing_teams)
@@ -602,11 +608,12 @@ class ShareableObjectMixin(models.Model):
id__in=shared_users
).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mails
for user_id in removed_users:
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user_id, municipals_names)
for user_id in new_users:
celery_send_mail_shared_access_given.delay(self.identifier, self.title, user_id)
celery_send_mail_shared_access_given.delay(self.identifier, self.title, user_id, municipals_names)
# Set new shared users
self.share_with_user_list(accessing_users)
@@ -669,8 +676,9 @@ class ShareableObjectMixin(models.Model):
default_users.append(user)
self.share_with_user_list(cleaned_users)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user in default_users:
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user.id)
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user.id, municipals_names)
class GeoReferencedMixin(models.Model):
@@ -767,5 +775,6 @@ class ResubmitableObjectMixin(models.Model):
"""
resubmissions = self.resubmissions.all()
municipal_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for resubmission in resubmissions:
resubmission.send_resubmission_mail(self.identifier)
resubmission.send_resubmission_mail(self.identifier, municipal_names)

View File

@@ -31,7 +31,7 @@ class Resubmission(BaseResource):
help_text="Optional comment for the user itself"
)
def send_resubmission_mail(self, obj_identifier):
def send_resubmission_mail(self, obj_identifier, municipal_names):
""" Sends a resubmission mail
"""
@@ -41,6 +41,6 @@ class Resubmission(BaseResource):
return
mailer = Mailer()
mailer.send_mail_resubmission(obj_identifier, self)
mailer.send_mail_resubmission(obj_identifier, self, municipal_names)
self.resubmission_sent = True
self.save()

View File

@@ -25,87 +25,87 @@ def celery_update_parcels(geometry_id: str, recheck: bool = True):
@shared_task
def celery_send_mail_shared_access_removed(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_access_removed(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_access_removed(obj_identifier, obj_title)
user.send_mail_shared_access_removed(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_access_given(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_access_given(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_access_given(obj_identifier, obj_title)
user.send_mail_shared_access_given(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_access_removed_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_access_removed_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_access_removed(obj_identifier, obj_title)
team.send_mail_shared_access_removed(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_access_given_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_access_given_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_access_given_team(obj_identifier, obj_title)
team.send_mail_shared_access_given_team(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_recorded(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_data_recorded(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_recorded(obj_identifier, obj_title)
user.send_mail_shared_data_recorded(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_unrecorded(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_data_unrecorded(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_unrecorded(obj_identifier, obj_title)
user.send_mail_shared_data_unrecorded(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_recorded_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_data_recorded_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_recorded(obj_identifier, obj_title)
team.send_mail_shared_data_recorded(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_unrecorded_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_data_unrecorded_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_unrecorded(obj_identifier, obj_title)
team.send_mail_shared_data_unrecorded(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_deleted(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_data_deleted(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_deleted(obj_identifier, obj_title)
user.send_mail_shared_data_deleted(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_checked(obj_identifier, obj_title=None, user_id=None):
def celery_send_mail_shared_data_checked(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_checked(obj_identifier, obj_title)
user.send_mail_shared_data_checked(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_deleted_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_data_deleted_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_deleted(obj_identifier, obj_title)
team.send_mail_shared_data_deleted(obj_identifier, obj_title, municipals_names)
@shared_task
def celery_send_mail_shared_data_checked_team(obj_identifier, obj_title=None, team_id=None):
def celery_send_mail_shared_data_checked_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_checked(obj_identifier, obj_title)
team.send_mail_shared_data_checked(obj_identifier, obj_title, municipals_names)
@shared_task

View File

@@ -45,12 +45,14 @@ class Mailer:
auth_password=self.auth_password
)
def send_mail_shared_access_removed(self, obj_identifier, obj_title, user):
def send_mail_shared_access_removed(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if user has no access to the object anymore
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): Related user
municipals_names (iterable): List of municipals of the entry
Returns:
@@ -59,6 +61,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_removed.html", context)
@@ -69,11 +72,14 @@ class Mailer:
msg
)
def send_mail_shared_access_given(self, obj_identifier, obj_title, user):
def send_mail_shared_access_given(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if user just got access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): The related user
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -82,6 +88,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_given.html", context)
@@ -92,7 +99,7 @@ class Mailer:
msg
)
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if a team just got access to the object
Args:
@@ -100,6 +107,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -108,6 +116,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_given_team.html", context)
@@ -118,7 +127,7 @@ class Mailer:
msg
)
def send_mail_shared_access_removed_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_access_removed_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if a team just lost access to the object
Args:
@@ -126,6 +135,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -134,6 +144,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_removed_team.html", context)
@@ -144,7 +155,7 @@ class Mailer:
msg
)
def send_mail_shared_data_unrecorded_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_data_unrecorded_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if data has just been unrecorded
Args:
@@ -152,6 +163,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -160,6 +172,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_unrecorded_team.html", context)
@@ -170,7 +183,7 @@ class Mailer:
msg
)
def send_mail_shared_data_recorded_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_data_recorded_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if data has just been recorded
Args:
@@ -178,6 +191,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -186,6 +200,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_recorded_team.html", context)
@@ -196,7 +211,7 @@ class Mailer:
msg
)
def send_mail_shared_data_checked_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_data_checked_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if data has just been checked
Args:
@@ -204,6 +219,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -212,6 +228,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/checking/shared_data_checked_team.html", context)
@@ -249,11 +266,15 @@ class Mailer:
msg
)
def send_mail_shared_data_deleted_team(self, obj_identifier, obj_title, team, users_to_notify):
def send_mail_shared_data_deleted_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
""" Send a mail if data has just been deleted
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
team (Team): The related team
users_to_notify (QuerySet): Contains team users who want to be notified
municipals_names (iterable): List of municipals for the entry
Returns:
@@ -262,6 +283,7 @@ class Mailer:
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/deleting/shared_data_deleted_team.html", context)
@@ -272,11 +294,14 @@ class Mailer:
msg
)
def send_mail_shared_data_recorded(self, obj_identifier, obj_title, user):
def send_mail_shared_data_recorded(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): The related user
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -285,6 +310,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_recorded.html", context)
@@ -295,11 +321,14 @@ class Mailer:
msg
)
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title, user):
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): The related user
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -308,6 +337,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_unrecorded.html", context)
@@ -318,11 +348,14 @@ class Mailer:
msg
)
def send_mail_shared_data_deleted(self, obj_identifier, obj_title, user):
def send_mail_shared_data_deleted(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if shared data has just been deleted
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): The related user
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -331,6 +364,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/deleting/shared_data_deleted.html", context)
@@ -341,11 +375,14 @@ class Mailer:
msg
)
def send_mail_shared_data_checked(self, obj_identifier, obj_title, user):
def send_mail_shared_data_checked(self, obj_identifier, obj_title, user, municipals_names):
""" Send a mail if shared data just has been checked
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
user (User): The related user
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -354,6 +391,7 @@ class Mailer:
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/checking/shared_data_checked.html", context)
@@ -413,12 +451,13 @@ class Mailer:
msg
)
def send_mail_resubmission(self, obj_identifier, resubmission):
def send_mail_resubmission(self, obj_identifier, resubmission, municipals_names):
""" Send a resubmission mail for a user
Args:
obj_identifier (str): The (resubmitted) object's identifier
resubmission (Resubmission): The resubmission
municipals_names (iterable): List of municipals for this entry
Returns:
@@ -426,6 +465,7 @@ class Mailer:
context = {
"obj_identifier": obj_identifier,
"resubmission": resubmission,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/resubmission/resubmission.html", context)

View File

@@ -44,9 +44,7 @@ def get_geom_parcels(request: HttpRequest, id: str):
status_code = 200
if parcels_available or not geometry_exists:
parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
municipals = Municipal.objects.filter(id__in=municipals)
municipals = geom.get_underlying_municipals(parcels)
rpp = 100
num_all_parcels = parcels.count()