dnscms: improve associations app
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from django.urls import reverse
|
||||
from wagtail.admin.views.pages.choose_parent import ChooseParentView
|
||||
|
||||
|
||||
class ListingRedirectChooseParentView(ChooseParentView):
|
||||
"""ChooseParentView that redirects new pages back to a listing viewset.
|
||||
|
||||
Subclasses set ``listing_url_name`` (e.g. ``"events:index"``).
|
||||
"""
|
||||
|
||||
listing_url_name: str
|
||||
|
||||
def _with_next(self, response):
|
||||
if response.status_code != 302:
|
||||
return response
|
||||
url = response["Location"]
|
||||
sep = "&" if "?" in url else "?"
|
||||
response["Location"] = f"{url}{sep}{urlencode({'next': reverse(self.listing_url_name)})}"
|
||||
return response
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self._with_next(super().get(request, *args, **kwargs))
|
||||
|
||||
def form_valid(self, form):
|
||||
return self._with_next(super().form_valid(form))
|
||||
@@ -5,7 +5,6 @@ from django.utils.html import format_html
|
||||
from wagtail import hooks
|
||||
from wagtail.admin.menu import MenuItem
|
||||
|
||||
from associations.models import AssociationIndex
|
||||
from news.models import NewsIndex
|
||||
|
||||
|
||||
@@ -14,15 +13,6 @@ def enable_additional_rich_text_features(features):
|
||||
features.default_features.extend(["h5", "h6", "blockquote"])
|
||||
|
||||
|
||||
@hooks.register("register_admin_menu_item")
|
||||
def register_associations_menu_item():
|
||||
page = AssociationIndex.objects.first()
|
||||
associations_url = "#"
|
||||
if page:
|
||||
associations_url = reverse("wagtailadmin_explore", args=(quote(page.pk),))
|
||||
return MenuItem("Foreninger", associations_url, icon_name="group", order=2)
|
||||
|
||||
|
||||
@hooks.register("register_admin_menu_item")
|
||||
def register_news_menu_item():
|
||||
page = NewsIndex.objects.first()
|
||||
|
||||
Reference in New Issue
Block a user