1
1
import re
2
+ import warnings
3
+ from distutils .version import StrictVersion
2
4
3
- VERSION = (0 , 2 , 3 )
5
+ VERSION = (0 , 3 , 0 )
6
+ DJANGO_VERSION = None
4
7
5
8
_macros_library = {
6
9
'id' : r'\d+' ,
@@ -71,6 +74,13 @@ def __unicode__(self):
71
74
def url (regex , view , kwargs = None , name = None , prefix = '' ):
72
75
from django .conf .urls import url as baseurl
73
76
77
+ if DJANGO_VERSION is None :
78
+ global DJANGO_VERSION
79
+
80
+ from django import get_version
81
+
82
+ DJANGO_VERSION = get_version ()
83
+
74
84
# Handle include()'s in views.
75
85
end_dollar = True
76
86
if isinstance (view , tuple ) and len (view ) == 3 :
@@ -81,4 +91,25 @@ def url(regex, view, kwargs=None, name=None, prefix=''):
81
91
if hasattr (view , 'as_view' ) and hasattr (view .as_view , '__call__' ):
82
92
view = view .as_view ()
83
93
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 )
0 commit comments