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

Doesn't work for classes #12

Open
mjamalil opened this issue Apr 1, 2021 · 0 comments
Open

Doesn't work for classes #12

mjamalil opened this issue Apr 1, 2021 · 0 comments

Comments

@mjamalil
Copy link

mjamalil commented Apr 1, 2021

This doesn't work for class following diff should be applied to fix it

diff --git a/django_unused/unused/find_views.py b/django_unused/unused/find_views.py
index 4b5a766..4761ea1 100644
--- a/django_unused/unused/find_views.py
+++ b/django_unused/unused/find_views.py
@@ -1,10 +1,7 @@
url_view_names = get_view_names(urlpatterns, non_matches)
return url_view_names
@@ -107,10 +104,23 @@ def get_view_names(url_list, non_matches, view_names=None):
view_names = []
for entry in url_list:
# If the entry is not a single pattern, recursively traverse the lists until we hit a single pattern.
+

  •    if hasattr(entry.callback, '__name__'):
    
  •        name = entry.callback.__name__
    
  •    elif hasattr(entry.callback, '__class__'):
    
  •        name = entry.callback.__class__.__name__
    
  •    else:
    
  •        raise ValueError("can't find the name of this view -> {}".format(entry.callback))
       if hasattr(entry, 'url_patterns'):
           get_view_names(entry.url_patterns, non_matches, view_names)
       # If a single pattern is not one of the non-matches, add it to our list of view names.
    
  •    elif entry.callback.__name__ not in non_matches:
    
  •        view_names.append(entry.callback.__name__)
    
  •    elif name not in non_matches:
    
  •        view_names.append(name)
    

    return view_names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant