2
2
3
3
from django .conf .urls import url as baseurl
4
4
5
- VERSION = (0 , 1 , 0 )
5
+ VERSION = (0 , 1 , 1 )
6
6
7
7
_macros_library = {
8
8
'id' : r'\d+' ,
@@ -27,14 +27,18 @@ def regex_group(macro, pattern):
27
27
return '(?P<%s>%s)' % (macro , pattern )
28
28
29
29
30
- def normalize_pattern (url ):
31
- return '^%s$' % url .lstrip ("^ \n " ).rstrip ("$ \n " )
30
+ def normalize_pattern (url , end_dollar = True ):
31
+ pattern = '^%s$'
32
+ if not end_dollar :
33
+ pattern = '^%s'
34
+
35
+ return pattern % url .lstrip ("^ \n " ).rstrip ("$ \n " )
32
36
33
37
34
38
class MacroUrlPattern (object ):
35
- def __init__ (self , pattern ):
39
+ def __init__ (self , pattern , end_dollar = True ):
36
40
self .pattern = pattern
37
-
41
+ self . end_dollar = end_dollar
38
42
39
43
def compile (self ):
40
44
pattern = self .pattern
@@ -48,7 +52,7 @@ def compile(self):
48
52
pattern = pattern .replace (match , regex_group (macro , _macros_library [_macro ]))
49
53
continue
50
54
51
- return normalize_pattern (pattern )
55
+ return normalize_pattern (pattern , self . end_dollar )
52
56
53
57
@property
54
58
def compiled (self ):
@@ -65,4 +69,8 @@ def __unicode__(self):
65
69
66
70
67
71
def url (regex , view , kwargs = None , name = None , prefix = '' ):
68
- return baseurl (MacroUrlPattern (regex ), view , kwargs = kwargs , name = name , prefix = prefix )
72
+ end_dollar = True
73
+ if isinstance (view , tuple ) and len (view ) == 3 :
74
+ end_dollar = False
75
+
76
+ return baseurl (MacroUrlPattern (regex , end_dollar = end_dollar ), view , kwargs = kwargs , name = name , prefix = prefix )
0 commit comments