-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2529 from carpentries/feature/2526-instructor-tra…
…ining-event-approaching-email [Emails] Instructor training event approaching email
- Loading branch information
Showing
28 changed files
with
2,417 additions
and
349 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
amy/emails/actions/admin_signs_instructor_up_for_workshop.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.