jet_custom_apps_example.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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
  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_app_list({
  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_CUSTOM_APPS = [')
  30. for app in app_list:
  31. app_label = app.get('app_label', app.get('name'))
  32. self.stdout.write(' (\'%s\', [' % app_label)
  33. for model in app['models']:
  34. self.stdout.write(' \'%s\',' % model['object_name'])
  35. self.stdout.write(' ]),')
  36. self.stdout.write(']')