Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation indicator for URLs when using JSON format. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions django_extensions/management/commands/show_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand All @@ -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)),
Expand Down Expand Up @@ -211,8 +216,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)
Copy link

@twiden twiden Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value has two defaults. this is 2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. That's what I get for refactoring :)


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)):
Expand Down