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 pop_model(self, apps, model): try: (model, title) = model except: (model, title) = (model, "") parts = model.split('.') if len(parts) == 2: (app_label, model_class) = parts app_dict = apps.get(app_label) if app_dict: models = app_dict.get('models') for i, model_dict in enumerate(models): if model_dict: if model_dict and (model_dict.get('classname') == model_class): models[i] = None if title: model_dict['title'] = title return model_dict return None
def _init_with_context(self, context): always_selected = _get_settings('menu.always_selected', default=[]) apps = _make_apps(context) for app in self.sort_app(apps): self.append_app(apps.get(app), always_selected=_check_always_selected(always_selected, app))