Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Merge 08ef132 into b26ce4c
Browse files Browse the repository at this point in the history
  • Loading branch information
jproffitt committed Jul 5, 2018
2 parents b26ce4c + 08ef132 commit 717bd2a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ docs/_build/
public/
.tox
tests/_testdata/media/
.cache/
.cache/
.idea/
.pytest_cache/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 18 additions & 4 deletions djangocms_htmlsitemap/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions djangocms_htmlsitemap/compat.py
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_cmsplugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 717bd2a

Please sign in to comment.