Context Processors
Custom Django context processors for the Smarter dashboard application.
These processors inject template context variables into every view that renders
a template inheriting from base.html. Each processor is registered in
TEMPLATES['OPTIONS']['context_processors'] in Django settings.
Context processors
sidebar()Resolves and caches the href targets for every sidebar navigation link. Returns a
sidebardict keyed by destination name.base()Assembles the primary
dashboardcontext dict: user identity, role flags (is_superuser,is_staff), feature toggles, resource counts, and platform version metadata. The inner result is cached per user.branding()Provides a
brandingdict containing corporate identity, support contact details, social-media URLs, CDN paths, and a dynamic copyright notice. Values are sourced fromsmarter_settings.footer()Provides a
footerdict with links to legal, plans, support, and contact pages.cache_buster()Injects a
cache_busterstring (v=<timestamp>) for appending to static asset URLs in local development.
Cache utilities
cache_invalidations()Invalidates all per-user caches (account, profile, plugins, chatbots, and page-level caches for the dashboard and workbench) after user data changes. Called by signal handlers in the account app.
See also
smarter.apps.account.signals.cache_invalidate
Usage
Add the processors to your Django settings:
TEMPLATES = [
{
"OPTIONS": {
"context_processors": [
...
"smarter.apps.dashboard.context_processors.sidebar",
"smarter.apps.dashboard.context_processors.base",
"smarter.apps.dashboard.context_processors.branding",
"smarter.apps.dashboard.context_processors.footer",
"smarter.apps.dashboard.context_processors.cache_buster",
],
},
}
]
- smarter.apps.dashboard.context_processors.base(request)[source]
Provides the base context for all templates inheriting from
base.htmlin the Smarter dashboard.This context processor injects a comprehensive set of user-specific and application-wide variables into the template context. These variables include user identity, role flags, product metadata, and resource counts (such as chatbots, plugins, API keys, custom domains, connections, and secrets). The context is used to render the dashboard layout and personalize the user experience.
The resource counts are cached for performance, and the context is dynamically constructed based on the authenticated user’s account and profile.
- Parameters:
request (
HttpRequest) – The HTTP request object.- Returns:
A dictionary containing the dashboard context variables.
- Return type:
- smarter.apps.dashboard.context_processors.branding(request)[source]
Provides organization-specific branding context for dashboard templates.
This context processor injects a comprehensive set of branding and support variables into the template context for all pages inheriting from
base.html. These variables ensure that consistent corporate identity, contact, and support information are available throughout the dashboard user interface.The context includes:
The root URL of the application, suitable for constructing absolute links.
Support contact details, such as phone number and email address, for user assistance.
Corporate name and physical address, for legal and informational display.
General contact information and published support hours.
A copyright notice, dynamically including the current year and corporate name.
Social media profile URLs (Facebook, Twitter, LinkedIn) for brand presence and outreach.
All values are sourced from Django settings, allowing for easy customization and environment-specific overrides.
Example usage in a Django template:
{{ branding.corporate_name }} {{ branding.support_email }} {{ branding.copyright }}
This processor is intended to be added to the
TEMPLATES['OPTIONS']['context_processors']list in your Django settings, making thebrandingcontext variable available in all templates rendered by Django that inherit frombase.html.
- smarter.apps.dashboard.context_processors.cache_buster(request)[source]
Adds a cache-busting query parameter to static asset URLs during development.
This context processor is intended for use in local development environments to ensure that browsers do not serve outdated versions of static files (such as JavaScript, CSS, or images) from cache. It injects a
cache_bustervariable into the template context, which can be appended as a query parameter to static asset URLs. The value is a version string based on the current timestamp, guaranteeing uniqueness on each page load.Example usage in a Django template:
<script src="{{ STATIC_URL }}main.js?{{ cache_buster }}"></script>
This approach is especially useful when making frequent changes to static assets during development, as it forces the browser to fetch the latest version every time the page is reloaded. In production, this processor is typically disabled or omitted to allow for proper static file caching and performance optimization.
The
cache_bustervariable is a string in the formatv=<timestamp>.
- smarter.apps.dashboard.context_processors.cache_invalidations(user_profile)[source]
Invalidates caches for all resource-counting context processors. This function is intended to be called after any operation that modifies the underlying user data.
Note
This is called by signal handlers in the account app, tied to the AbstractBroker.
See also
smarter.apps.account.signals.cache_invalidate
- Return type:
Provides organization-specific legal context for dashboard templates.
This context processor injects legal and compliance-related variables into the template context for all pages inheriting from
base.html. These variables ensure that consistent legal information, such as terms of service, privacy policy, and cookie policy URLs, are available throughout the dashboard user interface.The context includes:
URLs for the terms of service, privacy policy, and cookie policy documents.
A dynamically generated copyright notice that includes the current year and corporate name.
All values are sourced from Django settings, allowing for easy customization and environment-specific overrides.
Example usage in a Django template:
{{ footer.legal_url }} {{ footer.plans_url }} {{ footer.contact_url }}
- smarter.apps.dashboard.context_processors.is_sphinx_build()[source]
Determine if the current execution context is a Sphinx documentation build.
- smarter.apps.dashboard.context_processors.sidebar(request)[source]
Resolve and cache the href targets for every dashboard sidebar navigation link.
The inner result is cached so that URL reversals are only performed once per process lifetime (the URLs are static). The resolved URLs are returned under a
sidebarkey whose sub-keys correspond to each navigation destination:dashboard,workbench,apply_manifest,prompt_passthrough,server_logs,providers,plugins,connections,secrets,vectorstores,api_keys,custom_domains,example_manifests,swagger_docs,redoc,json_schemas,account,admin.- Parameters:
request (
HttpRequest) – The incoming HTTP request (not used directly; required by the Django context-processor protocol).- Returns:
A dict with a single
"sidebar"key mapping destination names to their resolved URL strings.- Return type: