Rework Teams/Positions access control and add full Locations/Opponents CRUD

Team managers/coaches now only see their own teams, can't create teams,
and can view (but not edit) positions -- admins keep full rights.
Locations and Opponents move from read-only stubs to full CRUD, gated
to admins and management-position staff, with a country dropdown
(django-countries) instead of free text. Also: the team list shows
player/staff counts, and deleting a news item's main photo promotes
another one instead of leaving the item without one.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R1gj3J1QPfP38XWpnpbFpy
This commit is contained in:
2026-08-04 12:27:24 +02:00
parent 9a4da9b136
commit e6850232f0
23 changed files with 813 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from club.models import ClubMembership, ClubRole, FeePayment
from events.models import Location, Opponent
from members.models import Family, FamilyMembership, Member
from members.services.family import find_member_by_email
from news.models import News
@@ -97,6 +98,25 @@ class PositionForm(forms.ModelForm):
return cleaned
class LocationForm(forms.ModelForm):
class Meta:
model = Location
fields = ["name", "address", "city", "zip_code", "country"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# CountryField's own widget (a lazily-translated Select) must stay the widget
# class -- only the searchable-select JS hooks are added on top of it, the
# same progressive enhancement TeamMembershipForm uses for its member field.
self.fields["country"].widget.attrs.update({"data-searchable": "true", "data-search-placeholder": _("Type a country to search...")})
class OpponentForm(forms.ModelForm):
class Meta:
model = Opponent
fields = ["name", "logo"]
class ClubRoleAssignForm(forms.ModelForm):
"""Grant a club-wide role to a member already affiliated with this club."""