Skip to content

Commit

Permalink
Shift-type-filter on member page (#471)
Browse files Browse the repository at this point in the history
* get ShiftTemplateGroup from

* filter for next shifts

* translation Schicht-Typ

* test for filter of shift types
  • Loading branch information
crosspolar authored Dec 29, 2023
1 parent 7ff3fbc commit 9aac610
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
38 changes: 37 additions & 1 deletion tapir/coop/tests/test_share_owner_list_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,40 @@ def create_incoming_payment(member: ShareOwner, amount) -> IncomingPayment:
created_by=TapirUserFactory.create(is_in_member_office=True),
)

def test_filter_for_shift_type(self):
user_shiftname_dict = {}
for _ in range(2):
shift_template = ShiftTemplateFactory.create(nb_slots=0)
for shift_slot_name in ["ShiftSlotTest1", "ShiftSlotTest2"]:
# Create slots for that shift
shift_slot_template = ShiftSlotTemplate.objects.create(
name=shift_slot_name,
shift_template=shift_template,
)
user = TapirUserFactory.create()
ShiftAttendanceTemplate.objects.create(
user=user,
slot_template=shift_slot_template,
)
user_shiftname_dict[user.share_owner] = shift_slot_name

first_shift_slot_name = user_shiftname_dict[next(iter(user_shiftname_dict))]
all_users_of_with_same_shift_slot = [
key
for key, value in user_shiftname_dict.items()
if value == first_shift_slot_name
]
all_users_of_other_same_shift_slot = [
key
for key, value in user_shiftname_dict.items()
if value != first_shift_slot_name
]
self.visit_view(
{"shift_slot_name": first_shift_slot_name},
must_be_in=all_users_of_with_same_shift_slot,
must_be_out=all_users_of_other_same_shift_slot,
)

def test_abcd_week(self):
for name in ["A", "B"]:
ShiftTemplateGroup.objects.create(name=name)
Expand Down Expand Up @@ -236,7 +270,9 @@ def test_attended_welcome_session(self):
must_be_out=owners_who_did_not_attend,
)

def visit_view(self, params: dict, must_be_in, must_be_out):
def visit_view(
self, params: dict, must_be_in: list[ShareOwner], must_be_out: list[ShareOwner]
):
self.login_as_member_office_user()

query_dictionary = QueryDict("", mutable=True)
Expand Down
31 changes: 28 additions & 3 deletions tapir/coop/views/shareowner.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
ShiftUserData,
SHIFT_USER_CAPABILITY_CHOICES,
ShiftExemption,
ShiftTemplateGroup,
ShiftSlotTemplate,
)
from tapir.utils.models import copy_user_info
from tapir.utils.shortcuts import set_header_for_file_download
Expand Down Expand Up @@ -595,6 +597,20 @@ class Meta:
"is_company",
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# initiate after database has been initiated
self.filters["abcd_week"].extra.update(
{"choices": list(ShiftTemplateGroup.objects.values_list("name", "name"))}
)
self.filters["shift_slot_name"].extra.update(
{
"choices": list(
ShiftSlotTemplate.objects.values_list("name", "name").distinct()
)
}
)

status = ChoiceFilter(
choices=MEMBER_STATUS_CHOICES,
method="status_filter",
Expand Down Expand Up @@ -641,10 +657,7 @@ class Meta:
has_tapir_account = BooleanFilter(
method="has_tapir_account_filter", label="Has a Tapir account"
)
# Théo 17.09.21 : It would be nicer to get the values from the DB, but that raises exceptions
# when creating a brand new docker instance, because the corresponding table doesn't exist yet.
abcd_week = ChoiceFilter(
choices=[("A", "A"), ("B", "B"), ("C", "C"), ("D", "D")],
method="abcd_week_filter",
label=_("ABCD Week"),
)
Expand All @@ -661,6 +674,18 @@ class Meta:
method="is_currently_exempted_from_shifts_filter",
label=_("Is currently exempted from shifts"),
)
shift_slot_name = ChoiceFilter(
choices=[],
method="shift_slot_filter",
label=_("Shift Type"),
)

@staticmethod
def shift_slot_filter(queryset: ShareOwner.ShareOwnerQuerySet, name, value: str):
return queryset.filter(
# Find all Tapir-Users currently enrolled in that shift-name "value"
user__in=TapirUser.objects.registered_to_shift_slot_name(value)
).distinct()

@staticmethod
def display_name_filter(queryset: ShareOwner.ShareOwnerQuerySet, name, value: str):
Expand Down
8 changes: 7 additions & 1 deletion tapir/translations/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,13 @@ msgstr "Name oder Mitgliedsnummer"
msgid "Is currently exempted from shifts"
msgstr "Ist derzeit von der Schichtarbeit befreit"

#: coop/views/shareowner.py:881
#: tapir/coop/views/shareowner.py:680
#, fuzzy
#| msgid "Shift exemptions"
msgid "Shift Type"
msgstr "Schicht-Typ"

#: tapir/coop/views/shareowner.py:906
msgctxt "Willing to give a share"
msgid "No"
msgstr "Nein"
Expand Down

0 comments on commit 9aac610

Please sign in to comment.