2018-11-16 12:08:37 +00:00
|
|
|
"""passbook administration overview"""
|
2019-04-29 18:37:44 +00:00
|
|
|
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
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
from passbook.admin.mixins import AdminRequiredMixin
|
2019-02-25 16:52:51 +00:00
|
|
|
from passbook.core import __version__
|
|
|
|
from passbook.core.celery import CELERY_APP
|
2019-02-21 15:06:57 +00:00
|
|
|
from passbook.core.models import (Application, Factor, Invitation, Policy,
|
|
|
|
Provider, Source, User)
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
class AdministrationOverviewView(AdminRequiredMixin, TemplateView):
|
2018-11-16 12:08:37 +00:00
|
|
|
"""Overview View"""
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
template_name = 'administration/overview.html'
|
|
|
|
|
2019-04-29 18:37:44 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
if 'clear' in self.request.POST:
|
|
|
|
cache.clear()
|
|
|
|
return redirect(reverse('passbook_core:auth-login'))
|
|
|
|
return self.get(*args, **kwargs)
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
kwargs['application_count'] = len(Application.objects.all())
|
2019-02-16 09:24:31 +00:00
|
|
|
kwargs['policy_count'] = len(Policy.objects.all())
|
2018-11-11 12:41:48 +00:00
|
|
|
kwargs['user_count'] = len(User.objects.all())
|
2018-11-16 10:40:24 +00:00
|
|
|
kwargs['provider_count'] = len(Provider.objects.all())
|
2019-02-21 15:06:57 +00:00
|
|
|
kwargs['source_count'] = len(Source.objects.all())
|
|
|
|
kwargs['factor_count'] = len(Factor.objects.all())
|
|
|
|
kwargs['invitation_count'] = len(Invitation.objects.all())
|
2019-02-25 16:52:51 +00:00
|
|
|
kwargs['version'] = __version__
|
|
|
|
kwargs['worker_count'] = len(CELERY_APP.control.ping(timeout=0.5))
|
2019-02-27 14:45:42 +00:00
|
|
|
kwargs['providers_without_application'] = Provider.objects.filter(application=None)
|
2019-03-03 16:12:35 +00:00
|
|
|
kwargs['policies_without_attachment'] = len(Policy.objects.filter(policymodel__isnull=True))
|
2019-04-29 18:37:44 +00:00
|
|
|
kwargs['cached_policies'] = len(cache.keys('policy_*'))
|
|
|
|
print(cache.keys('*'))
|
2018-11-11 12:41:48 +00:00
|
|
|
return super().get_context_data(**kwargs)
|