add functions listing services into a utils module (and use it)
This commit is contained in:
parent
7cfae74b66
commit
e1418d06b6
|
@ -0,0 +1,9 @@
|
|||
def get_installed_services():
|
||||
from .models import AVAILABLE_SERVICES
|
||||
installed_services = []
|
||||
for available_service in AVAILABLE_SERVICES:
|
||||
installed_services.extend(available_service.objects.all())
|
||||
return installed_services
|
||||
|
||||
def get_operational_services():
|
||||
return [x for x in get_installed_services() if x.is_operational()]
|
|
@ -9,6 +9,7 @@ from django.views.generic.edit import CreateView
|
|||
|
||||
from .models import IdentityProvider, WebForms, AVAILABLE_SERVICES
|
||||
from .forms import IdentityProviderForm, WebFormsForm
|
||||
from . import utils
|
||||
|
||||
|
||||
class AvailableService(object):
|
||||
|
@ -25,10 +26,7 @@ class HomeView(TemplateView):
|
|||
context['url_template'] = settings.SERVICE_URL_TEMPLATE
|
||||
context['available_services'] = [
|
||||
AvailableService(x) for x in AVAILABLE_SERVICES]
|
||||
installed_services = []
|
||||
for available_service in AVAILABLE_SERVICES:
|
||||
installed_services.extend(available_service.objects.all())
|
||||
context['installed_services'] = installed_services
|
||||
context['installed_services'] = utils.get_installed_services()
|
||||
return context
|
||||
|
||||
|
||||
|
@ -72,19 +70,12 @@ def operational_check_view(request, service, slug, **kwargs):
|
|||
|
||||
|
||||
def installed_services_json_view(request, **kwargs):
|
||||
installed_services = []
|
||||
for available_service in AVAILABLE_SERVICES:
|
||||
installed_services.extend(available_service.objects.all())
|
||||
response = HttpResponse(content_type='application/json')
|
||||
json.dump([x.as_dict() for x in installed_services], response)
|
||||
json.dump([x.as_dict() for x in utils.get_installed_services()], response)
|
||||
return response
|
||||
|
||||
|
||||
def operational_services_json_view(request, **kwargs):
|
||||
installed_services = []
|
||||
for available_service in AVAILABLE_SERVICES:
|
||||
installed_services.extend(available_service.objects.all())
|
||||
response = HttpResponse(content_type='application/json')
|
||||
json.dump([x.as_dict() for x in installed_services if x.is_operational()],
|
||||
response)
|
||||
json.dump([x.as_dict() for x in utils.get_operational_services()], response)
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue