From 4ef7af2971c6b2a928005e7cb6b91b4ecbfe4409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Linds=C3=A4th?= Date: Wed, 15 Jul 2020 12:49:05 +0200 Subject: [PATCH] Add deprecation indicator for URLs when using JSON format. Based on release 3.0.2. --- .../management/commands/show_urls.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/django_extensions/management/commands/show_urls.py b/django_extensions/management/commands/show_urls.py index bb0a42d95..5e8eec931 100644 --- a/django_extensions/management/commands/show_urls.py +++ b/django_extensions/management/commands/show_urls.py @@ -121,7 +121,12 @@ def handle(self, *args, **options): raise CommandError("Error occurred while trying to load %s: %s" % (getattr(settings, urlconf), str(e))) view_functions = self.extract_views_from_urlpatterns(urlconf.urlpatterns) - for (func, regex, url_name) in view_functions: + for (func, regex, url_name, *dep_status) in view_functions: + if dep_status: + deprecated = bool(dep_status[0]) + else: + deprecated = False + if hasattr(func, '__globals__'): func_globals = func.__globals__ elif hasattr(func, 'func_globals'): @@ -148,7 +153,7 @@ def handle(self, *args, **options): decorator = ', '.join(decorators) if format_style == 'json': - views.append({"url": url, "module": module, "name": url_name, "decorators": decorator}) + views.append({"url": url, "module": module, "name": url_name, "decorators": decorator, "deprecated": deprecated}) else: views.append(fmtr.format( module='{0}.{1}'.format(style.MODULE(func.__module__), style.MODULE_NAME(func_name)), @@ -203,6 +208,7 @@ def extract_views_from_urlpatterns(self, urlpatterns, base='', namespace=None): """ views = [] for p in urlpatterns: + deprecated = False if isinstance(p, (URLPattern, RegexURLPattern)): try: if not p.name: @@ -211,8 +217,12 @@ def extract_views_from_urlpatterns(self, urlpatterns, base='', namespace=None): name = '{0}:{1}'.format(namespace, p.name) else: name = p.name + deprecated = getattr(p, "deprecated", False) + pattern = describe_pattern(p) - views.append((p.callback, base + pattern, name)) + views.append( + (p.callback, base + pattern, name, deprecated) + ) except ViewDoesNotExist: continue elif isinstance(p, (URLResolver, RegexURLResolver)):