-
Notifications
You must be signed in to change notification settings - Fork 31
feat: #704 extend shareowner view with capability experience filter #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -631,6 +631,14 @@ def __init__(self, *args, **kwargs): | |
| method="has_capability_filter", | ||
| label=_("Has qualification"), | ||
| ) | ||
| has_recent_capability_experience = ChoiceFilter( | ||
| choices=[ | ||
| (capability, capability_name) | ||
| for capability, capability_name in SHIFT_USER_CAPABILITY_CHOICES.items() | ||
| ], | ||
| method="has_recent_capability_experience_filter", | ||
| label=_("Has completed a shift with this qualification in the last 6 months"), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
| ) | ||
| not_has_capability = ChoiceFilter( | ||
| choices=[ | ||
| (capability, capability_name) | ||
|
|
@@ -734,6 +742,14 @@ def has_capability_filter( | |
| user__in=TapirUser.objects.has_capability(value) | ||
| ).distinct() | ||
|
|
||
| @staticmethod | ||
| def has_recent_capability_experience_filter( | ||
| queryset: ShareOwner.ShareOwnerQuerySet, name, value: str | ||
| ): | ||
| return queryset.filter( | ||
| user__in=TapirUser.objects.has_recent_capability_experience(value) | ||
| ).distinct() | ||
|
|
||
| @staticmethod | ||
| def not_has_capability_filter( | ||
| queryset: ShareOwner.ShareOwnerQuerySet, name, value: str | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from calendar import HTMLCalendar, month_name, day_abbr | ||
| from datetime import datetime, date | ||
| from datetime import datetime, date, timedelta | ||
|
|
||
| from django.utils import timezone | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
@@ -145,6 +145,21 @@ def get_ids_of_users_registered_to_a_shift_with_capability( | |
| ) | ||
|
|
||
|
|
||
| def get_ids_of_users_recently_completed_a_shift_with_capability( | ||
| capability: ShiftUserCapability, | ||
| ): | ||
| six_months_ago = timezone.now().date() - timedelta(weeks=26) | ||
| return ( | ||
| ShiftAttendance.objects.filter( | ||
| slot__required_capabilities__contains=[capability], | ||
| state__in=[ShiftAttendance.State.DONE], | ||
| slot__shift__start_time__gt=six_months_ago, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick, but I would include the day and use gte, so you really have 6 months. |
||
| ) | ||
| .distinct() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove |
||
| .values_list("user__id", flat=True) | ||
| ) | ||
|
|
||
|
|
||
| def get_attendance_mode_display(attendance_mode: str) -> str: | ||
| for mode_choice in SHIFT_ATTENDANCE_MODE_CHOICES: | ||
| if mode_choice[0] == attendance_mode: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I continued with this hack for now, otherwise I think #704 will grow into a non-beginner-friendly task :)
happy to refactor this, if you have ideas and can guide me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a suggestion? I'm no big backend expert