diff --git a/shiftregister/fallback/urls.py b/shiftregister/fallback/urls.py index d6afee1..6df05e2 100644 --- a/shiftregister/fallback/urls.py +++ b/shiftregister/fallback/urls.py @@ -8,4 +8,5 @@ urlpatterns = [ views.my_fallback_shifts, name="my_fallback_shifts", ), + path("members/", views.team_members, name="team_members"), ] diff --git a/shiftregister/fallback/views.py b/shiftregister/fallback/views.py index fe6925c..7a95420 100644 --- a/shiftregister/fallback/views.py +++ b/shiftregister/fallback/views.py @@ -1,4 +1,7 @@ from base64 import urlsafe_b64decode +from django.contrib.auth.decorators import login_required +from django.db.models import Count +from django.http import HttpResponse from django.shortcuts import render, get_object_or_404 from shiftregister.fallback.models import TeamMember @@ -26,3 +29,18 @@ def my_fallback_shifts(request, team_member_id): "is_draw": is_draw, } return render(request, "my_fallback_shifts.html", context) + + +@login_required +def team_members(request): + response = HttpResponse( + "\n".join( + f"{member.name} {member.url()}" + for member in TeamMember.objects.annotate( + shift_count=Count("fallback_shifts") + ).filter(fallback_shifts__gt=0) + ) + ) + response.headers["Content-Type"] = "text/plain; charset=utf-8" + + return response