11import 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):
7174def 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 )
0 commit comments