This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/admin/views/overview.py

45 lines
1.8 KiB
Python
Raw Normal View History

"""passbook administration overview"""
from django.core.cache import cache
from django.shortcuts import redirect, reverse
2018-11-11 12:41:48 +00:00
from django.views.generic import TemplateView
2019-10-07 14:33:48 +00:00
from passbook import __version__
2018-11-16 08:10:35 +00:00
from passbook.admin.mixins import AdminRequiredMixin
from passbook.core.models import Application, Policy, Provider, Source, User
2020-05-08 17:46:39 +00:00
from passbook.flows.models import Flow, Stage
from passbook.root.celery import CELERY_APP
from passbook.stages.invitation.models import Invitation
2018-11-11 12:41:48 +00:00
2018-11-16 08:10:35 +00:00
class AdministrationOverviewView(AdminRequiredMixin, TemplateView):
"""Overview View"""
2018-11-11 12:41:48 +00:00
2019-12-31 11:51:16 +00:00
template_name = "administration/overview.html"
2018-11-11 12:41:48 +00:00
def post(self, *args, **kwargs):
"""Handle post (clear cache from modal)"""
2019-12-31 11:51:16 +00:00
if "clear" in self.request.POST:
cache.clear()
return redirect(reverse("passbook_flows:default-authentication"))
return self.get(*args, **kwargs)
2018-11-11 12:41:48 +00:00
def get_context_data(self, **kwargs):
2019-12-31 11:51:16 +00:00
kwargs["application_count"] = len(Application.objects.all())
kwargs["policy_count"] = len(Policy.objects.all())
kwargs["user_count"] = len(User.objects.all())
kwargs["provider_count"] = len(Provider.objects.all())
kwargs["source_count"] = len(Source.objects.all())
2020-05-08 17:46:39 +00:00
kwargs["stage_count"] = len(Stage.objects.all())
kwargs["flow_count"] = len(Flow.objects.all())
2019-12-31 11:51:16 +00:00
kwargs["invitation_count"] = len(Invitation.objects.all())
kwargs["version"] = __version__
kwargs["worker_count"] = len(CELERY_APP.control.ping(timeout=0.5))
kwargs["providers_without_application"] = Provider.objects.filter(
application=None
)
kwargs["policies_without_binding"] = len(
2019-12-31 11:51:16 +00:00
Policy.objects.filter(policymodel__isnull=True)
)
kwargs["cached_policies"] = len(cache.keys("policy_*"))
2018-11-11 12:41:48 +00:00
return super().get_context_data(**kwargs)