def get_avail_models(context): """ Returns (model, perm,) for all models user can possibly see """ items = [] admin_site = get_admin_site(context) for model, model_admin in list(admin_site._registry.items()): perms = model_admin.get_model_perms(context.get('request')) if True not in list(perms.values()): continue items.append((model, perms,)) return items
def init_with_context(self, context): self.children += [ items.MenuItem( title=get_admin_site(context).site_header, url=None, icon='fa-gears', css_styles='font-size: 1.5em;', ), items.UserTools( css_styles='float: right;', is_user_allowed=lambda user: user.is_active and user.is_staff, ), ]
def init_with_context(self, context): model_map = get_model_map(get_admin_site(context)) for entry in self.subtree: children = None kwargs = {} if isinstance(entry, dict): kwargs['title'] = entry.get('title') kwargs['icon'] = entry.get('icon') kwargs['url'] = entry.get('url') model = entry.get('model') children = entry.get('children') elif isinstance(entry, tuple) and len(entry) == 2: model, kwargs['icon'] = entry else: model = entry if model is not None: model = model_map.get(model) if model is None: continue kwargs['url'] = self._get_admin_change_url(model, context) kwargs['add_url'] = self._get_admin_add_url(model, context) if kwargs.get('title') is None: kwargs['title'] = capfirst(model._meta.verbose_name_plural) if isinstance(entry, dict): kwargs['description'] = entry.get('description', kwargs.get('title')) else: kwargs['description'] = kwargs.get('title') if children is None: self.children.append(MenuItem(**kwargs)) else: self.children.append(SubModelMenu(subtree=children, **kwargs))