djblets.util.views¶
Various utility views.
- cached_javascript_catalog(request: HttpRequest, domain: str = 'djangojs', packages: Sequence[str] = []) HttpResponse[source]¶
A cached version of javascript_catalog.
- Parameters:
request (
django.http.HttpRequest) – The HTTP request.domain (
str) – The translation domain to use when looking up strings.packages (
listofstr) – The package names to get strings from.
- Returns:
The response to send back to the client.
- Return type:
- class HealthCheckStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
-
A status indicator for health checks.
New in version 4.0.
- __str__() str[source]¶
Return a string representation of the status.
This exists so we can compare a string against an enum. Once we move to StrEnum this can be removed.
- Returns:
The string status.
- Return type:
- __format__(format_spec)¶
Return a formatted version of the string as described by format_spec.
- __new__(value)¶
- __repr__()¶
Return repr(self).
- class HealthCheckResult[source]¶
Bases:
TypedDictResult structure for health checks.
New in version 4.0.
- checks: dict[str, djblets.util.views.HealthCheckStatus]¶
The individual checks that were run.
- status: HealthCheckStatus¶
The overall health status of the server.
- __annotations__ = {'checks': ForwardRef('dict[str, HealthCheckStatus]', module='djblets.util.views'), 'errors': ForwardRef('dict[str, str]', module='djblets.util.views'), 'status': ForwardRef('HealthCheckStatus', module='djblets.util.views')}¶
- __closed__ = None¶
- __extra_items__ = typing_extensions.NoExtraItems¶
- __mutable_keys__ = frozenset({'checks', 'errors', 'status'})¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (typing_extensions.TypedDict,)¶
- __readonly_keys__ = frozenset({})¶
- __required_keys__ = frozenset({'checks', 'errors', 'status'})¶
- __total__ = True¶
- class HealthCheckView(*args, **kwargs)[source]¶
Bases:
ViewA view for health checks.
This will check the status of connected database and cache servers, and report whether everything can be accessed. It will return either HTTP 200 or 503, and the payload will be a JSON blob defined by
HealthCheckResult.This will only allow requests from whitelisted IP addresses. These are set in a Django setting named
DJBLETS_HEALTHCHECK_IPS, which should be a list of strings.Changed in version 6.0: Changed to allow CIDR subnets in the
DJBLETS_HEALTHCHECK_IPSsetting.New in version 4.0.
- get(request: HttpRequest, *args, **kwargs) HttpResponse[source]¶
Perform a health check.
This will do a health check on whether the database and cache server can be used. If both are accessible, this will return an HTTP 200. If not, this will return HTTP 500.
Changed in version 6.0: Changed IP matching to use networks instead of single IP addresses.
- Parameters:
request (
django.http.HttpRequest) – The HTTP request.*args (
tuple, unused) – Positional arguments, for future expansion.**kwargs (
dict, unused) – Keyword arguments, for future expansion.
- Returns:
The response to send back to the client.
- Return type:
- __annotations__ = {'_cache_key': 'str'}¶