def _init_with_context(self, context): always_selected = _get_settings('menu.always_selected', default=[]) apps = _make_apps(context) customize = _get_settings('menu.custom', default=[]) for node in customize: label = node.get('label') options = node.setdefault('options', { 'always_selected': node.get('always_selected', _check_always_selected(always_selected, label)), 'icon': node.get('icon', None), }) if not node.get('is_app', False): item = node['menuitem'] = MenuItem( title=capfirst(_(label)), description=label, **options ) for model in node.get('models', []): model_dict = self.pop_model(apps, model) if model_dict: item.children.append(MenuItem(**model_dict)) # apps = self.rebuild_apps(apps) for node in customize: label = node.get('label') if not node.get('is_app'): self.children.append(node.get('menuitem')) elif label in apps: self.append_app(apps.get(label), **node.get('options')) del apps[label] # if not _get_settings('menu.append_remaining'): return for label, app_dict in apps.items(): self.append_app(app_dict, always_selected=_check_always_selected(always_selected, label))
def rebuild_apps(self, apps): result = {} for app_label, app_dict in apps.items(): models = list(filter(None, app_dict.get('models'))) if models: app_dict['models'] = models result[app_label] = app_dict return result