jet_custom_apps_example.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_noargs(self, **options):
  10. class User:
  11. is_active = True
  12. is_staff = True
  13. is_superuser = True
  14. def has_module_perms(self, app):
  15. return True
  16. def has_perm(self, object):
  17. return True
  18. class Request:
  19. user = User()
  20. app_list = get_app_list({
  21. 'request': Request(),
  22. 'user': None
  23. })
  24. self.stdout.write('# Add this to your settings.py to customize applications and models list')
  25. self.stdout.write('JET_SIDE_MENU_CUSTOM_APPS = [')
  26. for app in app_list:
  27. app_label = app.get('app_label', app.get('name'))
  28. self.stdout.write(' (\'%s\', [' % app_label)
  29. for model in app['models']:
  30. self.stdout.write(' \'%s\',' % model['object_name'])
  31. self.stdout.write(' ]),')
  32. self.stdout.write(']')