'Tree Menu Auto Generate
Every app listed at INSTALLED_APPS is scanned
1st - app_name.forms is imported. All its objects/classes are scanned
looking for ModelForm classes
2nd - app_name.nav is imported. TreeNode classes are scanned for
hard-coded menu entries or overwriting
3rd - app_name.models is imported. models.Model classes are scanned,
if a related ModelForm is found several entries are Added to the Menu
- Objects
- Add (Model)
- View (Model)'

def generate(self, request=None):

    self._generated = True
    self._navs.clear()
    tree_roots.clear()
    childs_of = []
    if hasattr(notifier, 'failover_status'):
        fstatus = notifier().failover_status()
    else:
        fstatus = 'SINGLE'
    for app in settings.INSTALLED_APPS:
        if (app in getattr(settings, 'BLACKLIST_NAV', [])):
            continue
        try:
            self._generate_app(app, request, tree_roots, childs_of, fstatus)
        except Exception as e:
            log.error('Failed    to    generate    navtree    for    app    %s:    %s', app, e)
            log_traceback(log=log)
    nav = TreeRoot('documentation', name=_('Guide'), icon=(get_sw_name() + 'GuideIcon'), action='opendocumentation', view='documentation_home', order=970)
    tree_roots.register(nav)
    nav = TreeRoot('display', name=_('Display    System    Processes'), action='displayprocs', icon='TopIcon', order=985)
    tree_roots.register(nav)
    if (fstatus in ('MASTER', 'SINGLE')):
        nav = TreeRoot('initialwizard', name=_('Wizard'), icon='WizardIcon', action='wizard', order=980)
        tree_roots.register(nav)
    nav = TreeRoot('shell', name=_('Shell'), icon='ShellIcon', action='shell', order=990)
    tree_roots.register(nav)
    nav = TreeRoot('logout', name=_('Log    Out'), icon='LogOutIcon', action='logout', order=995)
    tree_roots.register(nav)
    nav = TreeRoot('reboot', name=_('Reboot'), action='reboot', icon='RebootIcon', type='scary_dialog', view='system_reboot_dialog', order=999)
    tree_roots.register(nav)
    nav = TreeRoot('shutdown', name=_('Shutdown'), icon='ShutdownIcon', type='scary_dialog', view='system_shutdown_dialog', order=1000)
    tree_roots.register(nav)
    for (opt, model) in childs_of:
        for nav in tree_roots:
            exists = nav.find_gname(model._admin.menu_child_of)
            if (exists is not False):
                exists.append_child(opt)
                break
        if (exists is False):
            log.debug('Could    not    find    %s    to    attach    %r', model._admin.menu_child_of, opt)
    self.replace_navs(tree_roots)
    jails = []
    for j in Jails.objects.all():
        if ((j.jail_type == WARDEN_TYPE_PLUGINJAIL) and (j.jail_status == WARDEN_STATUS_RUNNING)):
            jails.append(j)
    self._get_plugins_nodes(request, jails)
