diff --git a/.gitignore b/.gitignore index 7b66b6ac8..d5e693c88 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,6 @@ wagtailmenus.sqlite # VSCode .vscode/ + +# Pyenv +.python-version diff --git a/.travis.yml b/.travis.yml index e6c005e95..81284fc8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,8 @@ matrix: python: 3.8 - env: TOXENV=py38-dj3-wt28 python: 3.8 + - env: TOXENV=py38-dj3-wt29 + python: 3.8 install: - pip install tox codecov diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c2ebd08..d1de78361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Changelog ========= + +3.0.2 (xx.06.2020) +------------------ + +* Added support for Wagtail 2.9 (no code changes necessary) (Sekani Tembo). +* Added compatibility with Django Sites Framework (Sekani Tembo). +* Minor documentation updates (Sekani Tembo). + + 3.0.1 (08.02.2020) ------------------ diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 04fbf27e4..1e78ac1fc 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -21,6 +21,7 @@ * Oktay Altay (OktayAltay) * Dan Bentley (danbentley) * Arkadiusz Michał Ryś (ArkadiuszMichalRys) +* Sekani Tembo (Method Softworks) ## Translators diff --git a/docs/source/contributing/index.rst b/docs/source/contributing/index.rst index 4c9bbef15..3a1e346bc 100644 --- a/docs/source/contributing/index.rst +++ b/docs/source/contributing/index.rst @@ -126,7 +126,7 @@ Or if you want to measure test coverage, run: .. code-block:: console - coverage --source=wagtailmenus runtests.py + coverage run --source=wagtailmenus runtests.py coverage report Testing in a single environment is a quick and easy way to identify obvious issues with your code. However, it's important to test changes in other environments too, before they are submitted. In order to help with this, wagtailmenus is configured to use ``tox`` for multi-environment tests. They take longer to complete, but running them is as simple as running: diff --git a/docs/source/index.rst b/docs/source/index.rst index 13117af40..880e39093 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -7,7 +7,7 @@ wagtailmenus is an open-source extension for `Wagtail CMS The current version is tested for compatibility with the following: -- Wagtail versions 2.0 to 2.8 +- Wagtail versions 2.0 to 2.9 - Django versions 1.11, 2.0, 2.2 and 3.0 - Python versions 3.4 to 3.8 diff --git a/docs/source/releases/3.0.2.rst b/docs/source/releases/3.0.2.rst new file mode 100644 index 000000000..df9c04f31 --- /dev/null +++ b/docs/source/releases/3.0.2.rst @@ -0,0 +1,15 @@ +================================ +Wagtailmenus 3.0.2 release notes +================================ + +Minor changes +============= + +* Added support for Wagtail 2.9 (no code changes necessary) (Sekani Tembo). +* Added compatibility with Django Sites Framework [1]_ (Sekani Tembo). +* Minor documentation updates (Sekani Tembo). + +.. rubric:: Footnotes +.. [1] Be sure to update code according to Wagtail 2.9 Release \ *Notes'* + `Upgrade Considerations `_ \ + *if* you intend to remove Wagtail's `SiteMiddleware` and/or use the Django Sites Framework's `CurrentSiteMiddleware` diff --git a/docs/source/releases/index.rst b/docs/source/releases/index.rst index c06031932..4d89ee883 100644 --- a/docs/source/releases/index.rst +++ b/docs/source/releases/index.rst @@ -5,6 +5,7 @@ Release notes .. toctree:: :maxdepth: 1 + 3.0.2 3.0.1 3.0 2.13.1 diff --git a/setup.py b/setup.py index 39357608e..59462e7b8 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ ] development_extras = [ - 'wagtail>=2.4,<2.9', + 'wagtail>=2.4,<=2.9', 'django-debug-toolbar', 'django-extensions', 'ipdb', diff --git a/tox.ini b/tox.ini index 91fc9852a..a831d6b35 100644 --- a/tox.ini +++ b/tox.ini @@ -17,9 +17,10 @@ basepython = py38: python3.8 deps = - dj111: Django>=1.11,<2.1 + dj111: Django>=1.11,<2.0 dj2: Django>=2.0,<2.1 dj22: Django>=2.2,<3.0 + dj3: Django>=3.0,<3.1 wt2: wagtail>=2.0,<2.1 wt21: wagtail>=2.1,<2.2 wt22: wagtail>=2.2,<2.3 @@ -29,3 +30,4 @@ deps = wt26: wagtail>=2.6,<2.7 wt27: wagtail>=2.7,<2.8 wt28: wagtail>=2.8,<2.9 + wt29: wagtail>=2.9,<3.0 diff --git a/wagtailmenus/__init__.py b/wagtailmenus/__init__.py index 363116d7f..19d7c7db1 100644 --- a/wagtailmenus/__init__.py +++ b/wagtailmenus/__init__.py @@ -2,7 +2,7 @@ # major.minor.patch.release.number # release must be one of alpha, beta, rc, or final -VERSION = (3, 0, 1, "final", 0) +VERSION = (3, 0, 2, "alpha", 0) __version__ = get_version(VERSION) stable_branch_name = get_stable_branch_name(VERSION) diff --git a/wagtailmenus/utils/misc.py b/wagtailmenus/utils/misc.py index 8d25f9c8a..29c9e7594 100644 --- a/wagtailmenus/utils/misc.py +++ b/wagtailmenus/utils/misc.py @@ -5,8 +5,12 @@ def get_site_from_request(request, fallback_to_default=True): - if getattr(request, 'site', None): + site = getattr(request, 'site', None) + if isinstance(site, Site): return request.site + site = Site.find_for_request(request) + if site: + return site if fallback_to_default: return Site.objects.filter(is_default_site=True).first() return None diff --git a/wagtailmenus/utils/tests/test_misc.py b/wagtailmenus/utils/tests/test_misc.py index f562e44ff..0f09ed410 100644 --- a/wagtailmenus/utils/tests/test_misc.py +++ b/wagtailmenus/utils/tests/test_misc.py @@ -1,8 +1,10 @@ -from django.test import RequestFactory, TestCase +from django.test import RequestFactory, TestCase, modify_settings +from distutils.version import LooseVersion +from wagtail.core import __version__ as wagtail_version from wagtail.core.models import Page, Site from wagtailmenus.conf import defaults -from wagtailmenus.utils.misc import derive_page, derive_section_root +from wagtailmenus.utils.misc import derive_page, derive_section_root, get_site_from_request from wagtailmenus.tests.models import ( ArticleListPage, ArticlePage, LowLevelPage, TopLevelPage ) @@ -229,3 +231,51 @@ def test_returns_none_if_provided_page_is_not_a_descendant_of_a_section_root(sel with self.assertNumQueries(0): result = derive_section_root(self.page_with_depth_of_3) self.assertIs(result, None) + + +class TestGetSiteFromRequest(TestCase): + """Tests for wagtailmenus.utils.misc.get_site_from_request()""" + fixtures = ['test.json'] + + def setUp(self): + # URL to request during test + self.url = '/superheroes/marvel-comics/' + # Establish if Wagtail is v2.9 or above + if LooseVersion(wagtail_version) >= LooseVersion('2.9'): + self.is_wagtail_29_or_above = True + else: + self.is_wagtail_29_or_above = False + + def _run_test(self): + """ + Confirm that the Site returned by get_site_from_request() is a Wagtail Site + instance. + """ + request = self.client.get(self.url).wsgi_request + site = get_site_from_request(request) + self.assertIsInstance(site, Site) + + def test_with_wagtail_site_in_request(self): + """ + Test when Wagtail Site exists at request.site. + """ + self._run_test() + + @modify_settings(MIDDLEWARE={ + 'append': 'django.contrib.sites.middleware.CurrentSiteMiddleware', + 'remove': 'wagtail.core.middleware.SiteMiddleware', + }) + def test_with_django_site_in_request_wagtail_29_and_above(self): + """ + Test when only a Django Site exists at request.site for Wagtail 2.9 and above. + """ + if self.is_wagtail_29_or_above: + self._run_test() + + @modify_settings(MIDDLEWARE={'remove': 'wagtail.core.middleware.SiteMiddleware'}) + def test_with_no_site_in_request_wagtail_29_and_above(self): + """ + Test when no Site object exists at request.site for Wagtail 2.9 and above. + """ + if self.is_wagtail_29_or_above: + self._run_test()