Skip to content

Commit

Permalink
Merge pull request #38 from neon-jungle/5.2
Browse files Browse the repository at this point in the history
fixes for wt 5.2
  • Loading branch information
seb-b authored Dec 20, 2023
2 parents 59d6917 + 9940593 commit 1bac35d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 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
36 changes: 23 additions & 13 deletions wagtailnews/views/editor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from functools import lru_cache

from django.core.exceptions import PermissionDenied
from django.forms import Media
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.functional import cached_property
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.ui.side_panels import PreviewSidePanel
from wagtail.admin.views.generic import (
CreateView, DeleteView, EditView, UnpublishView)
from wagtail.admin.views.generic.preview import \
Expand Down Expand Up @@ -39,38 +41,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 1bac35d

Please sign in to comment.