diff --git a/forecasts/models.py b/forecasts/models.py index f4caccde241c03fb798bd630b7b67560508fd5cb..a6a55e54b806303a9b84dca2281f946440b10df1 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 8c32ca0bf461ac7c9c0c6cd31396f837218b5ab5..789d4a5a4e4c74643df82771f65699565dc6c839 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 66a1d7ef7968a9073eabf35e8240540d49615522..400eff6c7e8b0d68fa164bedf149c14a3e62fbee 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)