diff --git a/.gitignore b/.gitignore index bf8f8dc..fc87578 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ docs/_build/ public/ .tox tests/_testdata/media/ -.cache/ \ No newline at end of file +.cache/ +.idea/ +.pytest_cache/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index afe54cc..1a568c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ python: - "3.5" - "3.6" env: - - DJANGO="django>=1.8,<1.9" CMS="django-cms>=3.2,<3.5" - - DJANGO="django>=1.9,<1.10" CMS="django-cms>=3.2,<3.5" - - DJANGO="django>=1.10,<1.11" CMS="django-cms>=3.2,<3.5" - - DJANGO="django>=1.11,<2" CMS="django-cms>=3.2,<3.5" + - DJANGO="django>=1.8,<1.9" CMS="django-cms>=3.2,<3.6" + - DJANGO="django>=1.9,<1.10" CMS="django-cms>=3.2,<3.6" + - DJANGO="django>=1.10,<1.11" CMS="django-cms>=3.2,<3.6" + - DJANGO="django>=1.11,<2" CMS="django-cms>=3.2,<3.6" - TOXENV=lint matrix: diff --git a/djangocms_htmlsitemap/cms_plugins.py b/djangocms_htmlsitemap/cms_plugins.py index ac085dd..2a265ea 100644 --- a/djangocms_htmlsitemap/cms_plugins.py +++ b/djangocms_htmlsitemap/cms_plugins.py @@ -8,6 +8,7 @@ from django.contrib.sites.models import Site from django.utils.translation import ugettext_lazy as _ +from djangocms_htmlsitemap.compat import DJANGO_CMS_35 from .models import HtmlSitemapPluginConf @@ -20,19 +21,32 @@ class HtmlSitemapPlugin(CMSPluginBase): def render(self, context, instance, placeholder): request = context['request'] site = Site.objects.get_current() - pages = Page.objects.public().published(site=site).order_by('path') \ - .filter(depth__gte=instance.min_depth, login_required=False) \ + + path_column = 'node__path' if DJANGO_CMS_35 else 'path' + node_column = 'node__depth' if DJANGO_CMS_35 else 'depth' + + pages = Page.objects.public().published(site=site).order_by(path_column) \ + .filter(**{node_column + '__gte': instance.min_depth}, login_required=False) \ .filter(title_set__language=request.LANGUAGE_CODE) \ .distinct() if instance.max_depth: - pages = pages.filter(depth__lte=instance.max_depth) + pages = pages.filter(**{node_column + '__lte': instance.max_depth}) if instance.in_navigation is not None: pages = pages.filter(in_navigation=instance.in_navigation) context['instance'] = instance context['pages'] = pages - context['annotated_pages'] = Page.get_annotated_list_qs(pages) + + if DJANGO_CMS_35: + from cms.models.pagemodel import TreeNode + nodes = [page.node for page in pages.select_related('node')] + annotated_nodes = TreeNode.get_annotated_list_qs(nodes) + annotated_pages = [(pages[x], annotated_nodes[x][1]) for x in range(0, len(nodes))] + else: + annotated_pages = Page.get_annotated_list_qs(pages) + + context['annotated_pages'] = annotated_pages return context diff --git a/djangocms_htmlsitemap/compat.py b/djangocms_htmlsitemap/compat.py new file mode 100644 index 0000000..7fe7c0f --- /dev/null +++ b/djangocms_htmlsitemap/compat.py @@ -0,0 +1,6 @@ +import cms +from distutils.version import LooseVersion + +DJANGO_CMS_VERSION = LooseVersion(cms.__version__) + +DJANGO_CMS_35 = DJANGO_CMS_VERSION >= LooseVersion('3.5') diff --git a/setup.py b/setup.py index b3c8d3e..4e14459 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def read_relative_file(filename): zip_safe=False, install_requires=[ 'django>=1.7,<2', - 'django-cms>=3.1,<3.5', + 'django-cms>=3.1,<3.6', ], classifiers=[ 'Development Status :: 4 - Beta', diff --git a/tests/integration/test_cmsplugins.py b/tests/integration/test_cmsplugins.py index 7c2e1c1..802933f 100644 --- a/tests/integration/test_cmsplugins.py +++ b/tests/integration/test_cmsplugins.py @@ -40,6 +40,14 @@ def setup_cms(self): # Creates a basic tree of CMS pages self.index_page = create_page('Index', 'index.html', 'en', published=True, in_navigation=True) # noq + + try: + # django-cms 3.5+ + self.index_page.set_as_homepage() + except AttributeError: + # django-cms < 3.5 defaults the first page as being the home page + pass + self.depth2_page1 = create_page( 'Depth 2 page 1', 'simple.html', 'en', in_navigation=True, published=True, parent=self.index_page) self.depth2_page2 = create_page( diff --git a/tox.ini b/tox.ini index d9f6e6e..a50100f 100644 --- a/tox.ini +++ b/tox.ini @@ -19,6 +19,7 @@ deps = djangocms32: django-cms>=3.2,<3.3 djangocms33: django-cms>=3.3,<3.4 djangocms34: django-cms>=3.4,<3.5 + djangocms35: django-cms>=3.5,<3.6 setenv = PYTHONPATH = {toxinidir}:{toxinidir} commands =