def init_with_context(self, context): app_list = get_app_list(context) app_to_remove = [] for app in app_list: app_name = app.get("app_label", app.get("name", "")) app["models"] = filter( lambda model: self.models is None or ("%s.%s" % (app_name, model["object_name"])) in self.models or ("%s.*" % app_name) in self.models, app["models"], ) app["models"] = filter( lambda model: self.exclude is None or ( ("%s.%s" % (app_name, model["object_name"])) not in self.exclude and ("%s.*" % app_name) not in self.exclude), app["models"], ) app["models"] = list(app["models"]) if self.hide_empty and len(list(app["models"])) == 0: app_to_remove.append(app) for app in app_to_remove: app_list.remove(app) self.children = app_list
def test_get_app_list(self): class User: is_active = True is_staff = True def has_module_perms(self, app): return True def has_perm(self, obj): return True class Request: user = User() app_list = get_app_list({'request': Request(), 'user': None}) self.assertIsInstance(app_list, list) for app in app_list: self.assertIsInstance(app, dict) self.assertIsNotNone(app, app.get('models')) self.assertIsNotNone(app, app.get('app_url')) self.assertIsNotNone(app, app.get('app_label')) for model in app['models']: self.assertIsNotNone(app, model.get('object_name')) self.assertIsNotNone(app, model.get('name'))
def get_menu(context): app_list = get_app_list(context) current_found = False pinned = PinnedApplication.objects.values_list('app_label', flat=True) apps = [] pinned_apps = [] for app in app_list: if not current_found: for model in app['models']: if context['request'].path.startswith(model['admin_url']): model['current'] = True current_found = True break if not current_found and context['request'].path.startswith(app['app_url']): app['current'] = True current_found = True if app.get('app_label', app.get('name')) in pinned: pinned_apps.append(app) else: apps.append(app) return {'apps': apps, 'pinned_apps': pinned_apps}
def handle_noargs(self, **options): class User: is_active = True is_staff = True def has_module_perms(self, app): return True def has_perm(self, object): return True class Request: user = User() app_list = get_app_list({ 'request': Request(), 'user': None }) self.stdout.write('# Add this to your settings.py to customize applications and models list') self.stdout.write('JET_SIDE_MENU_CUSTOM_APPS = [') for app in app_list: app_label = app.get('app_label', app.get('name')) self.stdout.write(' (\'%s\', [' % app_label) for model in app['models']: self.stdout.write(' \'%s\',' % model['object_name']) self.stdout.write(' ]),') self.stdout.write(']')
def handle_noargs(self, **options): class User: is_active = True is_staff = True is_superuser = True def has_module_perms(self, app): return True def has_perm(self, object): return True class Request: user = User() app_list = get_app_list({'request': Request(), 'user': None}) self.stdout.write( '# Add this to your settings.py to customize applications and models list' ) self.stdout.write('JET_SIDE_MENU_CUSTOM_APPS = [') for app in app_list: app_label = app.get('app_label', app.get('name')) self.stdout.write(' (\'%s\', [' % app_label) for model in app['models']: self.stdout.write(' \'%s\',' % model['object_name']) self.stdout.write(' ]),') self.stdout.write(']')
def get_menu(context): app_list = get_app_list(context) current_found = False pinned = PinnedApplication.objects.values_list('app_label', flat=True) apps = [] pinned_apps = [] for app in app_list: if not current_found: for model in app['models']: if context['request'].path.startswith(model['admin_url']): model['current'] = True current_found = True break if not current_found and context['request'].path.startswith( app['app_url']): app['current'] = True current_found = True if app.get('app_label', app.get('name')) in pinned: pinned_apps.append(app) else: apps.append(app) return {'apps': apps, 'pinned_apps': pinned_apps}
def test_get_app_list(self): class User: is_active = True is_staff = True def has_module_perms(self, app): return True def has_perm(self, object): return True class Request: user = User() app_list = get_app_list({ 'request': Request(), 'user': None }) self.assertIsInstance(app_list, list) for app in app_list: self.assertIsInstance(app, dict) self.assertIsNotNone(app, app.get('models')) self.assertIsNotNone(app, app.get('app_url')) self.assertIsNotNone(app, app.get('app_label')) for model in app['models']: self.assertIsNotNone(app, model.get('object_name')) self.assertIsNotNone(app, model.get('name'))
def handle_noargs(self, **options): class User: is_active = True is_staff = True is_superuser = True def has_module_perms(self, app): return True def has_perm(self, object): return True class Request: user = User() app_list = get_app_list({"request": Request(), "user": None}) self.stdout.write( "# Add this to your settings.py to customize applications and models list" ) self.stdout.write("JET_SIDE_MENU_CUSTOM_APPS = [") for app in app_list: app_label = app.get("app_label", app.get("name")) self.stdout.write(" ('%s', [" % app_label) for model in app["models"]: self.stdout.write(" '%s'," % model["object_name"]) self.stdout.write(" ]),") self.stdout.write("]")
def test_get_app_list(self): class User: is_active = True is_staff = True def has_module_perms(self, app): return True def has_perm(self, object): return True class Request: user = User() app_list = get_app_list({"request": Request(), "user": None}) self.assertIsInstance(app_list, list) for app in app_list: self.assertIsInstance(app, dict) self.assertIsNotNone(app, app.get("models")) self.assertIsNotNone(app, app.get("app_url")) self.assertIsNotNone(app, app.get("app_label")) for model in app["models"]: self.assertIsNotNone(app, model.get("object_name")) self.assertIsNotNone(app, model.get("name"))
def init_with_context(self, context): app_list = get_app_list(context) models = [] for app in app_list: app['models'] = filter( lambda model: self.models is None or model['object_name'] in self.models or app.get('app_label', app.get('name')) + '.*' in self.models, app['models'] ) app['models'] = filter( lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get('name')) + '.*' not in self.exclude, app['models'] ) app['models'] = list(app['models']) models.extend(app['models']) self.children = models
def init_with_context(self, context): app_list = get_app_list(context) models = [] for app in app_list: app_name = app.get('app_label', app.get('name', '')) app['models'] = filter( lambda model: self.models is None or ('%s.%s' % (app_name, model['object_name'])) in self.models or ('%s.*' % app_name) in self.models, app['models'] ) app['models'] = filter( lambda model: self.exclude is None or (('%s.%s' % (app_name, model['object_name'])) not in self.exclude and ('%s.*' % app_name) not in self.exclude), app['models'] ) app['models'] = list(app['models']) models.extend(app['models']) self.children = models
def init_with_context(self, context): app_list = get_app_list(context) models = [] for app in app_list: app['models'] = filter( lambda model: self.models is None or model[ 'object_name'] in self.models or app.get( 'app_label', app.get('name')) + '.*' in self.models, app['models']) app['models'] = filter( lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get( 'name')) + '.*' not in self.exclude, app['models']) app['models'] = list(app['models']) models.extend(app['models']) self.children = models
def init_with_context(self, context): app_list = get_app_list(context) app_to_remove = [] for app in app_list: app['models'] = filter( lambda model: self.models is None or model['object_name'] in self.models or app.get('app_label', app.get('name')) + '.*' in self.models, app['models'] ) app['models'] = filter( lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get('name')) + '.*' not in self.exclude, app['models'] ) app['models'] = list(app['models']) if self.hide_empty and len(list(app['models'])) == 0: app_to_remove.append(app) for app in app_to_remove: app_list.remove(app) self.children = app_list
def init_with_context(self, context): app_list = get_app_list(context) app_to_remove = [] for app in app_list: app_name = app.get('app_label', app.get('name', '')) app['models'] = filter( lambda model: self.models is None or ('%s.%s' % (app_name, model['object_name'])) in self.models or ('%s.*' % app_name) in self.models, app['models'] ) app['models'] = filter( lambda model: self.exclude is None or (('%s.%s' % (app_name, model['object_name'])) not in self.exclude and ('%s.*' % app_name) not in self.exclude), app['models'] ) app['models'] = list(app['models']) if self.hide_empty and len(list(app['models'])) == 0: app_to_remove.append(app) for app in app_to_remove: app_list.remove(app) self.children = app_list
def init_with_context(self, context): app_list = get_app_list(context) app_to_remove = [] for app in app_list: app['models'] = filter( lambda model: self.models is None or model[ 'object_name'] in self.models or app.get( 'app_label', app.get('name')) + '.*' in self.models, app['models']) app['models'] = filter( lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get( 'name')) + '.*' not in self.exclude, app['models']) app['models'] = list(app['models']) if self.hide_empty and len(list(app['models'])) == 0: app_to_remove.append(app) for app in app_to_remove: app_list.remove(app) self.children = app_list
def init_with_context(self, context): app_list = get_app_list(context) models = [] for app in app_list: app_name = app.get("app_label", app.get("name", "")) app["models"] = filter( lambda model: self.models is None or ("%s.%s" % (app_name, model["object_name"])) in self.models or ("%s.*" % app_name) in self.models, app["models"], ) app["models"] = filter( lambda model: self.exclude is None or ( ("%s.%s" % (app_name, model["object_name"])) not in self.exclude and ("%s.*" % app_name) not in self.exclude), app["models"], ) app["models"] = list(app["models"]) models.extend(app["models"]) self.children = models
def get_current_app(self): app_list = get_app_list({'request': self.request}) for app in app_list: if app.get('app_label', app.get('name')) == self.object.app_label: return app
def jet_get_menu(context): if settings.JET_SIDE_MENU_CUSTOM_APPS not in (None, False): app_list = get_app_list(context, False) app_dict = {} models_dict = {} for app in app_list: app_label = app.get('app_label', app.get('name')) app_dict[app_label] = app for model in app['models']: if app_label not in models_dict: models_dict[app_label] = {} models_dict[app_label][model['object_name']] = model app['models'] = [] app_list = [] settings_app_list = settings.JET_SIDE_MENU_CUSTOM_APPS if isinstance(settings_app_list, dict): admin_site = get_admin_site(context) settings_app_list = settings_app_list.get(admin_site.name, []) for item in settings_app_list: app_label, models = item if app_label in app_dict: app = app_dict[app_label] for model_label in models: if model_label == '__all__': app['models'] = models_dict[app_label].values() break elif model_label in models_dict[app_label]: model = models_dict[app_label][model_label] app['models'].append(model) app_list.append(app) else: app_list = get_app_list(context) current_found = False pinned = PinnedApplication.objects.filter( user=context.get('user').pk).values_list('app_label', flat=True) all_aps = [] apps = [] pinned_apps = [] for app in app_list: if not current_found: for model in app['models']: if context['request'].path.startswith(model['admin_url']): model['current'] = True current_found = True break if not current_found and context['request'].path.startswith( app['app_url']): app['current'] = True current_found = True if app.get('app_label', app.get('name')) in pinned: pinned_apps.append(app) else: apps.append(app) all_aps.append(app) return {'apps': apps, 'pinned_apps': pinned_apps, 'all_apps': all_aps}
def get_current_app(self): app_list = get_app_list({"request": self.request}) for app in app_list: if app.get("app_label", app.get("name")) == self.object.app_label: return app
def jet_get_menu(context): if settings.JET_SIDE_MENU_CUSTOM_APPS not in (None, False): app_list = get_app_list(context, False) app_dict = {} models_dict = {} for app in app_list: app_label = app.get('app_label', app.get('name')) app_dict[app_label] = app for model in app['models']: if app_label not in models_dict: models_dict[app_label] = {} models_dict[app_label][model['object_name']] = model app['models'] = [] app_list = [] settings_app_list = settings.JET_SIDE_MENU_CUSTOM_APPS if isinstance(settings_app_list, dict): admin_site = get_admin_site(context) settings_app_list = settings_app_list.get(admin_site.name, []) for item in settings_app_list: app_label, models = item if app_label in app_dict: app = app_dict[app_label] for model_label in models: if model_label == '__all__': app['models'] = models_dict[app_label].values() break elif model_label in models_dict[app_label]: model = models_dict[app_label][model_label] app['models'].append(model) app_list.append(app) else: app_list = get_app_list(context) current_found = False pinned = PinnedApplication.objects.filter(user=context.get('user').pk).values_list('app_label', flat=True) all_aps = [] apps = [] pinned_apps = [] for app in app_list: if not current_found: for model in app['models']: if 'admin_url' in model and context['request'].path.startswith(model['admin_url']): model['current'] = True current_found = True break if not current_found and context['request'].path.startswith(app['app_url']): app['current'] = True current_found = True if app.get('app_label', app.get('name')) in pinned: pinned_apps.append(app) else: apps.append(app) all_aps.append(app) return {'apps': apps, 'pinned_apps': pinned_apps, 'all_apps': all_aps}