Skip to content

Commit

Permalink
Merge pull request #2529 from carpentries/feature/2526-instructor-tra…
Browse files Browse the repository at this point in the history
…ining-event-approaching-email

[Emails] Instructor training event approaching email
  • Loading branch information
pbanaszkiewicz authored Sep 28, 2023
2 parents 8b9e582 + 5d07457 commit 3dcd5d0
Show file tree
Hide file tree
Showing 28 changed files with 2,417 additions and 349 deletions.
248 changes: 0 additions & 248 deletions amy/emails/actions.py

This file was deleted.

20 changes: 20 additions & 0 deletions amy/emails/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# flake8: noqa
from emails.actions.admin_signs_instructor_up_for_workshop import (
admin_signs_instructor_up_for_workshop_receiver,
)
from emails.actions.instructor_badge_awarded import instructor_badge_awarded_receiver
from emails.actions.instructor_confirmed_for_workshop import (
instructor_confirmed_for_workshop_receiver,
)
from emails.actions.instructor_declined_from_workshop import (
instructor_declined_from_workshop_receiver,
)
from emails.actions.instructor_signs_up_for_workshop import (
instructor_signs_up_for_workshop_receiver,
)
from emails.actions.instructor_training_approaching import (
instructor_training_approaching_receiver,
instructor_training_approaching_remove_receiver,
instructor_training_approaching_update_receiver,
)
from emails.actions.persons_merged import persons_merged_receiver
58 changes: 58 additions & 0 deletions amy/emails/actions/admin_signs_instructor_up_for_workshop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import Any

from django.dispatch import receiver
from typing_extensions import Unpack

from emails.controller import EmailController, EmailControllerMissingRecipientsException
from emails.models import EmailTemplate
from emails.signals import admin_signs_instructor_up_for_workshop_signal
from emails.types import AdminSignsInstructorUpContext, AdminSignsInstructorUpKwargs
from emails.utils import (
immediate_action,
messages_action_scheduled,
messages_missing_recipients,
messages_missing_template,
person_from_request,
)
from recruitment.models import InstructorRecruitmentSignup
from workshops.models import Event, Person
from workshops.utils.feature_flags import feature_flag_enabled


@receiver(admin_signs_instructor_up_for_workshop_signal)
@feature_flag_enabled("EMAIL_MODULE")
def admin_signs_instructor_up_for_workshop_receiver(
sender: Any, **kwargs: Unpack[AdminSignsInstructorUpKwargs]
) -> None:
request = kwargs["request"]
person_id = kwargs["person_id"]
event_id = kwargs["event_id"]
instructor_recruitment_signup_id = kwargs["instructor_recruitment_signup_id"]

scheduled_at = immediate_action()
person = Person.objects.get(pk=person_id)
event = Event.objects.get(pk=event_id)
instructor_recruitment_signup = InstructorRecruitmentSignup.objects.get(
pk=instructor_recruitment_signup_id
)
context: AdminSignsInstructorUpContext = {
"person": person,
"event": event,
"instructor_recruitment_signup": instructor_recruitment_signup,
}
signal = admin_signs_instructor_up_for_workshop_signal.signal_name
try:
scheduled_email = EmailController.schedule_email(
signal=signal,
context=context,
scheduled_at=scheduled_at,
to_header=[person.email] if person.email else [],
generic_relation_obj=instructor_recruitment_signup,
author=person_from_request(request),
)
except EmailControllerMissingRecipientsException:
messages_missing_recipients(request, signal)
except EmailTemplate.DoesNotExist:
messages_missing_template(request, signal)
else:
messages_action_scheduled(request, signal, scheduled_email)
52 changes: 52 additions & 0 deletions amy/emails/actions/instructor_badge_awarded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import Any

from django.dispatch import receiver
from typing_extensions import Unpack

from emails.controller import EmailController, EmailControllerMissingRecipientsException
from emails.models import EmailTemplate
from emails.signals import instructor_badge_awarded_signal
from emails.types import InstructorBadgeAwardedContext, InstructorBadgeAwardedKwargs
from emails.utils import (
immediate_action,
messages_action_scheduled,
messages_missing_recipients,
messages_missing_template,
person_from_request,
)
from workshops.models import Award, Person
from workshops.utils.feature_flags import feature_flag_enabled


@receiver(instructor_badge_awarded_signal)
@feature_flag_enabled("EMAIL_MODULE")
def instructor_badge_awarded_receiver(
sender: Any, **kwargs: Unpack[InstructorBadgeAwardedKwargs]
) -> None:
request = kwargs["request"]
person_id = kwargs["person_id"]
award_id = kwargs["award_id"]

scheduled_at = immediate_action()
person = Person.objects.get(pk=person_id)
award = Award.objects.get(pk=award_id)
context: InstructorBadgeAwardedContext = {
"person": person,
"award": award,
}
signal = instructor_badge_awarded_signal.signal_name
try:
scheduled_email = EmailController.schedule_email(
signal=signal,
context=context,
scheduled_at=scheduled_at,
to_header=[person.email] if person.email else [],
generic_relation_obj=award,
author=person_from_request(request),
)
except EmailControllerMissingRecipientsException:
messages_missing_recipients(request, signal)
except EmailTemplate.DoesNotExist:
messages_missing_template(request, signal)
else:
messages_action_scheduled(request, signal, scheduled_email)
Loading

0 comments on commit 3dcd5d0

Please sign in to comment.