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., llmclients, plugins, API keys, custom domains, MCPClients, secrets, guardrails, vectorstores, LLMHosts and extensions). 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(**kwargs)[source]
Bases:
SmarterAuthenticatedWebViewAPI view for the “My Resources” React component on the dashboard.
- property formatted_class_name: str
Returns the class name in a formatted string along with the name of this view.
- post(request, *args, **kwargs)[source]
Return the counts and list urls of the user’s resources, from the cache.
- Parameters:
request (
HttpRequest) – The request.- Return type:
- Returns:
The resources, as JSON.
- 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 llmclients 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 (
UserProfile|None) – 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_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 llmclients 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 (
UserProfile|None) – 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_extensions(invalidate=False, user_profile=None)[source]
Returns the number of enabled extensions that the specified user’s account may use.
An extension is available to an account when it is available to every account, or to that account in particular. See
smarter.apps.llmtool.models.Extension.is_available_to().The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – The user profile whose account’s extensions are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of enabled extensions available to the user’s account.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_guardrails(invalidate=False, user_profile=None)[source]
Returns the total number of guardrails associated with the specified user’s profile.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – The user profile whose guardrails are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of guardrails belonging to the user profile.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_llmclients(invalidate=False, user_profile=None)[source]
Returns the total number of llmclients associated with the specified user.
This function queries the database for all llmclient instances linked to the user’s account, regardless of deployment status. The resulting count is used to display the user’s available llmclients on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – UserProfile instance. The user profile whose llmclients are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of llmclients belonging to the user.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_llmhosts(invalidate=False, user_profile=None)[source]
Returns the total number of LLMHosts associated with the specified user’s profile.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – The user profile whose LLMHosts are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of LLMHosts belonging to the user profile.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_mcpclients(invalidate=False, user_profile=None)[source]
Returns the total number of MCPClients available to the specified user.
This function counts the MCPClients that the user owns, and those shared with them. The resulting count is used to display the user’s available MCPClients on the dashboard.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – UserProfile instance. The user profile whose MCPClients are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of MCPClients available 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 llmclient deployments that are pending for the specified user.
This function queries the database for all llmclient 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 (
UserProfile|None) – UserProfile instance. The user profile whose pending deployments are to be counted.
- Returns:
The number of pending llmclient 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 (
UserProfile|None) – 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 (
UserProfile|None) – 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 (
UserProfile|None) – The user profile whose secrets are to be counted.- Returns:
The number of secrets belonging to the user profile.
- Return type:
- smarter.apps.dashboard.views.views.api.my_resources.get_vectorstores(invalidate=False, user_profile=None)[source]
Returns the total number of vectorstores associated with the specified user’s profile.
The result is cached for a short duration to reduce database queries and improve dashboard performance.
- Parameters:
user_profile (
UserProfile|None) – The user profile whose vectorstores are to be counted.invalidate (
bool) – Boolean, optional. If True, invalidates the cache before fetching.
- Returns:
The number of vectorstores 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, along with the results of live checks of the backing services: the database, the cache, the Celery task broker, and the Celery workers.
- 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"),
]
- smarter.apps.dashboard.views.views.api.service_health.CHECK_DID_NOT_PASS = 'the check ran, and did not pass'
The error of a check that returned False rather than raising, e.g. no Celery worker answered its ping.
- class smarter.apps.dashboard.views.views.api.service_health.ServiceHealthView(**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, and the url of the platform’s source code repository, fromsmarter_settings, runs the liveHEALTH_CHECKS, at most once a minute (seecurrent_health_checks()), and returns them as a JSON object with an HTTP 200 status. A body of{"refresh": true}, which the dashboard’s refresh button sends, runs the checks again now.health_scoreis the percentage of checks that passed.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", "repository_url": "https://github.com/smarter-sh/smarter", "health_checks": [ {"name": "Database", "healthy": true}, {"name": "Cache", "healthy": true}, {"name": "Task Broker", "healthy": true}, {"name": "Workers", "healthy": false} ], "health_score": 75 }
- property formatted_class_name: str
Returns the class name in a formatted string along with the name of this view.
- post(request, *args, **kwargs)[source]
Handle POST requests to return platform health metadata.
- Parameters:
request (
HttpRequest) – The incoming HTTP POST request from the client.args – Additional positional arguments forwarded by the URL dispatcher.
kwargs – Additional keyword arguments forwarded by the URL dispatcher.
- Returns:
A JSON response containing platform version and environment metadata, and the results of the health checks.
- Return type:
- smarter.apps.dashboard.views.views.api.service_health.cached_health_checks()[source]
The results of
run_health_checks(), cached forHEALTH_CHECKS_CACHE_TIMEOUTseconds.
- smarter.apps.dashboard.views.views.api.service_health.check_cache()[source]
True if a value written to the cache can be read back.
- Return type:
- smarter.apps.dashboard.views.views.api.service_health.check_database()[source]
True if the database answers a trivial query.
- Return type:
- smarter.apps.dashboard.views.views.api.service_health.check_task_broker()[source]
True if the Celery broker accepts a connection.
- Return type:
- smarter.apps.dashboard.views.views.api.service_health.check_workers()[source]
True if at least one Celery worker answers a ping.
- Return type:
- smarter.apps.dashboard.views.views.api.service_health.current_health_checks()[source]
Return the results of the health checks, from the cache when it has them.
The checks ping the database, the cache and the Celery workers, so every dashboard shares one run of them a minute. If the cache itself is down, reading it raises, and the checks run uncached, so that the Cache check reports the failure instead of the whole widget failing.
- smarter.apps.dashboard.views.views.api.service_health.public_health_checks(checks)[source]
Return the health checks without their errors, for the dashboard’s widget.
An error can name internal hosts and services, which a dashboard user doesn’t need.
- smarter.apps.dashboard.views.views.api.service_health.run_health_checks()[source]
Run each health check, and report a failure, or an exception, as unhealthy, with why.
Each result has the check’s
name, whether it ishealthy, and itserror: an empty string for a healthy check, the exception’s class and message for one that raised, e.g.TimeoutError: Timeout connecting to server, orCHECK_DID_NOT_PASS. The error is for staff, e.g. Smarter Sysadmin’splatform_status:ServiceHealthViewleaves it out.
- smarter.apps.dashboard.views.views.api.service_health.wants_refresh(request)[source]
True if the request asks for the checks to run again now, with
{"refresh": true}as its body.The dashboard’s refresh button sends it. A missing or malformed body is not a refresh.
- Parameters:
request (
HttpRequest) – The incoming HTTP POST request.- Returns:
Whether the body’s
refreshis true.- Return type:
API view for the dashboard’s Newest Doodles widget: the newest doodles that the Smarter Doodle.
Artist drew for the sign-in page, in any region.
The doodles are read by smarter.apps.doodle.caching.newest_drawn_doodles(): only approved
ones, up to today, so a doodle that awaits a superuser’s approval, or one of a later day, is never
shown. Every user sees the same doodles. Each links to its artwork, a public url, and to the page
that its caption links to.
NewestDoodlesView: the authenticated POST endpoint, which returns aDrawnDoodlesResponse.
- class smarter.apps.dashboard.views.views.api.doodles.NewestDoodlesView(**kwargs)[source]
Bases:
SmarterAuthenticatedWebViewAPI view for the dashboard’s Newest Doodles widget.
A
POSTreturns the newest doodles that the Smarter Doodle Artist drew, at mostNEWEST_DRAWN_DOODLES, the newest first.- post(request, *args, **kwargs)[source]
Handle POST requests to return the newest drawn doodles.
- Parameters:
request (
HttpRequest) – The incoming HTTP POST request. Its body is ignored.- Returns:
A
DrawnDoodlesResponse.- Return type: