api_views: factorize code for stat decorator (#49670)
This commit is contained in:
parent
2f42606265
commit
c27792ecbe
|
@ -1135,6 +1135,7 @@ class StatisticsSerializer(serializers.Serializer):
|
|||
def stat(**kwargs):
|
||||
'''Extend action decorator to allow passing statistics related info.'''
|
||||
filters = kwargs.pop('filters', [])
|
||||
kwargs['detail'] = False
|
||||
decorator = action(**kwargs)
|
||||
|
||||
def wraps(func):
|
||||
|
@ -1219,27 +1220,27 @@ class StatisticsAPI(ViewSet):
|
|||
'err': 0,
|
||||
})
|
||||
|
||||
@stat(detail=False, name=_('Login count by authentication type'), filters=('ou', 'service'))
|
||||
@stat(name=_('Login count by authentication type'), filters=('ou', 'service'))
|
||||
def login(self, request):
|
||||
return self.get_statistics(request, UserLogin, 'get_method_statistics')
|
||||
|
||||
@stat(detail=False, name=_('Login count by service'))
|
||||
@stat(name=_('Login count by service'))
|
||||
def service_login(self, request):
|
||||
return self.get_statistics(request, UserLogin, 'get_service_statistics')
|
||||
|
||||
@stat(detail=False, name=_('Login count by organizational unit'))
|
||||
@stat(name=_('Login count by organizational unit'))
|
||||
def service_ou_login(self, request):
|
||||
return self.get_statistics(request, UserLogin, 'get_service_ou_statistics')
|
||||
|
||||
@stat(detail=False, name=_('Registration count by type'), filters=('ou', 'service'))
|
||||
@stat(name=_('Registration count by type'), filters=('ou', 'service'))
|
||||
def registration(self, request):
|
||||
return self.get_statistics(request, UserRegistration, 'get_method_statistics')
|
||||
|
||||
@stat(detail=False, name=_('Registration count by service'))
|
||||
@stat(name=_('Registration count by service'))
|
||||
def service_registration(self, request):
|
||||
return self.get_statistics(request, UserRegistration, 'get_service_statistics')
|
||||
|
||||
@stat(detail=False, name=_('Registration count by organizational unit'))
|
||||
@stat(name=_('Registration count by organizational unit'))
|
||||
def service_ou_registration(self, request):
|
||||
return self.get_statistics(request, UserRegistration, 'get_service_ou_statistics')
|
||||
|
||||
|
|
Loading…
Reference in New Issue