Skip to content

Commit

Permalink
[#2540] Inform users about issues with email strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
pbanaszkiewicz committed Nov 7, 2023
1 parent f18c4b1 commit 2760249
Showing 1 changed file with 50 additions and 24 deletions.
74 changes: 50 additions & 24 deletions amy/trainings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.shortcuts import redirect, render
from django.urls import reverse_lazy

from emails.actions.instructor_training_approaching import EmailStrategyException
from emails.actions.instructor_training_completed_not_badged import (
instructor_training_completed_not_badged_strategy,
run_instructor_training_completed_not_badged_strategy,
Expand Down Expand Up @@ -82,12 +83,18 @@ def form_valid(self, form):
person = form.cleaned_data["trainee"]
event = form.cleaned_data["event"]
result = super().form_valid(form)
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
try:
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
except EmailStrategyException as exc:
messages.error(
self.request,
f"Error when running instructor training completed strategy. {exc}",
)
return result


Expand All @@ -99,12 +106,18 @@ class TrainingProgressUpdate(RedirectSupportMixin, OnlyForAdminsMixin, AMYUpdate
def form_valid(self, form):
person = form.cleaned_data["trainee"]
event = form.cleaned_data["event"]
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
try:
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
except EmailStrategyException as exc:
messages.error(
self.request,
f"Error when running instructor training completed strategy. {exc}",
)
return super().form_valid(form)


Expand All @@ -121,12 +134,18 @@ def before_delete(self, *args, **kwargs):
def after_delete(self, *args, **kwargs):
person = self._person
event = self._event
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
try:
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(person),
request=self.request,
person=person,
training_completed_date=event.end if event else None,
)
except EmailStrategyException as exc:
messages.error(
self.request,
f"Error when running instructor training completed strategy. {exc}",
)


def all_trainees_queryset():
Expand Down Expand Up @@ -188,12 +207,19 @@ def all_trainees(request):
progress.full_clean()
progress.save()

run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(trainee),
request=request,
person=trainee,
training_completed_date=event.end if event else None,
)
try:
run_instructor_training_completed_not_badged_strategy(
instructor_training_completed_not_badged_strategy(trainee),
request=request,
person=trainee,
training_completed_date=event.end if event else None,
)
except EmailStrategyException as exc:
messages.error(
request,
"Error when running instructor training completed strategy."
f" {exc}",
)

except ValidationError as e:
unique_constraint_message = (
Expand Down

0 comments on commit 2760249

Please sign in to comment.