Skip to content

Commit

Permalink
[#2540] Add ungraded requirements to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
pbanaszkiewicz committed Nov 7, 2023
1 parent 4577c28 commit f18c4b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
12 changes: 9 additions & 3 deletions amy/emails/actions/instructor_training_completed_not_badged.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
StrategyEnum,
)
from emails.utils import two_months_after
from workshops.models import Person, TrainingProgress
from workshops.models import Person, TrainingProgress, TrainingRequirement

from .instructor_training_approaching import EmailStrategyException

Expand Down Expand Up @@ -154,15 +154,21 @@ def get_context(
passed_requirements = list(
TrainingProgress.objects.filter(trainee=person, state="p")
)
missing_requirements = list(
not_passed_requirements = list(
TrainingProgress.objects.filter(trainee=person).exclude(state="p")
)
not_graded_requirements = list(
TrainingRequirement.objects.filter(
name__in=["Training", "Get Involved", "Welcome Session", "Demo"]
).exclude(trainingprogress__trainee=person)
)
training_completed_date = kwargs["training_completed_date"]

return {
"person": person,
"passed_requirements": passed_requirements,
"missing_requirements": missing_requirements,
"not_passed_requirements": not_passed_requirements,
"not_graded_requirements": not_graded_requirements,
"training_completed_date": training_completed_date,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@

class TestInstructorTrainingCompletedNotBadgedCommonFunctions(TestCase):
def setUpTrainingProgresses(self, person: Person) -> None:
requirements = TrainingRequirement.objects.all() # should be 4 of them
self.requirements = TrainingRequirement.objects.filter(
name__in=["Training", "Get Involved", "Welcome Session", "Demo"]
)
self.progresses = [
TrainingProgress(state="p", trainee=person, requirement=requirements[0]),
TrainingProgress(state="f", trainee=person, requirement=requirements[1]),
TrainingProgress(state="f", trainee=person, requirement=requirements[2]),
TrainingProgress(state="p", trainee=person, requirement=requirements[3]),
TrainingProgress(
state="p", trainee=person, requirement=self.requirements[0]
),
TrainingProgress(
state="f", trainee=person, requirement=self.requirements[1]
),
TrainingProgress(
state="a", trainee=person, requirement=self.requirements[2]
),
# Last requirement is left ungraded.
# TrainingProgress(state="p", trainee=person, requirement=requirements[3]),
]
TrainingProgress.objects.bulk_create(self.progresses)

Expand All @@ -29,8 +38,9 @@ def setUpContext(
) -> InstructorTrainingCompletedNotBadgedContext:
return {
"person": person,
"passed_requirements": [self.progresses[0], self.progresses[3]],
"missing_requirements": [self.progresses[1], self.progresses[2]],
"passed_requirements": [self.progresses[0]],
"not_passed_requirements": [self.progresses[1], self.progresses[2]],
"not_graded_requirements": [self.requirements[3]],
"training_completed_date": training_completed_date,
}

Expand Down Expand Up @@ -71,8 +81,9 @@ def test_get_context(self) -> None:
context,
{
"person": person,
"passed_requirements": [self.progresses[0], self.progresses[3]],
"missing_requirements": [self.progresses[1], self.progresses[2]],
"passed_requirements": [self.progresses[0]],
"not_passed_requirements": [self.progresses[1], self.progresses[2]],
"not_graded_requirements": [self.requirements[3]],
"training_completed_date": training_completed_date,
},
)
Expand Down
5 changes: 3 additions & 2 deletions amy/emails/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.http import HttpRequest

from recruitment.models import InstructorRecruitmentSignup
from workshops.models import Award, Event, Person, TrainingProgress
from workshops.models import Award, Event, Person, TrainingProgress, TrainingRequirement


class InstructorBadgeAwardedKwargs(TypedDict):
Expand Down Expand Up @@ -106,7 +106,8 @@ class InstructorTrainingCompletedNotBadgedKwargs(TypedDict):
class InstructorTrainingCompletedNotBadgedContext(TypedDict):
person: Person
passed_requirements: list[TrainingProgress]
missing_requirements: list[TrainingProgress]
not_passed_requirements: list[TrainingProgress]
not_graded_requirements: list[TrainingRequirement]
training_completed_date: date


Expand Down

0 comments on commit f18c4b1

Please sign in to comment.