Permalink
Browse files

Option to require new style urls

To help with migrating away from old style URLs, there is an option that
can error on every file containing an old style url
  • Loading branch information...
1 parent 35580b2 commit 8577559d58232c8966cc7b54ee9dd8302d8ec62f @theospears theospears committed Nov 16, 2012
@@ -20,6 +20,8 @@ class Command(BaseCommand):
default=False, help="Break on first error."),
make_option('--check-urls', '-u', action='store_true', dest='check_urls',
default=False, help="Check url tag view names are quoted appropriately"),
+ make_option('--force-new-urls', '-n', action='store_true', dest='force_new_urls',
+ default=False, help="Error on usage of old style url tags (without {% load urls from future %}"),
make_option('--include', '-i', action='append', dest='includes',
default=[], help="Append these paths to TEMPLATE_DIRS")
)
@@ -51,7 +53,7 @@ def handle(self, *args, **options):
filepath = os.path.join(root, filename)
if verbosity>1:
print filepath
- validatingtemplatetags.before_new_template()
+ validatingtemplatetags.before_new_template(options.get('force_new_urls', False))
try:
template_loader.load_template(filename, [root])
except Exception, e:
@@ -3,13 +3,15 @@
from django.templatetags import future
register = Library()
+error_on_old_style_url_tag = False
new_style_url_tag = False
errors = []
-def before_new_template():
+def before_new_template(force_new_urls):
"""Reset state ready for new template"""
- global new_style_url_tag, errors
+ global new_style_url_tag, error_on_old_style_url_tag, errors
new_style_url_tag = False
+ error_on_old_style_url_tag = force_new_urls
errors = []
def get_template_errors():
@@ -50,9 +52,15 @@ def load(parser, token):
@register.tag(name='url')
def old_style_url(parser, token):
+ global error_on_old_style_url_tag
+
bits = token.split_contents()
view = bits[1]
+ if error_on_old_style_url_tag:
+ _error("Old style url tag used (only reported once per file): {%% %s %%}" % (" ".join(bits)), token)
+ error_on_old_style_url_tag = False
+
if view[0] in "\"'" and view[0] == view[-1]:
_error("Old style url tag with quotes around view name: {%% %s %%}" % (" ".join(bits)), token)

0 comments on commit 8577559

Please sign in to comment.