Created
October 17, 2018 19:25
-
-
Save luanfonceca/254eec2662e36f5db8151d09879c59ea to your computer and use it in GitHub Desktop.
Show Permissions management command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mock==2.0.0 | |
django-extensions==1.9.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import inspect | |
import mock | |
from django.core.management.base import BaseCommand | |
from django.core.management import call_command | |
def get_view(name): | |
components = name.split('.') | |
mod = __import__(components[0]) | |
for comp in components[1:]: | |
mod = getattr(mod, comp) | |
return mod | |
class Command(BaseCommand): | |
def add_arguments(self, parser): | |
parser.add_argument('app', nargs='+') | |
def handle(self, *args, **options): | |
app = options.get('app')[0] | |
with mock.patch('sys.stdout'): | |
urls = json.loads(call_command('show_urls', format='json')) | |
for url in urls: | |
if url.get('module').split('.')[0] == app: | |
view = get_view(url.get('module')) | |
path = inspect.getfile(view) | |
print('{}::{}'.format(path, view.__name__)) | |
for permission in view.permission_classes: | |
print('\t- {}'.format(permission.__name__)) | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment