From 68cad0c951ba52b398cc36c6034f36d67920695b Mon Sep 17 00:00:00 2001 From: Bernard Siebens Date: Tue, 4 Aug 2026 12:27:48 +0200 Subject: [PATCH] Add a home-location box to the club detail page in the control panel Setting a club's home ground here creates/updates the same events.Location row (flagged is_home) that the club's own Teams > Locations page shows and edits -- no separate sync step, it's the same record either way. Also fixes the shared form_field templatetag: django-countries' CountryField widget reports as "lazyselect", which fell through to a broken plain text input instead of rendering as a dropdown. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01R1gj3J1QPfP38XWpnpbFpy --- controlpanel/forms.py | 16 +++++ .../_club_home_location_card.html | 39 +++++++++++ .../templates/controlpanel/club_detail.html | 2 + controlpanel/templatetags/ui.py | 6 +- controlpanel/tests.py | 70 ++++++++++++++++++- controlpanel/urls.py | 1 + controlpanel/views.py | 36 +++++++++- 7 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 controlpanel/templates/controlpanel/_club_home_location_card.html diff --git a/controlpanel/forms.py b/controlpanel/forms.py index 7458513..1cd850a 100644 --- a/controlpanel/forms.py +++ b/controlpanel/forms.py @@ -6,6 +6,7 @@ from waffle import get_waffle_flag_model from billing.models import DuePayment, Subscription, Tier, TierPrice from club.models import Club +from events.models import Location from .services.admins import find_member_by_email @@ -30,6 +31,21 @@ class ClubForm(forms.ModelForm): self.fields["slug"].required = False +class HomeLocationForm(forms.ModelForm): + """Create or update the club's home ground -- this *is* an events.Location row + (flagged ``is_home``), the same one that shows up under the club's own + Teams > Locations page, so the two stay in sync by construction rather than + needing anything to keep them that way.""" + + class Meta: + model = Location + fields = ["name", "address", "city", "zip_code", "country"] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["country"].widget.attrs.update({"data-searchable": "true", "data-search-placeholder": _("Type a country to search...")}) + + class ClubAdminForm(forms.Form): """Grant club-admin rights to an email address, creating the person if new.""" diff --git a/controlpanel/templates/controlpanel/_club_home_location_card.html b/controlpanel/templates/controlpanel/_club_home_location_card.html new file mode 100644 index 0000000..6e0a449 --- /dev/null +++ b/controlpanel/templates/controlpanel/_club_home_location_card.html @@ -0,0 +1,39 @@ +{% load lucide %} + +{% comment %} + The club's home ground -- an events.Location row flagged is_home, so setting or + editing it here creates/updates the very same Location the club's own Teams > + Locations page shows, no separate sync step involved. Included with `club`, + `home_location`, `home_location_form` already in context. +{% endcomment %} +
+
+
+

{% lucide "map-pin" size=18 %} Home location

+ +
+ {% if home_location %} +
+
+
Name
+
{{ home_location.name }}
+
+
+
Address
+
{{ home_location.address }}, {{ home_location.zip_code }} {{ home_location.city }}, {{ home_location.country }}
+
+
+ {% else %} +

Not set yet. Once set, events at this location can be recognised as home games.

+ {% endif %} +
+
+ +{% url 'controlpanel:club_home_location_set' club.pk as home_location_url %} +{% include "controlpanel/_modal_form.html" with modal_id="club_home_location_modal" title="Home location" form=home_location_form action_url=home_location_url submit_label="Save" submit_icon="save" blurb="This creates or updates a Location for the club -- the same one that shows up on its own Teams > Locations page." %} diff --git a/controlpanel/templates/controlpanel/club_detail.html b/controlpanel/templates/controlpanel/club_detail.html index 0d334f6..5054799 100644 --- a/controlpanel/templates/controlpanel/club_detail.html +++ b/controlpanel/templates/controlpanel/club_detail.html @@ -194,12 +194,14 @@ {% include "controlpanel/_club_features_card.html" %} {% include "controlpanel/_club_billing_card.html" %} + {% include "controlpanel/_club_home_location_card.html" %} {% include "controlpanel/_club_admins_card.html" %} {% endblock panel %} {% block extra_body %} {{ charts|json_script:"chart-data" }} +