haikal/inventory/context_processors.py

45 lines
1.7 KiB
Python

from django.conf import settings
from inventory.utils import get_user_type
def currency_context(request):
"""
Provides a context dictionary containing the currency setting. This is typically
used for rendering templates with the appropriate currency value.
:param request: The HTTP request object. This parameter is not used within
the function but is included to maintain compatibility with
context processor signature.
:type request: HttpRequest
:return: A dictionary with the key 'CURRENCY' containing the value of the
project's CURRENCY setting.
:rtype: dict
"""
return {"CURRENCY": settings.CURRENCY}
def breadcrumbs(request):
"""
Generates a breadcrumb trail for the given request path.
The function processes the request's path, splits it into individual
segments, and creates a list of breadcrumb entries, each representing
a segment of the path. Each breadcrumb entry consists of a 'name'
(key) and its associated 'url' (key). The 'name' is a title-cased
representation of the path segment, and the 'url' is the cumulative URL
path leading to that segment.
:param request: The request object containing the path to be processed.
:type request: Any
:return: A dictionary containing a list of breadcrumbs, where each
breadcrumb is represented by a dictionary with 'name' and 'url'.
:rtype: dict
"""
breadcrumbs = []
path = request.path.strip("/").split("/")
for i in range(len(path)):
url = "/" + "/".join(path[: i + 1]) + "/"
breadcrumbs.append({"name": path[i].capitalize(), "url": url})
return {"breadcrumbs": breadcrumbs}