diff --git a/bullet/bullet_admin/mixins.py b/bullet/bullet_admin/mixins.py index 3e8b6840..31b79576 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: - def get_default_success_url(self): + default_success_url = None + + def get_default_success_url(self) -> str: + if self.default_success_url: + return self.default_success_url + raise ImproperlyConfigured( "No URL to redirect to. Provide a get_default_success_url." ) 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 %} - 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) 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)