Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erreur notification AC si adresses mails de la MUS et/ou BSV sont vides #447

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 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,21 @@ 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()

try:
notify_message(message)
with transaction.atomic():
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"))
Loading