Skip to content
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
16 changes: 16 additions & 0 deletions cms/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ def get_admin_model_object_by_id(model_class, obj_id):
should be visible to the admin.
"""
return model_class.objects.get(pk=obj_id)


def filter_admin_model(model_class, **kwargs):
"""
A method to filter a Model with keyword arguments.

3rd party applications may change the queryset by the use of monkey-patching.
djangocms-versioning is a prime example of this. By having this helper 3rd
party applications can monkeypatch this helper to ensure correct results
without monkeypatching entire functions of django-cms or through adding
their logic directly to django-cms.

This helper can be reused by applications that wish to get a model that
should be visible to the admin.
"""
return model_class.filter(**kwargs)
6 changes: 5 additions & 1 deletion cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from cms.cache.page import get_page_cache
from cms.exceptions import LanguageError
from cms.forms.login import CMSToolbarLoginForm
from cms.models.pagemodel import TreeNode
from cms.models import PageContent, TreeNode
from cms.page_rendering import _handle_no_page, _render_welcome_page, render_pagecontent
from cms.toolbar.utils import get_toolbar_from_request
from cms.utils import get_current_site
from cms.utils.conf import get_cms_setting
from cms.utils import helpers
from cms.utils.helpers import is_editable_model
from cms.utils.i18n import (get_fallback_languages, get_public_languages,
get_redirect_on_fallback, get_language_list,
Expand Down Expand Up @@ -168,6 +169,9 @@ def details(request, slug):
# use the page object with populated cache
content.page = page
if hasattr(request, 'toolbar'):
content = helpers.filter_admin_model(
PageContent, page_id=page.pk, language=request_language
).first()
request.toolbar.set_object(content)

return render_pagecontent(request, content)
Expand Down