Skip to content

Commit

Permalink
Merge pull request #159 from FidelityInternational/feature/remove-unp…
Browse files Browse the repository at this point in the history
…ublished-pages-from-admin-select-view

feature removed unpublished pages from menu item admin select view fo…
  • Loading branch information
joshyu authored Mar 6, 2024
2 parents 768beda + eaf2bc4 commit fec7b4c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog

Unreleased
==========
* feat: Removed unpublished pages from menu item admin select view for page drop down

1.8.2 (2022-10-25)
==================
Expand Down
13 changes: 12 additions & 1 deletion djangocms_navigation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from cms.models import Page
from cms.utils import get_current_site, get_language_from_request

from djangocms_versioning.constants import ARCHIVED, UNPUBLISHED

from djangocms_navigation.utils import is_model_supported, supported_models


Expand All @@ -32,8 +34,17 @@ def get(self, request, *args, **kwargs):
if not is_model_supported(self.menu_content_model, model):
return HttpResponseBadRequest()

queryset_data = self.get_data()

# Removing unpublished pages from queryset
if model == Page:
queryset_data = [
page for page in queryset_data
if not getattr(page.get_title_obj().versions.first(), "state", None) in [ARCHIVED, UNPUBLISHED]
]

data = {
"results": [{"text": str(obj), "id": obj.pk} for obj in self.get_data()]
"results": [{"text": str(obj), "id": obj.pk} for obj in queryset_data]
}
return JsonResponse(data)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

INSTALL_REQUIREMENTS = [
"Django>=1.11,<3.3",
"django-treebeard>=4.3",
"django-treebeard>=4.3,<4.6.0",
"django-cms",
]

Expand Down
10 changes: 4 additions & 6 deletions tests/requirements/requirements_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ flake8
isort
lxml
tox

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/develop-4#egg=django-cms
https://github.com/django-cms/django-cms/tarball/4.0.0#egg=django-cms
https://github.com/divio/djangocms-text-ckeditor/tarball/support/4.0.x#egg=djangocms-text-ckeditor
https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning
https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning
https://github.com/FidelityInternational/djangocms-version-locking/tarball/master#egg=djangocms-version-locking
https://github.com/django-cms/djangocms-moderation/tarball/master#egg=djangocms-moderation
https://github.com/FidelityInternational/djangocms-references/tarball/master#egg=djangocms-references
https://github.com/django-cms/djangocms-alias/tarball/master#egg=djangocms-alias
https://github.com/FidelityInternational/djangocms-references/tarball/1.4.3#egg=djangocms-references
https://github.com/django-cms/djangocms-alias/tarball/1.11.0#egg=djangocms-alias
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
envlist =
flake8
isort
py{37,38,39}-dj{22}-sqlite-cms40
py{37,38,39}-dj{22,32}-sqlite-cms40

skip_missing_interpreters=True

Expand Down

0 comments on commit fec7b4c

Please sign in to comment.