API
smarter.apps.dashboard.views.dashboard.api.my_resources
This module provides custom Django context processors for the Smarter dashboard
application. These context processors are designed to inject additional context
variables into templates that inherit from base.html, supporting the dynamic
rendering of dashboard and branding information throughout the application.
Overview
The context processors in this module serve the following purposes:
- Dashboard Context: Supplies user-specific and application-wide metadata,
such as the current user’s email, username, role flags, product version, and resource counts (e.g., chatbots, plugins, API keys, custom domains, connections, and secrets). This enables the dashboard to display personalized and up-to-date information for each authenticated user.
- Branding Context: Provides organization-specific branding details, including
support contact information, corporate name, address, social media links, and copyright notices. This ensures consistent branding and support information across all dashboard templates.
- Cache Busting: Adds a cache-busting query parameter to static asset URLs
during local development, preventing browsers from serving outdated static files.
Caching
Many of the resource-counting functions in this module are decorated with a caching mechanism to reduce database load and improve performance. The cache timeout is configurable and set to 60 seconds by default.
cache_invalidations(user_profile) is a utility function provided to invalidate all relevant caches when user data changes, ensuring that the dashboard reflects the most current information.
Usage
To use these context processors, add their import paths to the
TEMPLATES['OPTIONS']['context_processors'] list in your Django settings.
This will make the provided context variables available in all templates
rendered by Django that inherit from base.html.
Note
This module does not document individual function signatures or arguments, as
these are automatically included by Sphinx’s automodule directive. For
detailed API documentation, refer to the generated documentation for each function.
- class smarter.apps.dashboard.views.views.api.my_resources.MyResourcesView(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedWebViewAPI view for the “My Resources” React component on the dashboard.
- post(request, *args, **kwargs)[source]
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_api_keys(invalidate=False, user_profile=None)[source]
Returns the total number of API keys associated with the specified user.
This function queries the database for all API key records linked to chatbots owned by the user’s account. The resulting count is used to display the user’s available API keys on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose API keys are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of API keys belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_chatbots(invalidate=False, user_profile=None)[source]
Returns the total number of chatbots associated with the specified user.
This function queries the database for all chatbot instances linked to the user’s account, regardless of deployment status. The resulting count is used to display the user’s available chatbots on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose chatbots are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of chatbots belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_connections(invalidate=False, user_profile=None)[source]
Returns the total number of API and SQL connections associated with the specified user.
This function queries the database for all API and SQL connection records linked to the user’s account. The resulting count is used to display the user’s available connections on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose connections are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of API and SQL connections belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_custom_domains(invalidate=False, user_profile=None)[source]
Returns the total number of custom domains associated with the specified user.
This function queries the database for all custom domain records linked to chatbots owned by the user’s account. The resulting count is used to display the user’s available custom domains on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose custom domains are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of custom domains belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_pending_deployments(invalidate=False, user_profile=None)[source]
Returns the number of chatbot deployments that are pending for the specified user.
This function queries the database for all chatbot instances associated with the user’s account that have not yet been deployed. The result is used to inform users of outstanding deployment actions required on their dashboard.
The result is cached for a short duration to minimize database load and improve dashboard responsiveness.
- Parameters:
invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose pending deployments are to be counted.
- Returns:
The number of pending chatbot deployments for the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_plugins(invalidate=False, user_profile=None)[source]
Returns the total number of plugins associated with the specified user.
This function queries the database for all plugin metadata records linked to the user’s account. The resulting count is used to display the user’s available plugins on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – UserProfile instance. The user profile whose plugins are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of plugins belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_providers(invalidate=False, user_profile=None)[source]
Returns the total number of providers associated with the specified user’s account.
This function queries the database for all provider records linked to the user’s account. The resulting count is used to display the user’s available providers on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – The user profile whose providers are to be counted.- Returns:
The number of providers belonging to the user account + those belonging to the official smarter admin.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_secrets(invalidate=False, user_profile=None)[source]
Returns the total number of secrets associated with the specified user’s profile.
This function queries the database for all secret records linked to the user’s profile. The resulting count is used to display the user’s available secrets on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
Optional[UserProfile]) – The user profile whose secrets are to be counted.- Returns:
The number of secrets belonging to the user profile.
- Return type:
API view for the Dashboard “Service Health” React component.
This module provides a lightweight JSON endpoint consumed by the Service Health React widget on the main dashboard page. It returns version and environment metadata for the running Smarter platform so that operators can quickly verify which versions of core dependencies are active.
- Classes:
- ServiceHealthView: Authenticated POST endpoint that returns platform
version and environment metadata as a JSON response.
Example
Wire up the view in your URL configuration:
from smarter.apps.dashboard.views.views.api.service_health import ServiceHealthView
urlpatterns = [
path("service-health/", ServiceHealthView.as_view(), name="service_health"),
]
- class smarter.apps.dashboard.views.views.api.service_health.ServiceHealthView(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedWebViewAuthenticated JSON API view that reports platform version and environment metadata.
Extends
SmarterAuthenticatedWebViewto restrict access to authenticated users.On a
POSTrequest the view reads version strings and environment information fromsmarter_settingsand returns them as a flat JSON object with an HTTP 200 status.Response shape:
{ "smarter_version": "1.2.3", "linux_distribution": "Ubuntu 22.04", "django_version": "4.2.0", "python_version": "3.11.0", "pydantic_version": "2.0.0", "drf_version": "3.14.0" }
- post(request, *args, **kwargs)[source]
Handle POST requests to return platform health metadata. :param request: The incoming HTTP POST request from the client. :type request:
HttpRequest:type args: :param args: Additional positional arguments forwarded by the URL dispatcher. :type kwargs: :param kwargs: Additional keyword arguments forwarded by the URL dispatcher. :returns: A JSON response containing platform version and environment metadata.- Return type: