Skip to content

Commit

Permalink
Release prep/3.0.2 (#369)
Browse files Browse the repository at this point in the history
* Add support for Wagtail 2.9 and Django Sites Middleware compat
  • Loading branch information
sekanitembo authored Jun 17, 2020
1 parent 9ab5931 commit eab6762
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ wagtailmenus.sqlite

# VSCode
.vscode/

# Pyenv
.python-version
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Oktay Altay (OktayAltay)
* Dan Bentley (danbentley)
* Arkadiusz Michał Ryś (ArkadiuszMichalRys)
* Sekani Tembo (Method Softworks)

## Translators

Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions docs/source/releases/3.0.2.rst
Original file line number Diff line number Diff line change
@@ -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 <https://docs.wagtail.io/en/stable/releases/2.9.html#upgrade-considerations>`_ \
*if* you intend to remove Wagtail's `SiteMiddleware` and/or use the Django Sites Framework's `CurrentSiteMiddleware`
1 change: 1 addition & 0 deletions docs/source/releases/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release notes
.. toctree::
:maxdepth: 1

3.0.2
3.0.1
3.0
2.13.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]

development_extras = [
'wagtail>=2.4,<2.9',
'wagtail>=2.4,<=2.9',
'django-debug-toolbar',
'django-extensions',
'ipdb',
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion wagtailmenus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion wagtailmenus/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 52 additions & 2 deletions wagtailmenus/utils/tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -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
)
Expand Down Expand Up @@ -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()

0 comments on commit eab6762

Please sign in to comment.