Skip to content

Commit

Permalink
Make it possible to add collection from pagecontent admin
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-s committed Oct 22, 2019
1 parent 6023d8d commit 3993771
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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"
]
)

0 comments on commit 3993771

Please sign in to comment.