Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move NAVIGATION_CONTEXT_NAME to core, improve docs

Anna Siwik65abaadb8b7f
diff --git a/docs/guides/navigation.rst b/docs/guides/navigation.rst
index 5bcaa74478..f7df3937f8 100644
--- a/docs/guides/navigation.rst
+++ b/docs/guides/navigation.rst
@@ -3,7 +3,7 @@ Navigation
Saleor gives a possibility to configure storefront navigation. It can be done in dashboard ``Navigation`` tab.
-You can add up to 3 levels of menu items inside every menu you create. Each menu item can point to an internal page with Category, Collection or Page, or an external website by passing an extra URL.
+You can add up to 3 levels of menu items inside every menu you create. Each menu item can point to an internal page with Category, Collection, Page or an external website by passing an extra URL.
Managing menu items
diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py
index a26d54fed4..c362432507 100644
--- a/saleor/core/__init__.py
+++ b/saleor/core/__init__.py
@@ -3,6 +3,7 @@ from django.core.checks import register, Warning
TOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'
'-[0-9a-z]{12})')
+NAVIGATION_CONTEXT_NAME = 'menus'
@register()
diff --git a/saleor/core/context_processors.py b/saleor/core/context_processors.py
index d93b073391..4578f5a553 100644
--- a/saleor/core/context_processors.py
+++ b/saleor/core/context_processors.py
@@ -1,5 +1,6 @@
from django.conf import settings
+from . import NAVIGATION_CONTEXT_NAME
from ..menu.models import Menu
@@ -21,8 +22,8 @@ def default_currency(request):
# pylint: disable=W0613
def navigation(request):
menus = Menu.objects.prefetch_related(
- 'items', 'items__collection', 'items__category', 'items__page').all()
- return {settings.NAVIGATION_CONTEXT_NAME: list(menus)}
+ 'items__collection', 'items__category', 'items__page').all()
+ return {NAVIGATION_CONTEXT_NAME: list(menus)}
def search_enabled(request):
diff --git a/saleor/core/templatetags/shop.py b/saleor/core/templatetags/shop.py
index c8b4ad056f..03ae38e975 100644
--- a/saleor/core/templatetags/shop.py
+++ b/saleor/core/templatetags/shop.py
@@ -1,7 +1,8 @@
-from django.conf import settings
from django.template import Library
from django.utils.http import urlencode
+from ..context_processors import NAVIGATION_CONTEXT_NAME
+
register = Library()
@@ -18,7 +19,7 @@ def get_sort_by_url(context, field, descending=False):
@register.inclusion_tag('menu.html', takes_context=True)
def menu(context, slug, horizontal=False):
- menus = context[settings.NAVIGATION_CONTEXT_NAME]
+ menus = context[NAVIGATION_CONTEXT_NAME]
menu = next((menu for menu in menus if menu.slug == slug), None)
menu_items = menu.get_direct_items() if menu else None
return {'menu_items': menu_items, 'horizontal': horizontal}
diff --git a/saleor/settings.py b/saleor/settings.py
index 0436d2aa56..b4acba2dfe 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -422,7 +422,5 @@ ALLOWED_ATTRIBUTES = {
ALLOWED_STYLES = ['text-align']
-NAVIGATION_CONTEXT_NAME = 'menus'
-
# slugs for menus used in storefront's base template, created by default
DEFAULT_MENUS = ['navbar', 'footer']