From 039f7a152787899c490bfedd2fa9aba78b8920e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 21 Jan 2025 11:53:05 +0100 Subject: [PATCH 1/4] fix improper use of ?back --- .../templates/bullet_admin/components/link.html | 2 +- .../bullet_admin/templates/bullet_admin/generic/list.html | 8 ++++---- .../templates/bullet_admin/scanning/_review_teams.html | 2 +- .../templates/bullet_admin/venues/waiting_list.html | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bullet/bullet_admin/templates/bullet_admin/components/link.html b/bullet/bullet_admin/templates/bullet_admin/components/link.html index eb03b494..88b678e0 100644 --- a/bullet/bullet_admin/templates/bullet_admin/components/link.html +++ b/bullet/bullet_admin/templates/bullet_admin/components/link.html @@ -1,5 +1,5 @@ {% load utils %} -{% query_transform back=request.get_full_path as back %} +{% query_transform next=request.get_full_path as back %} diff --git a/bullet/bullet_admin/templates/bullet_admin/generic/list.html b/bullet/bullet_admin/templates/bullet_admin/generic/list.html index cdf7a7f1..0e58d528 100644 --- a/bullet/bullet_admin/templates/bullet_admin/generic/list.html +++ b/bullet/bullet_admin/templates/bullet_admin/generic/list.html @@ -18,7 +18,7 @@ {% endif %} {% endslot %} {% slot buttons %} - {% query_replace back=request.get_full_path as back %} + {% query_replace next=request.get_full_path as back %} {% if help_url %} {% #abtn icon="mdi:help" label="Help" url=help_url|add:back %} {% endif %} @@ -162,13 +162,13 @@ {% if forloop.first %} {% if view_url %} + href="{{ view_url }}{% query_transform next=request.get_full_path %}"> {% elif edit_url %} + href="{{ edit_url }}{% query_transform next=request.get_full_path %}"> {% elif delete_url %} + href="{{ delete_url }}{% query_transform next=request.get_full_path %}"> {% endif %} {% endif %} {% if item or item == 0 %}{{ item }}{% endif %} diff --git a/bullet/bullet_admin/templates/bullet_admin/scanning/_review_teams.html b/bullet/bullet_admin/templates/bullet_admin/scanning/_review_teams.html index 0763d639..b49993b4 100644 --- a/bullet/bullet_admin/templates/bullet_admin/scanning/_review_teams.html +++ b/bullet/bullet_admin/templates/bullet_admin/scanning/_review_teams.html @@ -8,7 +8,7 @@ {% add_query back_url venue=venue.id as back_url %}

All teams in this venue are reviewed. Please, finish the review when ready. + href="{% url "badmin:venue_finish_review" venue.id %}?next={{ back_url|urlencode }}">finish the review when ready.

{% else %}

diff --git a/bullet/bullet_admin/templates/bullet_admin/venues/waiting_list.html b/bullet/bullet_admin/templates/bullet_admin/venues/waiting_list.html index c554c36f..19a64d06 100644 --- a/bullet/bullet_admin/templates/bullet_admin/venues/waiting_list.html +++ b/bullet/bullet_admin/templates/bullet_admin/venues/waiting_list.html @@ -90,7 +90,7 @@ Edit {% if not competition.results_public %} - From 0c4c73ebddf4c5a7a29885370ed9f10492d7bdac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 21 Jan 2025 11:53:32 +0100 Subject: [PATCH 2/4] allow providing just default_success_url --- bullet/bullet_admin/mixins.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bullet/bullet_admin/mixins.py b/bullet/bullet_admin/mixins.py index 3e8b6840..69cd7a41 100644 --- a/bullet/bullet_admin/mixins.py +++ b/bullet/bullet_admin/mixins.py @@ -122,7 +122,12 @@ def get_context_data(self, **kwargs): class RedirectBackMixin: + default_success_url = None + def get_default_success_url(self): + if self.default_success_url: + return self.default_success_url + raise ImproperlyConfigured( "No URL to redirect to. Provide a get_default_success_url." ) From b08d6c314bfffc8c03ae3b1f79e10e9f2a740caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 21 Jan 2025 11:54:37 +0100 Subject: [PATCH 3/4] return RedirectBackMixin to school views --- bullet/bullet_admin/views/education.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bullet/bullet_admin/views/education.py b/bullet/bullet_admin/views/education.py index f4d1d3bc..e5ff24d7 100644 --- a/bullet/bullet_admin/views/education.py +++ b/bullet/bullet_admin/views/education.py @@ -7,6 +7,7 @@ from bullet import search from bullet_admin.access import CountryAdminAccess, CountryAdminInAccess from bullet_admin.forms.education import SchoolForm +from bullet_admin.mixins import RedirectBackMixin from bullet_admin.utils import get_allowed_countries from bullet_admin.views import GenericForm, GenericList @@ -69,6 +70,7 @@ def get_edit_url(self, school: School) -> str: class SchoolUpdateView( CountryAdminInAccess, SchoolQuerySetMixin, + RedirectBackMixin, GenericForm, UpdateView, ): @@ -76,7 +78,7 @@ class SchoolUpdateView( template_name = "bullet_admin/education/school_form.html" form_title = "Edit school" require_unlocked_competition = False - success_url = reverse_lazy("badmin:school_list") + default_success_url = reverse_lazy("badmin:school_list") def get_permission_country(self): return self.get_object().country @@ -93,12 +95,12 @@ def form_valid(self, form): class SchoolCreateView( - CountryAdminAccess, SchoolQuerySetMixin, GenericForm, CreateView + CountryAdminAccess, SchoolQuerySetMixin, RedirectBackMixin, GenericForm, CreateView ): require_unlocked_competition = False form_class = SchoolForm form_title = "New school" - success_url = reverse_lazy("badmin:school_list") + default_success_url = reverse_lazy("badmin:school_list") def form_valid(self, form): school: School = form.save(commit=False) From 74916046b7cbd20e8afd29be404564e68fad9ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 21 Jan 2025 11:58:23 +0100 Subject: [PATCH 4/4] return RedirectBackMixin to album views --- bullet/bullet_admin/mixins.py | 2 +- bullet/bullet_admin/views/albums.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bullet/bullet_admin/mixins.py b/bullet/bullet_admin/mixins.py index 69cd7a41..31b79576 100644 --- a/bullet/bullet_admin/mixins.py +++ b/bullet/bullet_admin/mixins.py @@ -124,7 +124,7 @@ def get_context_data(self, **kwargs): class RedirectBackMixin: default_success_url = None - def get_default_success_url(self): + def get_default_success_url(self) -> str: if self.default_success_url: return self.default_success_url diff --git a/bullet/bullet_admin/views/albums.py b/bullet/bullet_admin/views/albums.py index b3db8025..1ac539a7 100644 --- a/bullet/bullet_admin/views/albums.py +++ b/bullet/bullet_admin/views/albums.py @@ -11,6 +11,7 @@ from bullet_admin.access import PhotoUploadAccess from bullet_admin.forms.album import AlbumForm +from bullet_admin.mixins import RedirectBackMixin from bullet_admin.utils import get_active_competition from bullet_admin.views import GenericDelete, GenericForm, GenericList @@ -53,7 +54,7 @@ def dispatch(self, request, *args, **kwargs): return super().dispatch(request, *args, **kwargs) -class AlbumFormMixin(GenericForm): +class AlbumFormMixin(RedirectBackMixin, GenericForm): form_class = AlbumForm form_multipart = True @@ -80,7 +81,7 @@ def form_valid(self, form): photo.save() return HttpResponseRedirect(self.get_success_url()) - def get_success_url(self): + def get_default_success_url(self): return reverse("badmin:album_edit", kwargs={"pk": self.object.id}) @@ -105,9 +106,9 @@ def form_valid(self, form): return ret -class AlbumDeleteView(PhotoUploadAccess, GenericDelete, DeleteView): +class AlbumDeleteView(PhotoUploadAccess, RedirectBackMixin, GenericDelete, DeleteView): model = Album - success_url = reverse_lazy("badmin:album_list") + default_success_url = reverse_lazy("badmin:album_list") def form_valid(self, form): super().form_valid(form)