Skip to content

Commit 275f429

Browse files
committed
chore: rename mandatory to optional
1 parent 9cf570a commit 275f429

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

tapir/accounts/forms.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
class TapirUserSelfUpdateForm(forms.ModelForm):
1717
mandatory_mails = forms.MultipleChoiceField(
1818
required=False,
19-
choices=get_mail_types(enabled_by_default="both", mandatory=True),
19+
choices=get_mail_types(enabled_by_default="both", optional=False),
2020
label=_("Mandatory Emails"),
2121
widget=CheckboxSelectMultiple(),
2222
initial=[
23-
m[0] for m in get_mail_types(enabled_by_default="both", mandatory=True)
23+
m[0] for m in get_mail_types(enabled_by_default="both", optional=False)
2424
],
2525
)
2626

@@ -33,7 +33,7 @@ class Meta:
3333
fields = ["usage_name", "pronouns", "optional_mails"]
3434
widgets = {
3535
"optional_mails": forms.widgets.CheckboxSelectMultiple(
36-
choices=get_mail_types(enabled_by_default="both", mandatory=False)
36+
choices=get_mail_types(enabled_by_default="both", optional=True)
3737
)
3838
}
3939

tapir/accounts/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TapirUserManager(UserManager.from_queryset(TapirUserQuerySet)):
6262

6363

6464
def get_optional_mails_enabledbydefault():
65-
return [m[0] for m in get_mail_types(mandatory=False, enabled_by_default=True)]
65+
return [m[0] for m in get_mail_types(optional=True, enabled_by_default=True)]
6666

6767

6868
class TapirUser(AbstractUser):

tapir/core/tapir_email_base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
def get_mail_types(
2424
enabled_by_default: MAIL_OPTIONS_ = True,
25-
mandatory: MAIL_OPTIONS_ = True,
25+
optional: MAIL_OPTIONS_ = True,
2626
) -> List[Tuple[str, str]]:
2727
"""
2828
default="both" returns both, default and non-default mails.
@@ -33,7 +33,7 @@ def filter_mail(mail):
3333
return (
3434
enabled_by_default == "both"
3535
or mail.enabled_by_default is enabled_by_default
36-
) and (mandatory == "both" or mail.mandatory is mandatory)
36+
) and (optional == "both" or mail.optional is optional)
3737

3838
return [
3939
(mail.get_unique_id(), mail.get_name())
@@ -43,12 +43,12 @@ def filter_mail(mail):
4343

4444

4545
def get_optional_mails() -> List[Tuple[str, str]]:
46-
return get_mail_types(mandatory=False, enabled_by_default="both")
46+
return get_mail_types(optional=True, enabled_by_default="both")
4747

4848

4949
class TapirEmailBase:
5050
enabled_by_default = True # mails are opt-out by default
51-
mandatory = True # mails are mandatory by default
51+
optional = False # mails are mandatory by default
5252

5353
class Meta:
5454
abstract = True
@@ -134,7 +134,7 @@ def send_to_share_owner(self, actor: User | None, recipient: ShareOwner):
134134

135135
def user_wants_to_or_has_to_receive_mail(self, user: TapirUser):
136136
return (self.get_unique_id() in user.optional_mails) | (
137-
self.get_unique_id() in [x[0] for x in get_mail_types(mandatory=True)]
137+
self.get_unique_id() in [x[0] for x in get_mail_types(optional=False)]
138138
)
139139

140140
def send_to_tapir_user(self, actor: User | None, recipient: TapirUser):

tapir/core/tests/test_email_preferences.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class VoluntaryMail(TapirEmailBase):
9-
mandatory = False
9+
optional = True
1010

1111
@classmethod
1212
def get_unique_id(cls) -> str:
@@ -41,8 +41,8 @@ def test_userWantsToOrHasToReceiveMail_mailSubscribedTo_shouldReceiveMail(self):
4141

4242
def test_userWantsToOrHasToReceiveMail_mailIsMandatory_shouldReceiveMail(self):
4343
tapir_user: TapirUser = TapirUserFactory.create()
44-
self.assertTrue(
45-
TapirAccountCreatedEmail.mandatory
44+
self.assertFalse(
45+
TapirAccountCreatedEmail.optional
4646
) # change to another mail-type if necessary
4747

4848
self.assertTrue(

tapir/shifts/emails/shift_reminder_email.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class ShiftReminderEmail(TapirEmailBase):
12-
mandatory = False
12+
optional = True
1313
enabled_by_default = True
1414

1515
def __init__(self, shift):

0 commit comments

Comments
 (0)