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 14, 2019
1 parent 6023d8d commit 1ab3ce1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 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_items_to_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,9 +33,16 @@
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)

add_item_to_unpublish_collection = add_items_to_collection
add_item_to_unpublish_collection.short_description = 'Add moderation collection to unpublish'


class PageContentAdmin(VersioningAdminMixin, DefaultPageContentAdmin):
change_list_template = "admin/djangocms_pageadmin/pagecontent/change_list.html"
Expand All @@ -47,6 +55,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 +104,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 +116,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 +125,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 +147,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

0 comments on commit 1ab3ce1

Please sign in to comment.