def get_app_index_dashboard(context): """ Returns the admin dashboard defined by the user or the default one. """ # this is a mess, needs cleanup ! app = context['app_list'][0] model_list = [] app_label = None app_title = app['name'] admin_site = get_admin_site(context=context) for model, model_admin in admin_site._registry.items(): if app['name'] == model._meta.app_label.title(): split = model.__module__.find(model._meta.app_label) app_label = model.__module__[0:split] + model._meta.app_label app_title = model._meta.app_label.title() for m in app['models']: if m['name'] == capfirst(model._meta.verbose_name_plural): mod = '%s.%s' % (model.__module__, model.__name__) model_list.append(mod) # if an app has registered its own dashboard, use it if app_label is not None and app_label in Registry.registry: return Registry.registry[app_label](app_title, model_list) # try to discover a general app_index dashboard (with fallback to the # default dashboard) return _get_dashboard_cls(getattr( settings, 'ADMIN_TOOLS_APP_INDEX_DASHBOARD', 'admin_tools.dashboard.dashboards.DefaultAppIndexDashboard' ), context)(app_title, model_list)
def get_app_index_dashboard(context): """ Returns the admin dashboard defined by the user or the default one. """ # this is a mess, needs cleanup ! app = context['app_list'][0] model_list = [] app_label = None app_title = app['name'] admin_site = get_admin_site(context=context) for model, model_admin in admin_site._registry.items(): if app['name'] == model._meta.app_label.title(): split = model.__module__.find(model._meta.app_label) app_label = model.__module__[0:split] + model._meta.app_label app_title = model._meta.app_label.title() for m in app['models']: if m['name'] == capfirst(model._meta.verbose_name_plural): mod = '%s.%s' % (model.__module__, model.__name__) model_list.append(mod) # if an app has registered its own dashboard, use it if app_label is not None and app_label in Registry.registry: return Registry.registry[app_label](app_title, model_list) # try to discover a general app_index dashboard (with fallback to the # default dashboard) return _get_dashboard_cls( getattr(settings, 'ADMIN_TOOLS_APP_INDEX_DASHBOARD', 'admin_tools.dashboard.dashboards.DefaultAppIndexDashboard'), context)(app_title, model_list)
def get_app_index_dashboard(context): """ Returns the admin dashboard defined by the user or the default one. """ # this is a mess, needs cleanup ! app = context["app_list"][0] model_list = [] app_label = None app_title = app["name"] admin_site = get_admin_site(context=context) for model, model_admin in admin_site._registry.items(): if app["name"] == model._meta.app_label.title(): split = model.__module__.find(model._meta.app_label) app_label = model.__module__[0:split] + model._meta.app_label app_title = model._meta.app_label.title() for m in app["models"]: if m["name"] == capfirst(model._meta.verbose_name_plural): mod = "%s.%s" % (model.__module__, model.__name__) model_list.append(mod) # if an app has registered its own dashboard, use it if app_label is not None and app_label in Registry.registry: return Registry.registry[app_label](app_title, model_list) # try to discover a general app_index dashboard (with fallback to the # default dashboard) dashboard_cls = getattr( settings, "ADMIN_TOOLS_APP_INDEX_DASHBOARD", "admin_tools.dashboard.DefaultAppIndexDashboard" ) if type(dashboard_cls) is types.DictType: curr_url = context.get("request").META["PATH_INFO"] for key in dashboard_cls: admin_site_mod, admin_site_inst = key.rsplit(".", 1) admin_site_mod = import_module(admin_site_mod) admin_site = getattr(admin_site_mod, admin_site_inst) admin_url = reverse("%s:index" % admin_site.name) if curr_url.startswith(admin_url): mod, inst = dashboard_cls[key].rsplit(".", 1) mod = import_module(mod) return getattr(mod, inst)(app_title, model_list) else: mod, inst = dashboard_cls.rsplit(".", 1) mod = import_module(mod) return getattr(mod, inst)(app_title, model_list)
def get_app_index_dashboard(context): """ Returns the admin dashboard defined by the user or the default one. """ # this is a mess, needs cleanup ! app = context['app_list'][0] model_list = [] app_label = None app_title = app['name'] admin_site = get_admin_site(context=context) for model, model_admin in admin_site._registry.items(): if app['name'] == model._meta.app_label.title(): split = model.__module__.find(model._meta.app_label) app_label = model.__module__[0:split] + model._meta.app_label app_title = model._meta.app_label.title() for m in app['models']: if m['name'] == capfirst(model._meta.verbose_name_plural): mod = '%s.%s' % (model.__module__, model.__name__) model_list.append(mod) # if an app has registered its own dashboard, use it if app_label is not None and app_label in Registry.registry: return Registry.registry[app_label](app_title, model_list) # try to discover a general app_index dashboard (with fallback to the # default dashboard) dashboard_cls = getattr(settings, 'ADMIN_TOOLS_APP_INDEX_DASHBOARD', 'admin_tools.dashboard.DefaultAppIndexDashboard') if type(dashboard_cls) is types.DictType: curr_url = context.get('request').META['PATH_INFO'] for key in dashboard_cls: admin_site_mod, admin_site_inst = key.rsplit('.', 1) admin_site_mod = import_module(admin_site_mod) admin_site = getattr(admin_site_mod, admin_site_inst) admin_url = reverse('%s:index' % admin_site.name) if curr_url.startswith(admin_url): mod, inst = dashboard_cls[key].rsplit('.', 1) mod = import_module(mod) return getattr(mod, inst)(app_title, model_list) else: mod, inst = dashboard_cls.rsplit('.', 1) mod = import_module(mod) return getattr(mod, inst)(app_title, model_list)
def init_with_context(self, context): self.request = context['request'] resolved = resolve(context['request'].path) admin_site = get_admin_site(context['request']) grouped = {} for model, model_admin in admin_site._registry.items(): if not context['request'].user.has_perm('%s.change_%s' % (model._meta.app_label, model.__name__.lower())): continue if hasattr(model_admin, 'admin_menu_group'): group_data = getattr(model_admin, 'admin_menu_group') if not group_data[0] in grouped: grouped[group_data[0]] = CustomMenuItem(title=group_data[1], url="#") path = "%s_%s_" % (model._meta.app_label, model.__name__.lower()) title = ugettext(model.__name__) css_classes = [] if hasattr(model_admin, 'admin_menu_count'): count = model_admin.admin_menu_count(model) if count > 0: title = '%s (%d)' % (title, count) css_classes = ['bold', 'count'] grouped[group_data[0]].css_classes = ['bold'] item = CustomMenuItem(title=title, url=reverse("admin:%s_%s_changelist" % (model._meta.app_label, model.__name__.lower())), css_classes=css_classes) if hasattr(resolved, 'url_name') and resolved.url_name.find(path) == 0: item.force_selected = True grouped[group_data[0]].children.append(item) else: grouped[model._meta.app_label] = CustomMenuItem(title=model.__name__, url=reverse("admin:%s_%s_changelist" % (model._meta.app_label, model.__name__.lower()))) if context['request'].user.is_superuser: if not grouped.has_key('community'): grouped['community'] = CustomMenuItem(u'Сообщество', url='#') grouped['community'].children.append(CustomMenuItem(title=u"Пользователи", url=reverse('admin:auth_user_changelist'))) grouped['community'].children.append(CustomMenuItem(title=u"Группы", url=reverse('admin:auth_group_changelist'))) if hasattr(self, 'update_menu'): grouped = getattr(self, 'update_menu')(grouped) self.children += grouped.values()