diff --git a/.travis.yml b/.travis.yml index ab2f5f2..8c986a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - DJANGO=1.7 - DJANGO=1.8 - DJANGO=1.9 + - DJANGO=1.10 install: - pip install -q Django==$DJANGO script: @@ -25,3 +26,6 @@ matrix: - python: "2.6" env: DJANGO=1.9 + + - python: "2.6" + env: DJANGO=1.10 diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 78bda89..97872e3 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,8 @@ +v0.3.0 +------ + +Added support for Django 1.10 version. + v0.2.3 ------ diff --git a/README.markdown b/README.markdown index d4a3462..a6de49d 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -# [Django Macros URL](https://github.com/phpdude/django-macros-url/) v0.2.3 - Routing must be simple as possible +# [Django Macros URL](https://github.com/phpdude/django-macros-url/) v0.3.0 - Routing must be simple as possible Django Macros URL makes it easy to write (and read) URL patterns in your Django applications by using macros. diff --git a/macrosurl/__init__.py b/macrosurl/__init__.py index ee3959e..8899948 100644 --- a/macrosurl/__init__.py +++ b/macrosurl/__init__.py @@ -1,6 +1,9 @@ import re +import warnings +from distutils.version import StrictVersion -VERSION = (0, 2, 3) +VERSION = (0, 3, 0) +DJANGO_VERSION = None _macros_library = { 'id': r'\d+', @@ -71,6 +74,13 @@ def __unicode__(self): def url(regex, view, kwargs=None, name=None, prefix=''): from django.conf.urls import url as baseurl + if DJANGO_VERSION is None: + global DJANGO_VERSION + + from django import get_version + + DJANGO_VERSION = get_version() + # Handle include()'s in views. end_dollar = True if isinstance(view, tuple) and len(view) == 3: @@ -81,4 +91,25 @@ def url(regex, view, kwargs=None, name=None, prefix=''): if hasattr(view, 'as_view') and hasattr(view.as_view, '__call__'): view = view.as_view() - return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name, prefix=prefix) + if prefix: + warnings.warn( + 'Support for prefix in macrosurl.url() is deprecated and ' + 'will be removed in version 0.4 (support for prefix was removed in Django 1.10). ' + 'Please update your source code.' + 'In old Django versions prefix was used like "if prefix:view = prefix + \'.\' + view".' + ) + + view = prefix + '.' + view + + if DJANGO_VERSION >= StrictVersion('1.10') and not callable(view) and not isinstance(view, (list, tuple)): + warnings.warn( + 'View "%s" must be a callable in case of Django 1.10. ' + 'Macrosurl will try to load the view automatically (this behavior will be removed in version 0.4), but ' + 'please update your source code.' % view + ) + + from django.utils.module_loading import import_string + + view = import_string(view) + + return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name) diff --git a/tests/urls.py b/tests/urls.py index 14460b8..8af933b 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,4 +1,8 @@ import os +import warnings + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") + import sys import uuid @@ -13,6 +17,9 @@ class TestRegexCompilation(unittest.TestCase): + def setUp(self): + warnings.filterwarnings("ignore") + def test_nomacro(self): self.assertEqual(MacroUrlPattern('^$').compiled, '^$') self.assertEqual(MacroUrlPattern('^news/all/$').compiled, '^news/all/$') @@ -92,13 +99,15 @@ def test_strongurl(self): def test_includes_end(self): self.assertEqual(str(url('users/:slug', include('tests'))._regex), '^users/(?P[\\w-]+)') self.assertEqual(str(url('users/:slug', include('tests', namespace='1'))._regex), '^users/(?P[\\w-]+)') - self.assertEqual(str(url('users/:slug', 'tests')._regex), '^users/(?P[\\w-]+)$') + self.assertEqual(str(url('users/:slug', 'tests.views.view')._regex), '^users/(?P[\\w-]+)$') class TestRegexUrlResolving(unittest.TestCase): def setUp(self): self.view = 'tests.views.view' + warnings.filterwarnings("ignore") + def test_id(self): self.assertIsNone(url('product/:id', self.view).resolve('product/test')) self.assertIsNotNone(url('product/:id', self.view).resolve('product/10')) @@ -143,7 +152,7 @@ def test_date(self): self.assertIsNotNone(url('news/:date', self.view).resolve('news/%s-%s-%s' % (y, m, d))) def test_uuid(self): - self.assertIsNone(url("invoice/:uuid", 'view').resolve('invoice/123123-123123-1231231-1231312-3-1312312-')) + self.assertIsNone(url("invoice/:uuid", self.view).resolve('invoice/123123-123123-1231231-1231312-3-1312312-')) for i in range(1, 1000): self.assertIsNotNone(url("invoice/:uuid", self.view).resolve('invoice/%s' % uuid.uuid4()))