From 88e7ab649075013dc621c30fd89bb5ee0534cac5 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 11 Jun 2017 12:35:47 +0200 Subject: [PATCH 1/6] Filter out duplicated categories due to parler joins --- djangocms_blog/cms_menus.py | 32 +++++++++++++++++++++----------- tests/test_menu.py | 20 ++++++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/djangocms_blog/cms_menus.py b/djangocms_blog/cms_menus.py index 2e61642..c85885a 100644 --- a/djangocms_blog/cms_menus.py +++ b/djangocms_blog/cms_menus.py @@ -52,6 +52,13 @@ class BlogCategoryMenu(CMSAttachMenu): namespace=self.instance.application_namespace ) config = self._config[self.instance.application_namespace] + if hasattr(self, 'instance') and self.instance: + if not getattr(request, 'toolbar', False) or not request.toolbar.edit_mode: + if self.instance == self.instance.get_draft_object(): + return [] + else: + if self.instance == self.instance.get_public_object(): + return [] if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_CATEGORIES): categories_menu = True if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_POSTS): @@ -61,21 +68,24 @@ class BlogCategoryMenu(CMSAttachMenu): categories = BlogCategory.objects if config: categories = categories.namespace(self.instance.application_namespace) - categories = categories.active_translations(language).distinct() + categories = categories.active_translations(language) categories = categories.order_by('parent__id', 'translations__name').\ select_related('app_config').prefetch_related('translations') + added_categories = [] for category in categories: - node = NavigationNode( - category.name, - category.get_absolute_url(), - '{0}-{1}'.format(category.__class__.__name__, category.pk), - ( - '{0}-{1}'.format( - category.__class__.__name__, category.parent_id - ) if category.parent_id else None + if category.pk not in added_categories: + node = NavigationNode( + category.name, + category.get_absolute_url(), + '{0}-{1}'.format(category.__class__.__name__, category.pk), + ( + '{0}-{1}'.format( + category.__class__.__name__, category.parent_id + ) if category.parent_id else None + ) ) - ) - nodes.append(node) + nodes.append(node) + added_categories.append(category.pk) if posts_menu: posts = Post.objects diff --git a/tests/test_menu.py b/tests/test_menu.py index cb4ad05..f36871c 100644 --- a/tests/test_menu.py +++ b/tests/test_menu.py @@ -6,6 +6,7 @@ from django.utils.translation import activate from menus.menu_pool import menu_pool from parler.utils.context import smart_override, switch_language +from djangocms_blog.models import BlogCategory from djangocms_blog.settings import ( MENU_TYPE_CATEGORIES, MENU_TYPE_COMPLETE, MENU_TYPE_NONE, MENU_TYPE_POSTS, ) @@ -46,9 +47,10 @@ class MenuTest(BaseTest): for lang in ('en', 'it'): with smart_override(lang): self._reset_menus() - request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang)) + request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang), edit=True) nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + self.assertTrue(len(nodes), BlogCategory.objects.all().count() + len(pages)) + nodes_url = set([node.get_absolute_url() for node in nodes]) cats_url = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)]) self.assertTrue(cats_url.issubset(nodes_url)) @@ -57,9 +59,11 @@ class MenuTest(BaseTest): for lang in ('en', 'it'): with smart_override(lang): self._reset_menus() - request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang)) + request = self.get_page_request(pages[1].get_draft_object(), self.user, pages[1].get_draft_object().get_absolute_url(lang)) nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + urls = [node.get_absolute_url() for node in nodes] + nodes_url = [node.get_absolute_url() for node in nodes] + self.assertTrue(len(nodes_url), BlogCategory.objects.all().count() + len(pages)) self.assertFalse(posts[0].get_absolute_url(lang) in nodes_url) self.assertTrue(posts[1].get_absolute_url(lang) in nodes_url) @@ -90,7 +94,7 @@ class MenuTest(BaseTest): with smart_override(lang): self._reset_menus() nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + nodes_url = set([node.get_absolute_url() for node in nodes]) self.assertFalse(cats_url[lang].issubset(nodes_url)) self.assertFalse(posts_url[lang].issubset(nodes_url)) @@ -103,7 +107,7 @@ class MenuTest(BaseTest): with smart_override(lang): self._reset_menus() nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + nodes_url = set([node.get_absolute_url() for node in nodes]) self.assertFalse(cats_url[lang].issubset(nodes_url)) self.assertTrue(posts_url[lang].issubset(nodes_url)) @@ -116,7 +120,7 @@ class MenuTest(BaseTest): with smart_override(lang): self._reset_menus() nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + nodes_url = set([node.get_absolute_url() for node in nodes]) self.assertTrue(cats_url[lang].issubset(nodes_url)) self.assertFalse(posts_url[lang].issubset(nodes_url)) @@ -129,7 +133,7 @@ class MenuTest(BaseTest): with smart_override(lang): self._reset_menus() nodes = menu_pool.get_nodes(request) - nodes_url = set([node.url for node in nodes]) + nodes_url = set([node.get_absolute_url() for node in nodes]) self.assertTrue(cats_url[lang].issubset(nodes_url)) self.assertTrue(posts_url[lang].issubset(nodes_url)) From 12ca983a90d1d9ed23c973f314ce3f929882d135 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 11 Jun 2017 12:38:07 +0200 Subject: [PATCH 2/6] Update changelog --- HISTORY.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 0eaa66f..806d988 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,9 +8,9 @@ History 0.8.13 (unreleased) ******************* -* Drop python 2.6 compatibility +* Dropped python 2.6 compatibility * Fixed exceptions in __str__ -* Drop python 2.6 compatibility +* Fixed issue with duplicated categories in menu ******************* 0.8.12 (2017-03-11) From e3d7ce1b9427c7ecb09168eb9fd00efb14629512 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 11 Jun 2017 12:44:00 +0200 Subject: [PATCH 3/6] Added ALLOWED_HOSTS due to Django change --- cms_helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cms_helper.py b/cms_helper.py index ae6b887..6c66333 100755 --- a/cms_helper.py +++ b/cms_helper.py @@ -99,6 +99,7 @@ HELPER_SETTINGS = dict( 'default': {} }, BLOG_AUTO_SETUP=False, + ALLOWED_HOSTS=['*'], ) try: From 612e1c48a1ef570e8b2aef1904f09fcaff952182 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Tue, 25 Jul 2017 08:31:51 +0200 Subject: [PATCH 4/6] Improve CONTRIBUTING.rst doc --- CONTRIBUTING.rst | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 45823d8..6cd67c5 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -3,7 +3,7 @@ Contributing ============ Contributions are welcome, and they are greatly appreciated! Every -little bit helps, and credit will always be given. +little bit helps, and credit will always be given. You can contribute in many ways: @@ -33,10 +33,19 @@ Implement Features Look through the GitHub issues for features. Anything tagged with "feature" is open to whoever wants to implement it. +Branching model +~~~~~~~~~~~~~~~ + +When planning a code cotnribution, these is the project branching model: + +* new features goes to develop +* bugfixes for releases goes to release/Y.Z.x branches +* master is just a snapshot of the latest stable release and should not be targeted + Write Documentation ~~~~~~~~~~~~~~~~~~~ -djangocms-blog could always use more documentation, whether as part of the +djangocms-blog could always use more documentation, whether as part of the official djangocms-blog docs, in docstrings, or even on the web in blog posts, articles, and such. @@ -81,7 +90,7 @@ tests, including testing other Python versions with tox:: $ python setup.py test $ tox -To get flake8 and tox, just pip install them into your virtualenv. +To get flake8 and tox, just pip install them into your virtualenv. 6. Commit your changes and push your branch to GitHub:: @@ -100,7 +109,7 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check +3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/nephila/djangocms-blog/pull_requests and make sure that the tests pass for all supported Python versions. From 55a52b5197ca2ab7a69102ee7cc8f809415301ef Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Tue, 25 Jul 2017 19:05:51 +0200 Subject: [PATCH 5/6] Fix dependencies in tox --- requirements-test.txt | 1 - tox.ini | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements-test.txt b/requirements-test.txt index a9c6ae7..94e66fe 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -9,4 +9,3 @@ https://github.com/nephila/djangocms-helper/archive/develop.zip tox>=2.0 wheel pysolr -django-parler>=1.6 diff --git a/tox.ini b/tox.ini index b0e827e..8a2bdf9 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ deps = django16: django-taggit<0.18 django16: django-mptt<0.8 django16: django-filer<1.2 + django16: django-parler>=1.6,<1.7 django16: cmsplugin-filer<1.1 django16: django-haystack<2.5 django16: djangocms-admin-style<1.2 @@ -16,6 +17,7 @@ deps = django17: django-filer<1.3 django17: cmsplugin-filer<1.2 django17: django-haystack + django17: django-parler>=1.6,<1.7 django17: djangocms-admin-style<1.2 django17: django-taggit<0.18 django18: Django>=1.8,<1.9 @@ -24,12 +26,14 @@ deps = django18: cmsplugin-filer<1.2 django18: django-haystack django18: djangocms-admin-style>1.2,<1.3 + django18: django-parler>=1.6 django19: Django>=1.9,<1.10 django19: django-mptt>=0.8 django19: django-filer<1.3 django19: cmsplugin-filer<1.2 django19: django-haystack django19: djangocms-admin-style>1.2,<1.3 + django19: django-parler>=1.6 cms30: https://github.com/divio/django-cms/archive/release/3.0.x.zip cms30: djangocms-text-ckeditor<2.8 cms31: https://github.com/divio/django-cms/archive/release/3.1.x.zip @@ -38,9 +42,9 @@ deps = cms32: djangocms-text-ckeditor<3.0 cms33: https://github.com/divio/django-cms/archive/release/3.3.x.zip cms33: djangocms-text-ckeditor>=3.0 - cms34: https://github.com/divio/django-cms/archive/develop.zip + cms34: https://github.com/divio/django-cms/archive/release/3.4.x.zip cms34: djangocms-text-ckeditor>=3.0 - knocker: https://github.com/divio/django-cms/archive/release/3.3.x.zip + knocker: https://github.com/divio/django-cms/archive/release/3.4.x.zip knocker: https://github.com/nephila/django-knocker/archive/master.zip?0.1.1 knocker: djangocms-text-ckeditor<3.0 django-meta>=1.2 From 76670e75ede2736641b42e24edbc4c6354ad8c00 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Tue, 25 Jul 2017 20:43:39 +0200 Subject: [PATCH 6/6] Release 0.8.13 --- HISTORY.rst | 2 +- djangocms_blog/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 806d988..538c99b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,7 +5,7 @@ History ======= ******************* -0.8.13 (unreleased) +0.8.13 (2017-07-25) ******************* * Dropped python 2.6 compatibility diff --git a/djangocms_blog/__init__.py b/djangocms_blog/__init__.py index d347092..dd86410 100644 --- a/djangocms_blog/__init__.py +++ b/djangocms_blog/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- __author__ = 'Iacopo Spalletti' __email__ = 'i.spalletti@nephila.it' -__version__ = '0.8.12' +__version__ = '0.8.13' default_app_config = 'djangocms_blog.apps.BlogAppConfig'