From 719364f721b707268d3bf15cd7cf0cc1c6e84ac1 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Wed, 15 Nov 2017 16:13:07 +0100 Subject: [PATCH] Supporting season select for forecasts list --- forecasts/models.py | 8 +++++--- forecasts/templates/forecasts/index.html | 8 ++++++++ forecasts/views.py | 13 ++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/forecasts/models.py b/forecasts/models.py index f4caccde..a6a55e54 100755 --- a/forecasts/models.py +++ b/forecasts/models.py @@ -223,16 +223,18 @@ class ForecastConfiguration: # Returns a result object @staticmethod - def get_forecast_configurations_from_vipslogic(crop_organism_ids): + def get_forecast_configurations_from_vipslogic(crop_organism_ids, season): crop_organism_id_paramstring = "" if crop_organism_ids != None: for crop_organism_id in crop_organism_ids: crop_organism_id_paramstring += "&cropOrganismId=%s" % crop_organism_id - - request_result = requests.get("%s://%s/rest/organizationforecastconfigurations/%s?%s" % ( + + request_result = requests.get("%s://%s/rest/organizationforecastconfigurations/%s?from=%s-01-01&to=%s-12-31%s" % ( settings.VIPSLOGIC_PROTOCOL, settings.VIPSLOGIC_SERVER_NAME, settings.VIPS_ORGANIZATION_ID, + season, + season, crop_organism_id_paramstring ) ) diff --git a/forecasts/templates/forecasts/index.html b/forecasts/templates/forecasts/index.html index 8c32ca0b..789d4a5a 100755 --- a/forecasts/templates/forecasts/index.html +++ b/forecasts/templates/forecasts/index.html @@ -44,6 +44,14 @@ <th> <input id="weatherStationName" class="form-control" type="text" placeholder="{% trans "Search" %}" oninput="filterForecastConfigurations();"/> </th> + <th></th> + <th colspan="2"> + <select id="season" class="form-control" onchange="window.location.href='/forecasts?season=' + this.options[this.options.selectedIndex].value;"> + {% for season_option_value in season_range %} + <option value="{{season_option_value}}" {% if season_option_value == season %}selected="selected"{% endif %}>{{season_option_value}}</option> + {% endfor %} + </select> + </th> </tr> </thead> <thead> diff --git a/forecasts/views.py b/forecasts/views.py index 66a1d7ef..400eff6c 100755 --- a/forecasts/views.py +++ b/forecasts/views.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2014 NIBIO <http://www.nibio.no/>. +# Copyright (c) 2017 NIBIO <http://www.nibio.no/>. # # This file is part of VIPSWeb. # VIPSWeb is free software: you can redistribute it and/or modify @@ -17,6 +17,8 @@ # # @author: Tor-Einar Skog <tor-einar.skog@nibio.no> +from datetime import datetime +from dateutil.relativedelta import relativedelta from django.http import HttpResponse from django.shortcuts import render @@ -26,7 +28,10 @@ from django.utils import translation from forecasts.models import ForecastConfiguration, ForecastResult, ResultParameter, ResultParameterLocal, Model, MeasurementUnit, ModelGraphParameter def index(request): - forecast_configurations = ForecastConfiguration.get_forecast_configurations_from_vipslogic(None).text + + season_range = range(2016, datetime.now().year + 1) + season = int(request.GET.get("season", (datetime.now() + relativedelta(months = settings.SYSTEM_TIME_OFFSET_MONTHS)).year)) + forecast_configurations = ForecastConfiguration.get_forecast_configurations_from_vipslogic(None, season).text private_forecast_configurations = None if request.session.get("user_uuid",None) != None: private_forecast_configurations = ForecastConfiguration.get_private_forecast_configurations(request.session["user_uuid"]) @@ -34,7 +39,9 @@ def index(request): context = { 'forecast_configurations': forecast_configurations, 'private_forecast_configurations': private_forecast_configurations, - 'models_local_names' : Model.get_models_local_names().text + 'models_local_names' : Model.get_models_local_names().text, + 'season': season, + 'season_range': season_range } return render(request, 'forecasts/index.html', context) -- GitLab