home.views

Contains views that handle HTTP requests and return appropriate responses for the application.

Attributes

Classes

IndexView

Redirects authenticated users to the dashboard page.

DashboardView

Renders the dashboard page for authenticated users. Uses the 'home/dashboard.html' template.

NotificationDetailsView

Renders the notification details page for authenticated users.

NotificationMarkSolvedView

Mark notification as solved when viewed in the notification details page.

AddDomainsAndDevicesView

View to execute the add_domains_and_devices management command and pass status to the template.

DashboardChartsAndCountsView

View to mark the notification as Solved.

Module Contents

home.views.SUCCESS = 25[source]
home.views.ERROR = 40[source]
class home.views.IndexView(**kwargs)[source]

Bases: django.views.generic.base.RedirectView

Redirects authenticated users to the dashboard page.

permanent = False[source]
pattern_name = 'home:dashboard'[source]
class home.views.DashboardView(*args, **kwargs)[source]

Bases: trustpoint.views.base.SortableTableMixin[notifications.models.NotificationModel], django.views.generic.list.ListView[notifications.models.NotificationModel]

Renders the dashboard page for authenticated users. Uses the ‘home/dashboard.html’ template.

Parameters:
  • args (Any)

  • kwargs (Any)

template_name = 'home/dashboard.html'[source]
model[source]
context_object_name = 'notifications'[source]
default_sort_param = '-created_at'[source]
paginate_by = 5[source]
last_week_dates[source]
static generate_last_week_dates()[source]

Generates date strings for last one week.

Returns:

A list of date strings from last one week.

Return type:

list[str]

get_queryset()[source]

Returns a queryset of NotificationModel instances.

Returns:

A QuerySet containing filtered notifications.

Return type:

Any

get_context_data(**kwargs)[source]

Fetch context data.

Parameters:

**kwargs (Any) – Keyword arguments passed to super().get_context_data.

Returns:

The context to render the page.

Return type:

dict[str, Any]

static _render_created_at(record)[source]

Render the created_at field with a badge if the status is ‘New’.

Parameters:

record (notifications.models.NotificationModel) – The corresponding NotificationModel.

Returns:

The HTML of the created at display span.

Return type:

django.utils.safestring.SafeString

static _render_notification_type(record)[source]

Render the notification type with a badge according to the type.

Parameters:

record (notifications.models.NotificationModel) – The corresponding NotificationModel.

Returns:

The HTML of the span with class badge to display notification type.

Return type:

django.utils.safestring.SafeString

class home.views.NotificationDetailsView[source]

Bases: django.views.generic.detail.DetailView[notifications.models.NotificationModel]

Renders the notification details page for authenticated users.

template_name = 'home/notification_details.html'[source]
model[source]
context_object_name = 'notification'[source]
get_context_data(**kwargs)[source]

Adds information about the statuses of the Notification.

Parameters:

**kwargs (Any) – Keyword arguments passed to super().get_context_data.

Returns:

The context to render the page.

Return type:

dict[str, Any]

class home.views.NotificationMarkSolvedView[source]

Bases: django.views.generic.detail.DetailView[notifications.models.NotificationModel]

Mark notification as solved when viewed in the notification details page.

template_name = 'home/notification_details.html'[source]
model[source]
context_object_name = 'notification'[source]
get_context_data(**kwargs)[source]

Adds information about the solved status of the notification.

Parameters:

**kwargs (Any) – Keyword arguments passed to super().get_context_data.

Returns:

The context to render the page.

Return type:

dict[str, Any]

class home.views.AddDomainsAndDevicesView(**kwargs)[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.base.TemplateView

View to execute the add_domains_and_devices management command and pass status to the template.

get(request, *args, **kwargs)[source]

Handles GET requests and redirects to the dashboard.

Parameters:
  • request (django.http.HttpRequest) – The HTTP request object.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Keyword arguments passed to super().get_context_data.

Returns:

dashboard.

Return type:

The response that redirects the user to home

class home.views.DashboardChartsAndCountsView(**kwargs)[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.base.TemplateView

View to mark the notification as Solved.

get(request, *args, **kwargs)[source]

Get dashboard data for panels, tables and charts.

Parameters:
  • request (django.http.HttpRequest) – The HTTP request object.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Keyword arguments passed to super().get_context_data.

Returns:

The JSON response containing dashboard data.

Return type:

django.http.JsonResponse

get_device_charts_data(dashboard_data, start_date)[source]

Fetch data from database for device charts and add to dashboard data object.

Parameters:
  • dashboard_data (dict[str, Any]) – The dashboard data object.

  • start_date (datetime.datetime) – The start date for fetching device data.

Returns:

It returns nothing. It adds the device related data in dashboard_data object.

Return type:

None

get_cert_charts_data(dashboard_data, start_date)[source]

Fetch data from database for certificate charts and add to dashboard data object.

Parameters:
  • dashboard_data (dict[str, Any]) – The dashboard data object.

  • start_date (datetime.datetime) – The start date for fetching certificate data.

Returns:

It returns nothing. It adds the certificate related data in dashboard_data object.

Return type:

None

get_ca_charts_data(dashboard_data, start_date)[source]

Fetch data from database for issuing ca charts and add to dashboard data object.

Parameters:
  • dashboard_data (dict[str, Any]) – The dashboard data object.

  • start_date (datetime.datetime) – The start date for fetching issuing ca data.

Returns:

It returns nothing. It adds the issuing ca related data in dashboard_data object.

Return type:

None

get_device_count_by_onboarding_status(start_date)[source]

Fetch device count by onboarding status from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns device counts grouped by device onboarding status.

Return type:

dict[str, Any]

get_cert_counts()[source]

Fetch certificate count from database.

Returns:

It returns certificate counts.

Return type:

dict[str, Any]

get_cert_counts_by_status_and_date()[source]

Fetch certificate counts grouped by issue date and certificate status from database.

Returns:

It returns certificate counts grouped by issue date and certificate status.

Return type:

list[dict[str, Any]]

get_cert_counts_by_status(start_date)[source]

Fetch certs count by onboarding status from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns device counts grouped by device onboarding status.

Return type:

dict[str, Any]

get_issuing_ca_counts()[source]

Fetch issuing CA count from database.

Returns:

It returns total, active and expired issuing CA counts.

Return type:

dict[str, Any]

get_device_counts_by_date_and_status()[source]

Fetch device count by date and onboarding status from database.

Returns:

It returns device count grouped by date and onboarding status.

Return type:

list[dict[str, Any]]

get_device_count_by_onboarding_protocol(start_date)[source]

Fetch device count by onboarding protocol from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns device count by onboarding protocol.

Return type:

dict[str, Any]

get_device_count_by_domain(start_date)[source]

Fetch onboarded devices count grouped by domain from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns onboarded devices count grouped by domain.

Return type:

list[dict[str, Any]]

get_cert_counts_by_issuing_ca(start_date)[source]

Fetch certificate count grouped by issuing ca from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns certificate count grouped by issuing ca.

Return type:

list[dict[str, Any]]

get_cert_counts_by_issuing_ca_and_date(start_date)[source]

Fetch certificate count grouped by issuing ca and date from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns certificate count grouped by issuing ca and date.

Return type:

list[dict[str, Any]]

get_cert_counts_by_domain(start_date)[source]

Fetch certificate count grouped by domain from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns certificate count grouped by domain.

Return type:

list[dict[str, Any]]

get_cert_counts_by_profile(start_date)[source]

Fetch certificate count grouped by profile from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

Dict of certificate count for each certificate profile.

Return type:

dict[str, Any]

get_issuing_ca_counts_by_type(start_date)[source]

Fetch issuing ca counts grouped by type from database.

Parameters:

start_date (datetime.datetime) – The start date for fetching data.

Returns:

It returns issuing ca counts grouped by type.

Return type:

dict[str, Any]

get_expiring_device_counts()[source]

Fetch expiring device counts from database.

Returns:

It returns counts of devices with expiring certificates.

Return type:

dict[str, Any]

get_expired_device_counts()[source]

Fetch expired device counts from database.

Returns:

It returns counts of devices with expired certificates.

Return type:

dict[str, Any]

get_expiring_issuing_ca_counts()[source]

Fetch expiring issuing CA counts from database.

Returns:

It returns counts of issuing CAs with expiring certificates.

Return type:

dict[str, Any]