diff --git a/spatial/templates/spatial/index.html b/spatial/templates/spatial/index.html index 0919a042eae2cd80474e29aeffef2b95da4a7a2b..28b0ff43cec1492fb3d3ddb35a815b00d5541d91 100644 --- a/spatial/templates/spatial/index.html +++ b/spatial/templates/spatial/index.html @@ -28,14 +28,19 @@ <h2>VIPS grid map</h2> <p> View results from VIPS models run on gridded weather data. + {% if available_grid_models|length > 0 %} <ul> - {% for model in available_grid_models %} + {% for model in available_grid_models %} <li><a href="gridmap/{{model.model_id}}">{{ model.model_name }}</a></li> - {% endfor %} + {% endfor %} </ul> + {% else %} + <p><em>No GRID models available</em></p> + {% endif %} </p> <h2>Other resources</h2> <ul> <li><a href="test/PSILARTEMP">Carrot rust fly map [TEST]</a></li> </ul> {% endblock %} + diff --git a/spatial/views.py b/spatial/views.py index 5bfd2d33abc77a708d1cf8e87f239961721940ea..ef0a2deca2d4491c4c0111a23021c8ba2e55aec1 100644 --- a/spatial/views.py +++ b/spatial/views.py @@ -4,7 +4,9 @@ from django.conf import settings def index(request): - context = {"available_grid_models": settings.AVAILABLE_GRID_MODELS} + context = { + "available_grid_models": settings.AVAILABLE_GRID_MODELS if hasattr(settings, "AVAILABLE_GRID_MODELS") else [] + } return render(request, 'spatial/index.html', context) def psilartemp(request): @@ -12,9 +14,12 @@ def psilartemp(request): return render(request, 'spatial/psilartemp.html', context) def gridmap(request, model_id): - for model in settings.AVAILABLE_GRID_MODELS: - if model_id == model["model_id"]: - context = {"model_id": model_id} - return render(request, 'spatial/gridmap.html', context) + try: + for model in settings.AVAILABLE_GRID_MODELS: + if model_id == model["model_id"]: + context = {"model_id": model_id} + return render(request, 'spatial/gridmap.html', context) + except AttributeError: + pass return index(request)