jet_side_menu_items_example.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. try:
  2. from django.core.management.base import NoArgsCommand
  3. except ImportError:
  4. from django.core.management import BaseCommand as NoArgsCommand
  5. from jet.utils import get_app_list, get_original_menu_items
  6. class Command(NoArgsCommand):
  7. help = 'Generates example of JET custom apps setting'
  8. item_order = 0
  9. def handle(self, *args, **options):
  10. if args:
  11. raise CommandError("Command doesn't accept any arguments")
  12. return self.handle_noargs(**options)
  13. def handle_noargs(self, **options):
  14. class User:
  15. is_active = True
  16. is_staff = True
  17. is_superuser = True
  18. def has_module_perms(self, app):
  19. return True
  20. def has_perm(self, object):
  21. return True
  22. class Request:
  23. user = User()
  24. app_list = get_original_menu_items({
  25. 'request': Request(),
  26. 'user': None
  27. })
  28. self.stdout.write('# Add this to your settings.py to customize applications and models list')
  29. self.stdout.write('JET_SIDE_MENU_ITEMS = [')
  30. for app in app_list:
  31. self.stdout.write(' {\'app_label\': \'%s\', \'items\': [' % (
  32. app['app_label']
  33. ))
  34. for model in app['models']:
  35. self.stdout.write(' {\'name\': \'%s\'},' % (
  36. model['name']
  37. ))
  38. self.stdout.write(' ]},')
  39. self.stdout.write(']')