add functions listing services into a utils module (and use it)

This commit is contained in:
Frédéric Péters 2014-03-25 17:09:30 +01:00
parent 7cfae74b66
commit e1418d06b6
2 changed files with 13 additions and 13 deletions

View File

@ -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()]

View File

@ -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