-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added flying members registration reminder mail. * Added translation to flying members reminder mail. Added feature flag. * Translation file update after merge from master. * Updated description of the mail. * Only consider some attendance states in is_member_registered_to_a_shift_this_cycle * Fixed test name
- Loading branch information
1 parent
0070075
commit 86d9650
Showing
12 changed files
with
613 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
51 changes: 51 additions & 0 deletions
51
tapir/shifts/emails/flying_member_registration_reminder_email.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,51 @@ | ||
from typing import List | ||
|
||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from tapir.coop.models import ShareOwner | ||
from tapir.core.tapir_email_base import TapirEmailBase | ||
from tapir.shifts import config | ||
|
||
|
||
class FlyingMemberRegistrationReminderEmail(TapirEmailBase): | ||
@classmethod | ||
def get_unique_id(cls) -> str: | ||
return "tapir.shifts.flying_member_registration_reminder_email" | ||
|
||
@classmethod | ||
def get_name(cls) -> str: | ||
return _("Flying member registration reminder") | ||
|
||
@classmethod | ||
def get_description(cls) -> str: | ||
return _( | ||
"Sent to flying members %(nb_days)s days after a cycle has begun, if they haven't registered to a shift for this cycle." | ||
% { | ||
"nb_days": config.FLYING_MEMBERS_REGISTRATION_REMINDER_DAYS_AFTER_CYCLE_START | ||
} | ||
) | ||
|
||
def get_subject_templates(self) -> List: | ||
return [ | ||
"shifts/email/flying_member_registration_reminder_email.subject.html", | ||
] | ||
|
||
def get_body_templates(self) -> List: | ||
return [ | ||
"shifts/email/flying_member_registration_reminder_email.body.html", | ||
] | ||
|
||
@classmethod | ||
def get_dummy_version(cls) -> TapirEmailBase | None: | ||
share_owner = ( | ||
ShareOwner.objects.filter(user__isnull=False).order_by("?").first() | ||
) | ||
if not share_owner: | ||
return None | ||
mail = cls() | ||
mail.get_full_context( | ||
share_owner=share_owner, | ||
member_infos=share_owner.get_info(), | ||
tapir_user=share_owner.user, | ||
) | ||
return mail |
85 changes: 85 additions & 0 deletions
85
tapir/shifts/management/commands/send_flying_member_registration_reminder_mails.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,85 @@ | ||
import datetime | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
from tapir.core.models import FeatureFlag | ||
from tapir.log.models import EmailLogEntry | ||
from tapir.shifts.config import FEATURE_FLAG_FLYING_MEMBERS_REGISTRATION_REMINDER | ||
from tapir.shifts.emails.flying_member_registration_reminder_email import ( | ||
FlyingMemberRegistrationReminderEmail, | ||
) | ||
from tapir.shifts.models import ( | ||
ShiftUserData, | ||
ShiftAttendanceMode, | ||
ShiftCycleEntry, | ||
ShiftAttendance, | ||
) | ||
from tapir.shifts.services.shift_cycle_service import ShiftCycleService | ||
from tapir.shifts.services.shift_expectation_service import ShiftExpectationService | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Send FlyingMemberRegistrationReminderEmail if necessary." | ||
|
||
def handle(self, *args, **options): | ||
if not FeatureFlag.get_flag_value( | ||
FEATURE_FLAG_FLYING_MEMBERS_REGISTRATION_REMINDER | ||
): | ||
return | ||
|
||
start_date = ShiftCycleService.get_start_date_of_current_cycle() | ||
end_date = start_date + datetime.timedelta( | ||
days=ShiftCycleEntry.SHIFT_CYCLE_DURATION | ||
) | ||
if timezone.now().date() > end_date - datetime.timedelta(days=7): | ||
# Don't send mails if the cycle is about to end | ||
return | ||
|
||
flying_members = ShiftUserData.objects.filter( | ||
attendance_mode=ShiftAttendanceMode.FLYING | ||
) | ||
for shift_user_data in flying_members: | ||
if not self.should_member_receive_reminder_mail( | ||
shift_user_data, start_date | ||
): | ||
continue | ||
FlyingMemberRegistrationReminderEmail().send_to_tapir_user( | ||
actor=None, recipient=shift_user_data.user | ||
) | ||
|
||
@classmethod | ||
def should_member_receive_reminder_mail(cls, shift_user_data, start_date): | ||
if not ShiftExpectationService.is_member_expected_to_do_shifts(shift_user_data): | ||
return False | ||
if cls.has_user_received_reminder_this_cycle(shift_user_data, start_date): | ||
return False | ||
if cls.is_member_registered_to_a_shift_this_cycle(shift_user_data, start_date): | ||
return False | ||
return True | ||
|
||
@staticmethod | ||
def has_user_received_reminder_this_cycle( | ||
shift_user_data: ShiftUserData, cycle_start_date: datetime.date | ||
): | ||
cycle_end_date = cycle_start_date + datetime.timedelta( | ||
days=ShiftCycleEntry.SHIFT_CYCLE_DURATION | ||
) | ||
return EmailLogEntry.objects.filter( | ||
email_id=FlyingMemberRegistrationReminderEmail.get_unique_id(), | ||
user=shift_user_data.user, | ||
created_date__gte=cycle_start_date, | ||
created_date__lte=cycle_end_date, | ||
).exists() | ||
|
||
@staticmethod | ||
def is_member_registered_to_a_shift_this_cycle( | ||
shift_user_data: ShiftUserData, cycle_start_date: datetime.date | ||
): | ||
return ShiftAttendance.objects.filter( | ||
user=shift_user_data.user, | ||
slot__shift__start_time__date__gte=cycle_start_date, | ||
slot__shift__start_time__date__lt=cycle_start_date | ||
+ datetime.timedelta(days=ShiftCycleEntry.SHIFT_CYCLE_DURATION), | ||
state__in=ShiftAttendance.VALID_STATES, | ||
).exists() |
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
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
27 changes: 27 additions & 0 deletions
27
tapir/shifts/templates/shifts/email/flying_member_registration_reminder_email.body.html
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,27 @@ | ||
{% extends "core/email_base.html" %} | ||
{% load i18n %} | ||
{% load utils %} | ||
{% block body %} | ||
{% get_display_name_short member_infos as display_name_short %} | ||
{% blocktranslate with display_name_short=display_name_short %} | ||
<p>Hi {{ display_name_short }},</p> | ||
|
||
<p> | ||
we would like to remind you about your next <a href="https://members.supercoop.de/shifts/calendar">shift | ||
registration</a>. | ||
</p> | ||
<p> | ||
A new shift cycle has been running for a week and we have noticed | ||
that you have not yet registered for a suitable shift. As a flying member, | ||
unlike members with a regular ABCD shift, you have to take care of this yourself every four weeks. | ||
</p> | ||
<p> | ||
So take a look at the <a href="https://members.supercoop.de/shifts/calendar">shift calendar on Tapir</a> | ||
and register for one of the shifts highlighted in blue - this is where the most support is currently needed. | ||
</p> | ||
<p> | ||
Cooperative greetings,<br /> | ||
The Member Office | ||
</p> | ||
{% endblocktranslate %} | ||
{% endblock body %} |
2 changes: 2 additions & 0 deletions
2
tapir/shifts/templates/shifts/email/flying_member_registration_reminder_email.subject.html
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,2 @@ | ||
{% load i18n %} | ||
{% translate "Sign up for your next SuperCoop shift" %} |
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
Oops, something went wrong.