diff --git a/VIPSWeb/local_settings_sample.py b/VIPSWeb/local_settings_sample.py
index 15ab14e9c83c86b2b1fbb58829012c846421248b..27fbee0cf8a297cc76244734aaa6155f66334bac 100644
--- a/VIPSWeb/local_settings_sample.py
+++ b/VIPSWeb/local_settings_sample.py
@@ -107,4 +107,12 @@ MAP_ZOOMLEVEL = 4
MAP_ATTRIBUTION = "© <a href='http://www.openstreetmap.org'>OpenStreetMap</a> contributors"
# The message tags to use on the front page
-FRONTPAGE_MESSAGE_TAG_IDS = [1,2,3]
\ No newline at end of file
+FRONTPAGE_MESSAGE_TAG_IDS = [1,2,3]
+
+# For setting up groups of crops with forecasts. The crop_ids have to correspond to
+# crops in VIPSLogic
+# Sample:
+# CROP_GROUPS=[
+# {"crop_group_id": 1, "name":{"en":"Fruit", "nb":"Frukt"},"crop_ids":[23,44,53]}
+# ]
+CROP_GROUPS=[]
\ No newline at end of file
diff --git a/VIPSWeb/settings.py b/VIPSWeb/settings.py
index d8fb8dcfd85388497e3aeba8b591f88248c4c5e3..29ab44deb5aac369d0093c100ba63d0a1b25530a 100644
--- a/VIPSWeb/settings.py
+++ b/VIPSWeb/settings.py
@@ -130,6 +130,7 @@ INSTALLED_APPS = (
# 'django.contrib.admindocs',
'forecasts',
'messages',
+ 'organisms'
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
diff --git a/VIPSWeb/urls.py b/VIPSWeb/urls.py
index d91654b985eca1e50b799832e5384809167e9757..716583459728b8e458fdfe3e910f7bb99c0f0dfb 100644
--- a/VIPSWeb/urls.py
+++ b/VIPSWeb/urls.py
@@ -41,6 +41,7 @@ urlpatterns = patterns('',
url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")),
url(r'^messages/', include('messages.urls', namespace = "messages")),
+ url(r'^organisms/', include('organisms.urls', namespace = "organisms")),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
diff --git a/VIPSWeb/views.py b/VIPSWeb/views.py
index be81801a274eb0465af833ff829ae94390c5e8ad..d5e54b297a147d8576378ac86e10a2471919afac 100644
--- a/VIPSWeb/views.py
+++ b/VIPSWeb/views.py
@@ -17,7 +17,9 @@
from django.shortcuts import render
from django.conf import settings
+from django.utils import translation
from messages.models import Message, MessageTag
+from organisms.models import CropGroup
def index(request):
# Get front page categories. This is defined in local_settings.py
@@ -35,6 +37,7 @@ def index(request):
context = {
'message_tags': message_tags,
'messages_by_tag': messages_by_tag,
+ 'crop_groups': CropGroup.get_crop_groups(translation.get_language())
}
return render(request, 'index.html', context)
diff --git a/forecasts/models.py b/forecasts/models.py
index 9c0cedc683b6d1610033a3ec504cc3cf45b9d73b..54504a373b1a5f15c1d9060b4da6c18adde20a0d 100644
--- a/forecasts/models.py
+++ b/forecasts/models.py
@@ -26,10 +26,12 @@ from django.db import models
from django.utils import translation
from django.core.exceptions import ValidationError
+from organisms.models import Organism
+
# Create your models here.
"""
-Represent a single result from the running of a forecasting model
+Represents a single result from the running of a forecasting model
"""
class ForecastResult:
def __init__(self,forecast_result_id,result_valid_time,warning_status,all_values):
@@ -67,7 +69,8 @@ class ForecastConfiguration:
date_end,
location_point_of_interest,
weather_station_point_of_interest,
- user_id = None):
+ user_id = None,
+ crop_organism = None):
self.forecast_configuration_id = forecast_configuration_id
self.model_id = model_id
self.date_start = date_start
@@ -75,6 +78,7 @@ class ForecastConfiguration:
self.location_point_of_interest = location_point_of_interest#PointOfInterest(location_point_of_interest)
self.weather_station_point_of_interest = weather_station_point_of_interest
self.user_id = user_id
+ self.crop_organism = crop_organism
def set_model_local_name(self, model_local_name):
self.model_local_name = model_local_name
@@ -85,11 +89,11 @@ class ForecastConfiguration:
Currently this is a REST service
"""
@staticmethod
- def get_forecast_configurations():
+ def get_forecast_configurations(crop_organism_ids):
forecasts = []
model_local_names = {}
- for item in ForecastConfiguration.get_forecast_configurations_as_json():
+ for item in ForecastConfiguration.get_forecast_configurations_as_json(None):
forecast = ForecastConfiguration.get_instance_from_dict(item)
# Get the name of the model in the current locale
if model_local_names.get(forecast.model_id, None) == None:
@@ -100,9 +104,19 @@ class ForecastConfiguration:
return forecasts
@staticmethod
- def get_forecast_configurations_as_json():
- requestResult = requests.get("http://%s/rest/organizationforecastconfigurations/%s" % (settings.VIPSLOGIC_SERVER_NAME, settings.VIPS_ORGANIZATION_ID))
- return requestResult.json()
+ def get_forecast_configurations_as_json(crop_organism_ids):
+ 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("http://%s/rest/organizationforecastconfigurations/%s?%s" % (
+ settings.VIPSLOGIC_SERVER_NAME,
+ settings.VIPS_ORGANIZATION_ID,
+ crop_organism_id_paramstring
+ )
+ )
+ return request_result.json()
@staticmethod
def get_forecast_configuration(forecast_configuration_id):
@@ -124,7 +138,8 @@ class ForecastConfiguration:
theDict["dateEnd"],
PointOfInterest(theDict["locationPointOfInterestId"]),
PointOfInterest(theDict["weatherStationPointOfInterestId"]),
- theDict.get("vipsLogicUserId",None)
+ theDict.get("vipsLogicUserId",None),
+ Organism.get_instance_from_dict(theDict.get("cropOrganismId", None))
)
return instance
"""
diff --git a/forecasts/templates/forecasts/index.html b/forecasts/templates/forecasts/index.html
index 5ae6a1a18390aeb7a22d973cf827c4a07a9dcd9b..16253f392c0860ece341521af81f4307155c9fd1 100644
--- a/forecasts/templates/forecasts/index.html
+++ b/forecasts/templates/forecasts/index.html
@@ -27,6 +27,7 @@
<thead>
<tr>
<th>{% trans "Model name" %}</th>
+ <th>{% trans "Crop" %}
<th>{% trans "Location" %}</th>
<th>{% trans "Date start" %}</th>
<th>{% trans "Date end" %}</th>
@@ -37,6 +38,7 @@
{% for forecast_configuration in forecast_configurations %}
<tr>
<td>{{ forecast_configuration.model_local_name }}</td>
+ <td>{{ forecast_configuration.crop_organism.local_name }}</td>
<td>{{ forecast_configuration.location_point_of_interest.name }}</td>
<td>{{ forecast_configuration.date_start }}</td>
<td>{{ forecast_configuration.date_end }}</td>
diff --git a/forecasts/urls.py b/forecasts/urls.py
index 844731fe17127a6414aee43b28d29c27b67d39ff..b9b3fad5976fe945b72540453897d87bec71a691 100644
--- a/forecasts/urls.py
+++ b/forecasts/urls.py
@@ -24,8 +24,10 @@ urlpatterns = patterns('',
# ex: /forecasts/
url(r'^$', views.index, name='index'),
# ex: /forecasts/5/
- url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', cache_page(60 * 15)(views.detail_highcharts_json), name='detail_highcharts_json'),
- url(r'^(?P<forecast_id>\d+)/$', cache_page(60 * 15)(views.detail), name='detail'),
+ #url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', cache_page(60 * 15)(views.detail_highcharts_json), name='detail_highcharts_json'),
+ url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', views.detail_highcharts_json, name='detail_highcharts_json'),
+ #url(r'^(?P<forecast_id>\d+)/$', cache_page(60 * 15)(views.detail), name='detail'),
+ url(r'^(?P<forecast_id>\d+)/$', (views.detail), name='detail'),
url(r'^models/(?P<model_id>\w+)/$', views.models_detail, name='models_detail'),
url(r'^models/js/modelLocalNames.js', cache_page(60 * 30)(views.model_local_names_js), name='model_local_names_js'),
url(r'^models/$', views.models_index, name='models_index'),
diff --git a/forecasts/views.py b/forecasts/views.py
index 700abc850d13206e427574a9f4067fec308c88e4..cfb2b5405cfc0f57b27c1ff302bc807c3b586104 100644
--- a/forecasts/views.py
+++ b/forecasts/views.py
@@ -25,7 +25,7 @@ from django.shortcuts import render
from forecasts.models import ForecastConfiguration, ForecastResult, ResultParameter, Model, MeasurementUnit, ModelGraphParameter
def index(request):
- forecast_configurations = ForecastConfiguration.get_forecast_configurations()
+ forecast_configurations = ForecastConfiguration.get_forecast_configurations(None)
forecast_configurations.sort(key=lambda x: x.date_start, reverse=False)
context = {'forecast_configurations': forecast_configurations}
return render(request, 'forecasts/index.html', context)
diff --git a/organisms/__init__.py b/organisms/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/organisms/admin.py b/organisms/admin.py
new file mode 100644
index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e
--- /dev/null
+++ b/organisms/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/organisms/locale/nb/LC_MESSAGES/custom.mo b/organisms/locale/nb/LC_MESSAGES/custom.mo
new file mode 100644
index 0000000000000000000000000000000000000000..69cdba616a8d58cec09539f6844bf65727221bee
Binary files /dev/null and b/organisms/locale/nb/LC_MESSAGES/custom.mo differ
diff --git a/organisms/locale/nb/LC_MESSAGES/custom.po b/organisms/locale/nb/LC_MESSAGES/custom.po
new file mode 100644
index 0000000000000000000000000000000000000000..cee4c5d736d8f6e68126c3374b3f6f4637e3a22d
--- /dev/null
+++ b/organisms/locale/nb/LC_MESSAGES/custom.po
@@ -0,0 +1,23 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-09-04 09:26+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+# CUSTOM STUFF
+msgid "Fruit"
+msgstr "Frukt"
diff --git a/organisms/locale/nb/LC_MESSAGES/django.mo b/organisms/locale/nb/LC_MESSAGES/django.mo
new file mode 100644
index 0000000000000000000000000000000000000000..dbccee87d852359c8c4387b3d0fa4d60d2529952
Binary files /dev/null and b/organisms/locale/nb/LC_MESSAGES/django.mo differ
diff --git a/organisms/locale/nb/LC_MESSAGES/django.po b/organisms/locale/nb/LC_MESSAGES/django.po
new file mode 100644
index 0000000000000000000000000000000000000000..f8a340213a6ce5c0e60cbedb8f69707a976b0090
--- /dev/null
+++ b/organisms/locale/nb/LC_MESSAGES/django.po
@@ -0,0 +1,27 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-09-04 09:26+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: templates/organisms/index.html:3 templates/organisms/index.html.py:5
+msgid "Organisms"
+msgstr "Organismer"
+
+#: templates/organisms/index.html:5
+msgid "Crops"
+msgstr "Kulturer"
diff --git a/organisms/models.py b/organisms/models.py
new file mode 100644
index 0000000000000000000000000000000000000000..dd4a9a0a00d617e0e4bdbbb993b00138b7928b38
--- /dev/null
+++ b/organisms/models.py
@@ -0,0 +1,82 @@
+# Copyright (C) 2014 Bioforsk
+#
+# This file is part of VIPSWeb
+#
+# VIPSWeb is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIPSWeb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>.
+
+import requests
+from django.conf import settings
+from django.utils import translation
+
+class CropGroup:
+ def __init__(self,
+ crop_group_id,
+ name,
+ crop_ids
+ ):
+ self.crop_group_id = crop_group_id
+ self.name = name
+ self.crop_ids = crop_ids
+
+ @staticmethod
+ def get_crop_groups(language):
+ crop_groups = []
+ for item in settings.CROP_GROUPS:
+ crop_groups.append(CropGroup.get_instance_from_dict(item,language))
+ return crop_groups
+
+ @staticmethod
+ def get_instance_from_dict(dict,language):
+ return CropGroup(dict["crop_group_id"],
+ dict["name"].get(language,dict["name"]["en"]),
+ dict["crop_ids"]
+ )
+
+
+class Organism:
+ def __init__(self,
+ organism_id,
+ latin_name,
+ trade_name,
+ parent_organism_id,
+ hierarchy_category_id,
+ local_name
+ ):
+ self.organism_id = organism_id
+ self.latin_name = latin_name
+ self.trade_name = trade_name
+ self.parent_organism_id = parent_organism_id
+ self.hierarchy_category_id = hierarchy_category_id
+ self.local_name = local_name
+
+ @staticmethod
+ def get_instance_from_dict(theDict):
+ if theDict == None:
+ return None
+ # Get the local name (if it exists, fallback is English, then Latin name)
+ local_name = ""
+ for item in theDict["organismLocaleSet"]:
+ if item["organismLocalePK"]["locale"] == translation.get_language() \
+ or (local_name == "" and item["organismLocalePK"]["locale"] == "en"):
+ local_name = item["localName"]
+ if local_name == "":
+ local_name = theDict["latinName"]
+
+ return Organism(theDict["organismId"],
+ theDict["latinName"],
+ theDict["tradeName"],
+ theDict["parentOrganismId"],
+ theDict["hierarchyCategoryId"],
+ local_name
+ )
diff --git a/organisms/templates/organisms/index.html b/organisms/templates/organisms/index.html
new file mode 100644
index 0000000000000000000000000000000000000000..537af5d1f290922aab445541f44622b9d8171702
--- /dev/null
+++ b/organisms/templates/organisms/index.html
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% block title%}{% trans "Organisms" %}{%endblock%}
+{% block content %}
+<h1>{% trans "Organisms" %}/{% trans "Crops" %}</h1>
+<p>{% trans "Crop" %}</p>
+{% endblock %}
\ No newline at end of file
diff --git a/organisms/tests.py b/organisms/tests.py
new file mode 100644
index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6
--- /dev/null
+++ b/organisms/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/organisms/urls.py b/organisms/urls.py
new file mode 100644
index 0000000000000000000000000000000000000000..a6a352f82f73c5e791ad26b0bcfdbf50d05127c3
--- /dev/null
+++ b/organisms/urls.py
@@ -0,0 +1,27 @@
+# Copyright (C) 2014 Bioforsk
+#
+# This file is part of VIPSWeb
+#
+# VIPSWeb is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIPSWeb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>.
+
+from django.conf.urls import patterns, url
+
+from organisms import views
+
+urlpatterns = patterns('',
+ # ex: /organisms/
+ url(r'^$', views.index, name='index'),
+ # ex: /organisms/5/
+ #url(r'^(?P<organism_id>\d+)/$', views.detail, name='detail'),
+)
\ No newline at end of file
diff --git a/organisms/views.py b/organisms/views.py
new file mode 100644
index 0000000000000000000000000000000000000000..961f111e5cf8dda9e26f7812b57fe24de412ae06
--- /dev/null
+++ b/organisms/views.py
@@ -0,0 +1,26 @@
+# Copyright (C) 2014 Bioforsk
+#
+# This file is part of VIPSWeb
+#
+# VIPSWeb is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIPSWeb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>.
+
+from django.shortcuts import render, get_object_or_404
+
+
+def index(request):
+ context = {
+
+ }
+ return render(request, 'organisms/index.html', context)
+# Create your views here.