Let eligible referees self-serve sign-up for games needing one
Creating (or re-teaming) a home game for a club-managed team now auto- invites every eligible referee (teams.RefereeProfile) via a new RefereeSignup model, notifying them the same way news/events already do. They see it as its own distinct row on the mobile Calendar (own accent colour) and can accept or decline right there -- accepting routes through the existing capacity-checked assign_referee (assigned_by=None marks it self-service), so it lands as a real EventReferee row with no separate sync step. The desktop referee-management screen and event detail page both surface pending invites and flag self-signed-up referees distinctly from admin assignments. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ECGMEwrc2k4D8VQuwjstj9
This commit is contained in:
@@ -3,8 +3,16 @@
|
||||
Shared by the event detail page and the referee management dashboard --
|
||||
context: event, referees (EventReferee rows -- fee/km/km_rate read straight
|
||||
off the model instance, no separate form object needed), referee_candidates,
|
||||
referees_full, can_manage_referees, and an optional next_url to return to
|
||||
after a POST (defaults to the event detail page when blank).
|
||||
referees_full, pending_signups (RefereeSignup rows still INVITED -- the
|
||||
self-service counterpart, events.services.referees.sync_referee_invites/
|
||||
accept_referee_signup), can_manage_referees, and an optional next_url to
|
||||
return to after a POST (defaults to the event detail page when blank).
|
||||
|
||||
A referee row with no assigned_by (events.services.referees.
|
||||
accept_referee_signup passes assigned_by=None) is one who signed
|
||||
themselves up rather than one an admin picked -- flagged "Self sign-up"
|
||||
instead of "Assigned by ..." so that stays visible here without a
|
||||
separate screen.
|
||||
|
||||
The fee is entered right here, inline, rather than behind a "Fee" button
|
||||
that opened a second (and on the dashboard, nested-inside-a-dialog) modal
|
||||
@@ -33,7 +41,11 @@
|
||||
{% if referee.is_external %}<span class="badge badge-neutral badge-xs">{% trans "External" %}</span>{% endif %}
|
||||
{% if can_manage_referees and not referee.fee %}<span class="badge badge-warning badge-xs">{% trans "Fee not set" %}</span>{% endif %}
|
||||
</div>
|
||||
{% if referee.assigned_by %}<span class="text-xs text-muted">{% blocktrans with name=referee.assigned_by %}Assigned by {{ name }}{% endblocktrans %}</span>{% endif %}
|
||||
{% if referee.assigned_by %}
|
||||
<span class="text-xs text-muted">{% blocktrans with name=referee.assigned_by %}Assigned by {{ name }}{% endblocktrans %}</span>
|
||||
{% elif not referee.is_external %}
|
||||
<span class="badge badge-outline badge-xs w-fit">{% trans "Self sign-up" %}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if can_manage_referees %}
|
||||
@@ -76,6 +88,13 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if pending_signups %}
|
||||
<p class="mt-2 text-xs text-muted">
|
||||
{% blocktrans count counter=pending_signups|length %}Invited, no response yet: {% plural %}Invited, no response yet: {% endblocktrans %}
|
||||
{% for signup in pending_signups %}{{ signup.member }}{% if not forloop.last %}, {% endif %}{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if can_manage_referees and not referees_full %}
|
||||
<div class="mt-3 flex flex-col gap-2 border-t border-rule pt-3">
|
||||
<span class="font-mono text-[11px] tracking-[.08em] text-dim uppercase">{% trans "Add a referee" %}</span>
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
{% if game.opponent %}{% trans "vs" %} {{ game.opponent }}{% endif %}
|
||||
</h3>
|
||||
<div class="mb-4 font-mono text-sm text-muted">{{ game.start|date:"j M Y H:i" }}</div>
|
||||
{% include "management/_referee_assignment_panel.html" with event=game referees=game.referee_rows referee_candidates=game.referee_candidates referees_full=game.referees_full can_manage_referees=True next_url=request.get_full_path %}
|
||||
{% include "management/_referee_assignment_panel.html" with event=game referees=game.referee_rows referee_candidates=game.referee_candidates referees_full=game.referees_full pending_signups=game.pending_signups can_manage_referees=True next_url=request.get_full_path %}
|
||||
</div>
|
||||
<form method="dialog" class="modal-backdrop"><button>close</button></form>
|
||||
</dialog>
|
||||
|
||||
@@ -23,7 +23,7 @@ from billing.services.dues import record_payment, subscribe
|
||||
from club.models import Club, ClubMembership, ClubRole, DuesInvoice, FeePayment, MemberRequirementStatus, OnboardingRequirement, Season, Sponsor
|
||||
from club.services.invoicing import DuesInvoicePDFError
|
||||
from club.services.onboarding import mark_complete
|
||||
from events.models import Attendance, Competition, Event, EventReferee, EventSeries, Location, Opponent
|
||||
from events.models import Attendance, Competition, Event, EventReferee, EventSeries, Location, Opponent, RefereeSignup
|
||||
from events.services.rbihf_import import RBIHFImportError
|
||||
from events.services.recurrence import detach_occurrence, generate_occurrences
|
||||
from management.bulk_import import TEMPLATE_COLUMNS
|
||||
@@ -6554,6 +6554,39 @@ class RefereeManagementDashboardTests(ManagementTestBase):
|
||||
|
||||
self.assertRedirects(response, reverse("management:event_detail", args=[game.pk]))
|
||||
|
||||
def test_shows_a_pending_self_service_invite(self):
|
||||
# make_game()'s own event.teams.add(...) already triggers
|
||||
# events.services.referees.sync_referee_invites via events/signals.py --
|
||||
# self.referee (eligible for self.team) gets invited automatically.
|
||||
game = self.make_game()
|
||||
self.client.force_login(self.admin_user)
|
||||
|
||||
response = self.club_get("referee_management")
|
||||
|
||||
self.assertTrue(RefereeSignup.objects.filter(event=game, member=self.referee, status=RefereeSignup.Status.INVITED).exists())
|
||||
self.assertContains(response, "Invited, no response yet")
|
||||
self.assertContains(response, str(self.referee))
|
||||
|
||||
def test_no_pending_invite_shown_once_the_game_is_full(self):
|
||||
game = self.make_game(max_referees=1)
|
||||
EventReferee.objects.create(event=game, member=self.referee, assigned_by=self.admin_member)
|
||||
other_referee = Member.objects.create(first_name="Other", last_name="Ref")
|
||||
RefereeSignup.objects.create(event=game, member=other_referee, status=RefereeSignup.Status.INVITED)
|
||||
self.client.force_login(self.admin_user)
|
||||
|
||||
response = self.club_get("referee_management")
|
||||
|
||||
self.assertNotContains(response, "Invited, no response yet")
|
||||
|
||||
def test_self_signed_up_referee_is_flagged_distinctly_from_an_admin_assignment(self):
|
||||
game = self.make_game()
|
||||
EventReferee.objects.create(event=game, member=self.referee, assigned_by=None)
|
||||
self.client.force_login(self.admin_user)
|
||||
|
||||
response = self.club_get("referee_management")
|
||||
|
||||
self.assertContains(response, "Self sign-up")
|
||||
|
||||
|
||||
class FeatureGatedSectionsTests(ManagementTestBase):
|
||||
"""The Shop and Forms sections are still stubs (StubListMixin) and, on top
|
||||
|
||||
@@ -35,7 +35,7 @@ from club.services.onboarding import annotate_onboarding_status, approve_all_cle
|
||||
from controlpanel.messages import notify
|
||||
from controlpanel.mixins import RedirectOnInvalidMixin
|
||||
from controlpanel.services.statistics import club_attention, club_charts, club_statistics, unrostered_members
|
||||
from events.models import Attendance, Event, EventReferee, EventSeries, Location, Opponent
|
||||
from events.models import Attendance, Event, EventReferee, EventSeries, Location, Opponent, RefereeSignup
|
||||
from events.services.attendance import member_attendance_counts, member_attendance_sparkline, player_attendance_rankings, players_who_missed_recent_practices, team_attendance_rate, team_no_shows
|
||||
from events.services.calendar import add_months, month_bounds, month_grid, season_grid, week_bounds, week_grid
|
||||
from events.services.competitions import CompetitionFetchError, fetch_game_info
|
||||
@@ -2501,6 +2501,7 @@ class EventDetailView(ClubStaffRequiredMixin, DetailView):
|
||||
referees = []
|
||||
referee_candidates = []
|
||||
referees_full = False
|
||||
pending_signups = []
|
||||
if referee_management_needed:
|
||||
referees = list(event.referees.select_related("member", "assigned_by").order_by("member__last_name", "member__first_name"))
|
||||
referees_full = len(referees) >= event.max_referees
|
||||
@@ -2510,6 +2511,8 @@ class EventDetailView(ClubStaffRequiredMixin, DetailView):
|
||||
candidate.has_conflict = bool(conflicts)
|
||||
candidate.conflict_titles = ", ".join(conflict.title for conflict in conflicts)
|
||||
referee_candidates.append(candidate)
|
||||
if can_manage_referees:
|
||||
pending_signups = list(event.referee_signups.filter(status=RefereeSignup.Status.INVITED).select_related("member"))
|
||||
|
||||
return super().get_context_data(
|
||||
can_manage=can_manage,
|
||||
@@ -2521,6 +2524,7 @@ class EventDetailView(ClubStaffRequiredMixin, DetailView):
|
||||
referees=referees,
|
||||
referee_candidates=referee_candidates,
|
||||
referees_full=referees_full,
|
||||
pending_signups=pending_signups,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@@ -2745,6 +2749,7 @@ class RefereeManagementDashboardView(MemberAdminRequiredMixin, TemplateView):
|
||||
game.referees_full = len(game.referee_rows) >= game.max_referees
|
||||
game.referee_candidates = []
|
||||
game.fees_pending = any(not referee.fee for referee in game.referee_rows)
|
||||
game.pending_signups = list(game.referee_signups.filter(status=RefereeSignup.Status.INVITED).select_related("member")) if not game.referees_full else []
|
||||
if not game.referee_rows:
|
||||
kpi_no_referee += 1
|
||||
elif not game.referees_full:
|
||||
|
||||
Reference in New Issue
Block a user