Skip to content

Commit

Permalink
fixes for wt 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-b committed Dec 20, 2023
1 parent 59d6917 commit 20a6e81
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
author_email="[email protected]",
url="https://github.com/neon-jungle/wagtailnews/",
install_requires=[
"wagtail>=4.0.0",
"wagtail>=5.2.0",
],
extras_require={"docs": documentation_extras},
zip_safe=False,
Expand Down
6 changes: 3 additions & 3 deletions wagtailnews/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def __init__(
self,
label=_("News"),
url=reverse_lazy("wagtailnews:choose"),
classnames="icon icon-grip",
classname="icon icon-grip",
order=250,
**kwargs
**kwargs,
):
super(NewsMenuItem, self).__init__(
label, url, classnames=classnames, order=order, **kwargs
label, url, classname=classname, order=order, **kwargs
)

def is_shown(self, request):
Expand Down
47 changes: 27 additions & 20 deletions wagtailnews/views/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from wagtail.admin import messages
from wagtail.admin.panels import (
ObjectList, extract_panel_definitions_from_model_class)
from wagtail.admin.ui.side_panels import BasePreviewSidePanel, BaseSidePanels
from wagtail.admin.views.generic import (
CreateView, DeleteView, EditView, UnpublishView)
from wagtail.admin.views.generic.preview import \
PreviewOnEdit as GenericPreviewOnEdit
from wagtail.admin.panels import ObjectList, extract_panel_definitions_from_model_class
from wagtail.admin.ui.side_panels import PreviewSidePanel
from wagtail.admin.views.generic import CreateView, DeleteView, EditView, UnpublishView
from wagtail.admin.views.generic.preview import PreviewOnEdit as GenericPreviewOnEdit
from wagtail.models import Page

from django.forms import Media
from django.urls import reverse
from django.utils.functional import cached_property
from wagtailnews.permissions import format_perm, format_perms

from .. import signals
Expand All @@ -39,38 +38,46 @@ def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)


class PreviewSidePanel(BasePreviewSidePanel):
class PreviewSidePanel(PreviewSidePanel):
def __init__(self, object, request, newsindex):
self.newsindex = newsindex
if not object:
object = newsindex.get_newsitem_model()(newsindex=newsindex)
super().__init__(object, request)

def get_context_data(self, request):
context = super().get_context_data(request)
if self.object.id:
context["preview_url"] = reverse(
if object.id:
preview_url = reverse(
"wagtailnews:preview_on_edit",
kwargs={
"index_pk": self.newsindex.pk,
"newsitem_pk": self.object.pk,
"newsitem_pk": object.pk,
},
)
else:
context["preview_url"] = reverse(
preview_url = reverse(
"wagtailnews:preview_on_create",
kwargs={"index_pk": self.newsindex.pk},
)
return context
super().__init__(object, request, preview_url=preview_url)


class NewsItemSidePanels(BaseSidePanels):
class NewsItemSidePanels:
def __init__(self, request, object, newsindex):
# TODO status panel should be pretty easy, it's the default in BaseSidePanels
self.request = request
self.object = object

self.side_panels = [
PreviewSidePanel(object, request, newsindex),
]

def __iter__(self):
return iter(sorted(self.side_panels, key=lambda p: p.order))

@cached_property
def media(self):
media = Media()
for panel in self:
media += panel.media
return media


class NewsItemAdminMixin:
def setup(self, request, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion wagtailnews/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, **kwargs):
super(NewsItemSearchArea, self).__init__(
_("News"),
reverse("wagtailnews:search"),
classnames="icon icon-grip",
classname="icon icon-grip",
order=250,
**kwargs,
)
Expand Down

0 comments on commit 20a6e81

Please sign in to comment.