Skip to content

Commit 2ff37b8

Browse files
committed
v0.3.0
------ Added support for Django 1.10 version.
1 parent 098c2b2 commit 2ff37b8

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
- DJANGO=1.7
1111
- DJANGO=1.8
1212
- DJANGO=1.9
13+
- DJANGO=1.10
1314
install:
1415
- pip install -q Django==$DJANGO
1516
script:
@@ -25,3 +26,6 @@ matrix:
2526

2627
- python: "2.6"
2728
env: DJANGO=1.9
29+
30+
- python: "2.6"
31+
env: DJANGO=1.10

CHANGELOG.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.3.0
2+
------
3+
4+
Added support for Django 1.10 version.
5+
16
v0.2.3
27
------
38

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Django Macros URL](https://github.com/phpdude/django-macros-url/) v0.2.3 - Routing must be simple as possible
1+
# [Django Macros URL](https://github.com/phpdude/django-macros-url/) v0.3.0 - Routing must be simple as possible
22

33
Django Macros URL makes it easy to write (and read) URL patterns in your Django applications by using macros.
44

macrosurl/__init__.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import re
2+
import warnings
3+
from distutils.version import StrictVersion
24

3-
VERSION = (0, 2, 3)
5+
VERSION = (0, 3, 0)
6+
DJANGO_VERSION = None
47

58
_macros_library = {
69
'id': r'\d+',
@@ -71,6 +74,13 @@ def __unicode__(self):
7174
def url(regex, view, kwargs=None, name=None, prefix=''):
7275
from django.conf.urls import url as baseurl
7376

77+
if DJANGO_VERSION is None:
78+
global DJANGO_VERSION
79+
80+
from django import get_version
81+
82+
DJANGO_VERSION = get_version()
83+
7484
# Handle include()'s in views.
7585
end_dollar = True
7686
if isinstance(view, tuple) and len(view) == 3:
@@ -81,4 +91,25 @@ def url(regex, view, kwargs=None, name=None, prefix=''):
8191
if hasattr(view, 'as_view') and hasattr(view.as_view, '__call__'):
8292
view = view.as_view()
8393

84-
return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name, prefix=prefix)
94+
if prefix:
95+
warnings.warn(
96+
'Support for prefix in macrosurl.url() is deprecated and '
97+
'will be removed in version 0.4 (support for prefix was removed in Django 1.10). '
98+
'Please update your source code.'
99+
'In old Django versions prefix was used like "if prefix:view = prefix + \'.\' + view".'
100+
)
101+
102+
view = prefix + '.' + view
103+
104+
if DJANGO_VERSION >= StrictVersion('1.10') and not callable(view) and not isinstance(view, (list, tuple)):
105+
warnings.warn(
106+
'View "%s" must be a callable in case of Django 1.10. '
107+
'Macrosurl will try to load the view automatically (this behavior will be removed in version 0.4), but '
108+
'please update your source code.' % view
109+
)
110+
111+
from django.utils.module_loading import import_string
112+
113+
view = import_string(view)
114+
115+
return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name)

tests/urls.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import os
2+
import warnings
3+
4+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
5+
26
import sys
37
import uuid
48

@@ -13,6 +17,9 @@
1317

1418

1519
class TestRegexCompilation(unittest.TestCase):
20+
def setUp(self):
21+
warnings.filterwarnings("ignore")
22+
1623
def test_nomacro(self):
1724
self.assertEqual(MacroUrlPattern('^$').compiled, '^$')
1825
self.assertEqual(MacroUrlPattern('^news/all/$').compiled, '^news/all/$')
@@ -92,13 +99,15 @@ def test_strongurl(self):
9299
def test_includes_end(self):
93100
self.assertEqual(str(url('users/:slug', include('tests'))._regex), '^users/(?P<slug>[\\w-]+)')
94101
self.assertEqual(str(url('users/:slug', include('tests', namespace='1'))._regex), '^users/(?P<slug>[\\w-]+)')
95-
self.assertEqual(str(url('users/:slug', 'tests')._regex), '^users/(?P<slug>[\\w-]+)$')
102+
self.assertEqual(str(url('users/:slug', 'tests.views.view')._regex), '^users/(?P<slug>[\\w-]+)$')
96103

97104

98105
class TestRegexUrlResolving(unittest.TestCase):
99106
def setUp(self):
100107
self.view = 'tests.views.view'
101108

109+
warnings.filterwarnings("ignore")
110+
102111
def test_id(self):
103112
self.assertIsNone(url('product/:id', self.view).resolve('product/test'))
104113
self.assertIsNotNone(url('product/:id', self.view).resolve('product/10'))
@@ -143,7 +152,7 @@ def test_date(self):
143152
self.assertIsNotNone(url('news/:date', self.view).resolve('news/%s-%s-%s' % (y, m, d)))
144153

145154
def test_uuid(self):
146-
self.assertIsNone(url("invoice/:uuid", 'view').resolve('invoice/123123-123123-1231231-1231312-3-1312312-'))
155+
self.assertIsNone(url("invoice/:uuid", self.view).resolve('invoice/123123-123123-1231231-1231312-3-1312312-'))
147156
for i in range(1, 1000):
148157
self.assertIsNotNone(url("invoice/:uuid", self.view).resolve('invoice/%s' % uuid.uuid4()))
149158

0 commit comments

Comments
 (0)