Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to add collection from pagecontent admin #36

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions djangocms_pageadmin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from cms.signals.apphook import set_restart_trigger
from cms.toolbar.utils import get_object_preview_url

from djangocms_moderation.admin_actions import add_item_to_unpublish_collection
from djangocms_version_locking.models import VersionLock
from djangocms_version_locking.helpers import version_is_locked
from djangocms_versioning.admin import VersioningAdminMixin
Expand All @@ -32,6 +33,10 @@
from .forms import DuplicateForm
from .helpers import proxy_model

# TODO pageadmin should be usable without moderation and versioning.
# or atleast it should be usable without moderation.
USING_MODERATION = True


require_POST = method_decorator(require_POST)

Expand All @@ -47,6 +52,9 @@ class PageContentAdmin(VersioningAdminMixin, DefaultPageContentAdmin):
"state",
"modified_date",
]
actions = [
a for a in [add_item_to_unpublish_collection] if USING_MODERATION
]
ordering = ['-versions__modified']
search_fields = ("title",)

Expand Down Expand Up @@ -93,7 +101,6 @@ def get_version(self, obj):
def state(self, obj):
version = self.get_version(obj)
return version.get_state_display()

state.short_description = _("state")

def url(self, obj):
Expand All @@ -106,7 +113,6 @@ def url(self, obj):
url = reverse("pages-details-by-slug", kwargs={"slug": path})
if url is not None:
return format_html('<a href="{url}">{url}</a>', url=url)

url.short_description = _("url")

def get_title(self, obj):
Expand All @@ -116,13 +122,11 @@ def get_title(self, obj):
lock=self.is_locked(obj),
title=obj.title,
)

get_title.short_description = _("title")

def author(self, obj):
version = self.get_version(obj)
return version.created_by

author.short_description = _("author")
author.admin_order_field = "versions__created_by"

Expand All @@ -140,21 +144,22 @@ def is_home(self, obj):
def modified_date(self, obj):
version = self.get_version(obj)
return version.modified

modified_date.short_description = _("modified date")
modified_date.admin_order_field = "versions__modified"

def get_list_actions(self):
return [
actions = [
self._set_home_link,
self._get_preview_link,
self._get_edit_link,
self._get_duplicate_link,
self._get_unpublish_link,
self._get_manage_versions_link,
self._get_basic_settings_link,
self._get_advanced_settings_link,
]
if not USING_MODERATION:
actions.insert(4, self._get_unpublish_link)
return actions

def _get_preview_link(self, obj, request, disabled=False):
return render_to_string(
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"django-treebeard>=4.3",
"djangocms_versioning",
"djangocms_version_locking",
"djangocms-moderation"
]

TESTS_REQUIRE = [
Expand Down Expand Up @@ -42,6 +43,7 @@
dependency_links=[
"http://github.com/divio/django-cms/tarball/release/4.0.x#egg=django-cms-4.0.0",
"http://github.com/divio/djangocms-versioning/tarball/master#egg=djangocms-versioning-0.0.23",
"http://github.com/divio/djangocms-moderation/tarball/release/1.0.x#egg=djangocms-moderation-1.0.22",
"http://github.com/FidelityInternational/djangocms-version-locking/tarball/master#egg=djangocms-version-locking-0.0.13"
]
)
9 changes: 9 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import partial
from unittest.mock import patch
from unittest import skip

from django.contrib import admin
from django.contrib.sites.models import Site
Expand Down Expand Up @@ -143,6 +144,13 @@ class ListActionsTestCase(CMSTestCase):
def setUp(self):
self.modeladmin = admin.site._registry[PageContent]

def test_unpublish_action_is_added(self):
"""A dropdown item to add pages to a collection for unpublishing is available"""
actions = self.modeladmin.actions
func = actions[0]
self.assertEqual(func.__name__, 'add_item_to_unpublish_collection')
self.assertEqual(func.short_description, 'Add items to a collection to unpublish')

def test_preview_link(self):
pagecontent = PageContentWithVersionFactory()
func = self.modeladmin._list_actions(self.get_request("/"))
Expand Down Expand Up @@ -223,6 +231,7 @@ def test_set_home_link(self):
reverse("admin:cms_pagecontent_set_home_content", args=(version.pk,)),
)

@skip('This has been disabled. The ideal would be that this is enabled if moderation is disabled')
def test_unpublish_link(self):
version = PageVersionFactory(state=PUBLISHED)
pagecontent = version.content
Expand Down