Skip to content

Commit

Permalink
Fix notification AC si adresses mails de la MUS et/ou BSV sont vides …
Browse files Browse the repository at this point in the history
…en base.
  • Loading branch information
alanzirek committed Nov 15, 2024
1 parent 3bfaaa5 commit 870f220
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions core/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import models
from django.db import models, transaction
from django.urls import reverse

from core.forms import DocumentUploadForm, DocumentEditForm
Expand Down Expand Up @@ -106,15 +106,20 @@ def notify_ac(self, sender):
raise ValidationError("Cet objet est déjà notifié à l'AC")

self.is_ac_notified = True
message = Message.objects.create(
message = Message(
message_type=Message.NOTIFICATION_AC,
title="Notification à l'AC",
content="L'administration a été notifiée de cette fiche.",
sender=sender,
content_object=self,
)
notify_message(message)
self.save()
with transaction.atomic():
try:
notify_message(message)
self.save()
message.save()
except ValidationError as e:
raise ValidationError(f"Une erreur s'est produite lors de la notification : {e.message}")

class Meta:
abstract = True
Expand Down
4 changes: 2 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def post(self, request):
messages.success(request, "L'administration centrale a été notifiée avec succès")
except AttributeError:
messages.error(request, "Ce type d'objet n'est pas compatible avec une notification à l'AC.")
except ValidationError:
messages.error(request, "Cet objet est déjà notifié à l'AC")
except ValidationError as e:
messages.error(request, e.message)

return safe_redirect(request.POST.get("next"))

0 comments on commit 870f220

Please sign in to comment.