Пример #1
0
def sidebar_props(context):
    request = context["request"]
    search_areas = admin_search_areas.search_items_for_request(request)
    if search_areas:
        search_area = search_areas[0]
    else:
        search_area = None

    account_menu = [
        sidebar.LinkMenuItem("account",
                             _("Account"),
                             reverse("wagtailadmin_account"),
                             icon_name="user"),
        sidebar.LinkMenuItem("logout",
                             _("Log out"),
                             reverse("wagtailadmin_logout"),
                             icon_name="logout"),
    ]

    modules = [
        sidebar.WagtailBrandingModule(),
        sidebar.SearchModule(search_area) if search_area else None,
        sidebar.MainMenuModule(admin_menu.render_component(request),
                               account_menu, request.user),
    ]
    modules = [module for module in modules if module is not None]

    return json_script(
        {
            "modules": JSContext().pack(modules),
        },
        element_id="wagtail-sidebar-props",
    )
Пример #2
0
def menu_props(context):
    request = context['request']
    search_areas = admin_search_areas.search_items_for_request(request)
    if search_areas:
        search_area = search_areas[0]
    else:
        search_area = None

    account_menu = [
        sidebar.LinkMenuItem('account',
                             _("Account"),
                             reverse('wagtailadmin_account'),
                             icon_name='user'),
        sidebar.LinkMenuItem('logout',
                             _("Log out"),
                             reverse('wagtailadmin_logout'),
                             icon_name='logout'),
    ]

    modules = [
        sidebar.WagtailBrandingModule(),
        sidebar.SearchModule(search_area) if search_area else None,
        sidebar.MainMenuModule(admin_menu.render_component(request),
                               account_menu, request.user),
    ]
    modules = [module for module in modules if module is not None]

    return json.dumps({
        'modules': JSContext().pack(modules),
    },
                      cls=DjangoJSONEncoder)