Skip to content
Snippets Groups Projects
Commit 02fc1896 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

First version of crop type select

New app: organisms
parent a622b4ad
Branches
Tags
No related merge requests found
Showing
with 242 additions and 12 deletions
...@@ -107,4 +107,12 @@ MAP_ZOOMLEVEL = 4 ...@@ -107,4 +107,12 @@ MAP_ZOOMLEVEL = 4
MAP_ATTRIBUTION = "&copy; <a href='http://www.openstreetmap.org'>OpenStreetMap</a> contributors" MAP_ATTRIBUTION = "&copy; <a href='http://www.openstreetmap.org'>OpenStreetMap</a> contributors"
# The message tags to use on the front page # The message tags to use on the front page
FRONTPAGE_MESSAGE_TAG_IDS = [1,2,3] FRONTPAGE_MESSAGE_TAG_IDS = [1,2,3]
\ No newline at end of file
# 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
...@@ -130,6 +130,7 @@ INSTALLED_APPS = ( ...@@ -130,6 +130,7 @@ INSTALLED_APPS = (
# 'django.contrib.admindocs', # 'django.contrib.admindocs',
'forecasts', 'forecasts',
'messages', 'messages',
'organisms'
) )
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer' SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
......
...@@ -41,6 +41,7 @@ urlpatterns = patterns('', ...@@ -41,6 +41,7 @@ urlpatterns = patterns('',
url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")), url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")),
url(r'^messages/', include('messages.urls', namespace = "messages")), url(r'^messages/', include('messages.urls', namespace = "messages")),
url(r'^organisms/', include('organisms.urls', namespace = "organisms")),
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
from django.shortcuts import render from django.shortcuts import render
from django.conf import settings from django.conf import settings
from django.utils import translation
from messages.models import Message, MessageTag from messages.models import Message, MessageTag
from organisms.models import CropGroup
def index(request): def index(request):
# Get front page categories. This is defined in local_settings.py # Get front page categories. This is defined in local_settings.py
...@@ -35,6 +37,7 @@ def index(request): ...@@ -35,6 +37,7 @@ def index(request):
context = { context = {
'message_tags': message_tags, 'message_tags': message_tags,
'messages_by_tag': messages_by_tag, 'messages_by_tag': messages_by_tag,
'crop_groups': CropGroup.get_crop_groups(translation.get_language())
} }
return render(request, 'index.html', context) return render(request, 'index.html', context)
......
...@@ -26,10 +26,12 @@ from django.db import models ...@@ -26,10 +26,12 @@ from django.db import models
from django.utils import translation from django.utils import translation
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from organisms.models import Organism
# Create your models here. # 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: class ForecastResult:
def __init__(self,forecast_result_id,result_valid_time,warning_status,all_values): def __init__(self,forecast_result_id,result_valid_time,warning_status,all_values):
...@@ -67,7 +69,8 @@ class ForecastConfiguration: ...@@ -67,7 +69,8 @@ class ForecastConfiguration:
date_end, date_end,
location_point_of_interest, location_point_of_interest,
weather_station_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.forecast_configuration_id = forecast_configuration_id
self.model_id = model_id self.model_id = model_id
self.date_start = date_start self.date_start = date_start
...@@ -75,6 +78,7 @@ class ForecastConfiguration: ...@@ -75,6 +78,7 @@ class ForecastConfiguration:
self.location_point_of_interest = location_point_of_interest#PointOfInterest(location_point_of_interest) 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.weather_station_point_of_interest = weather_station_point_of_interest
self.user_id = user_id self.user_id = user_id
self.crop_organism = crop_organism
def set_model_local_name(self, model_local_name): def set_model_local_name(self, model_local_name):
self.model_local_name = model_local_name self.model_local_name = model_local_name
...@@ -85,11 +89,11 @@ class ForecastConfiguration: ...@@ -85,11 +89,11 @@ class ForecastConfiguration:
Currently this is a REST service Currently this is a REST service
""" """
@staticmethod @staticmethod
def get_forecast_configurations(): def get_forecast_configurations(crop_organism_ids):
forecasts = [] forecasts = []
model_local_names = {} 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) forecast = ForecastConfiguration.get_instance_from_dict(item)
# Get the name of the model in the current locale # Get the name of the model in the current locale
if model_local_names.get(forecast.model_id, None) == None: if model_local_names.get(forecast.model_id, None) == None:
...@@ -100,9 +104,19 @@ class ForecastConfiguration: ...@@ -100,9 +104,19 @@ class ForecastConfiguration:
return forecasts return forecasts
@staticmethod @staticmethod
def get_forecast_configurations_as_json(): def get_forecast_configurations_as_json(crop_organism_ids):
requestResult = requests.get("http://%s/rest/organizationforecastconfigurations/%s" % (settings.VIPSLOGIC_SERVER_NAME, settings.VIPS_ORGANIZATION_ID)) crop_organism_id_paramstring = ""
return requestResult.json() 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 @staticmethod
def get_forecast_configuration(forecast_configuration_id): def get_forecast_configuration(forecast_configuration_id):
...@@ -124,7 +138,8 @@ class ForecastConfiguration: ...@@ -124,7 +138,8 @@ class ForecastConfiguration:
theDict["dateEnd"], theDict["dateEnd"],
PointOfInterest(theDict["locationPointOfInterestId"]), PointOfInterest(theDict["locationPointOfInterestId"]),
PointOfInterest(theDict["weatherStationPointOfInterestId"]), PointOfInterest(theDict["weatherStationPointOfInterestId"]),
theDict.get("vipsLogicUserId",None) theDict.get("vipsLogicUserId",None),
Organism.get_instance_from_dict(theDict.get("cropOrganismId", None))
) )
return instance return instance
""" """
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<thead> <thead>
<tr> <tr>
<th>{% trans "Model name" %}</th> <th>{% trans "Model name" %}</th>
<th>{% trans "Crop" %}
<th>{% trans "Location" %}</th> <th>{% trans "Location" %}</th>
<th>{% trans "Date start" %}</th> <th>{% trans "Date start" %}</th>
<th>{% trans "Date end" %}</th> <th>{% trans "Date end" %}</th>
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
{% for forecast_configuration in forecast_configurations %} {% for forecast_configuration in forecast_configurations %}
<tr> <tr>
<td>{{ forecast_configuration.model_local_name }}</td> <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.location_point_of_interest.name }}</td>
<td>{{ forecast_configuration.date_start }}</td> <td>{{ forecast_configuration.date_start }}</td>
<td>{{ forecast_configuration.date_end }}</td> <td>{{ forecast_configuration.date_end }}</td>
......
...@@ -24,8 +24,10 @@ urlpatterns = patterns('', ...@@ -24,8 +24,10 @@ urlpatterns = patterns('',
# ex: /forecasts/ # ex: /forecasts/
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
# ex: /forecasts/5/ # 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+)/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/$', 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/(?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/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'), url(r'^models/$', views.models_index, name='models_index'),
......
...@@ -25,7 +25,7 @@ from django.shortcuts import render ...@@ -25,7 +25,7 @@ from django.shortcuts import render
from forecasts.models import ForecastConfiguration, ForecastResult, ResultParameter, Model, MeasurementUnit, ModelGraphParameter from forecasts.models import ForecastConfiguration, ForecastResult, ResultParameter, Model, MeasurementUnit, ModelGraphParameter
def index(request): 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) forecast_configurations.sort(key=lambda x: x.date_start, reverse=False)
context = {'forecast_configurations': forecast_configurations} context = {'forecast_configurations': forecast_configurations}
return render(request, 'forecasts/index.html', context) return render(request, 'forecasts/index.html', context)
......
from django.contrib import admin
# Register your models here.
File added
# 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"
File added
# 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"
# 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
)
{% 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
from django.test import TestCase
# Create your tests here.
# 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
# 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment