From ccd946c00a4239b0e9d60cc5882601049f1287d9 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@bioforsk.no> Date: Fri, 8 Apr 2016 16:34:10 +0200 Subject: [PATCH] Apple fruit moth module Alpha 1 --- VIPSWeb/settings.py | 1 + VIPSWeb/urls.py | 1 + applefruitmoth/__init__.py | 0 applefruitmoth/admin.py | 3 + .../locale/nb/LC_MESSAGES/django.mo | Bin 0 -> 632 bytes .../locale/nb/LC_MESSAGES/django.po | 33 ++++++ applefruitmoth/migrations/__init__.py | 0 applefruitmoth/models.py | 3 + .../static/applefruitmoth/js/map.js | 101 ++++++++++++++++++ .../templates/applefruitmoth/index.html | 77 +++++++++++++ applefruitmoth/tests.py | 3 + applefruitmoth/urls.py | 25 +++++ applefruitmoth/views.py | 9 ++ 13 files changed, 256 insertions(+) create mode 100644 applefruitmoth/__init__.py create mode 100644 applefruitmoth/admin.py create mode 100644 applefruitmoth/locale/nb/LC_MESSAGES/django.mo create mode 100644 applefruitmoth/locale/nb/LC_MESSAGES/django.po create mode 100644 applefruitmoth/migrations/__init__.py create mode 100644 applefruitmoth/models.py create mode 100644 applefruitmoth/static/applefruitmoth/js/map.js create mode 100644 applefruitmoth/templates/applefruitmoth/index.html create mode 100644 applefruitmoth/tests.py create mode 100644 applefruitmoth/urls.py create mode 100644 applefruitmoth/views.py diff --git a/VIPSWeb/settings.py b/VIPSWeb/settings.py index ed1ef3c6..62faca8f 100644 --- a/VIPSWeb/settings.py +++ b/VIPSWeb/settings.py @@ -137,6 +137,7 @@ INSTALLED_APPS = ( 'cerealblotchmodels', 'calculators', 'roughage', + 'applefruitmoth', 'fusarium', 'security', 'VIPSWeb' diff --git a/VIPSWeb/urls.py b/VIPSWeb/urls.py index 5d4f571e..df85d26b 100644 --- a/VIPSWeb/urls.py +++ b/VIPSWeb/urls.py @@ -50,6 +50,7 @@ urlpatterns = patterns('', url(r'^roughage/', include('roughage.urls', namespace = "roughage")), url(r'^security/', include('security.urls', namespace = "security")), url(r'^fusarium/', include('fusarium.urls', namespace = "fusarium")), + url(r'^applefruitmoth/', include('applefruitmoth.urls', namespace = "applefruitmoth")), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), url(r'^tinymce/', include('tinymce.urls')), diff --git a/applefruitmoth/__init__.py b/applefruitmoth/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/applefruitmoth/admin.py b/applefruitmoth/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/applefruitmoth/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/applefruitmoth/locale/nb/LC_MESSAGES/django.mo b/applefruitmoth/locale/nb/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..8059c528026978fb9ef90f9de92b26a52f068b24 GIT binary patch literal 632 zcmca7#4?qEfq{XAfq_AWfq}t>fq{XQfq@|gB*?(PPyiJ#WME*>W?*3GV_;z5U|?X_ z#lXOj&B(xTn1O*ojDdkcpNWA%oq>VDjfsJQlYxODkBNbSk%57M8EOs_)D8y6f`Xh> zg|wp5%o2s%{E`fXwEUvf<iz5V%)E34m(=3qqRfJl%=|os{4|9`d}@7Di;EM}Q;Qh_ zit@8klS_0xQ*^^pi;6Sz^Q;sC9G$%#-CY&JT!Vr={r$LtQVa5nN_2gT(=$_aol4V- zbwl#46u1KXLv)>sQWHTI>bfMBq*^H$85o-B8kp!BSST2pSs7Vq8yFcFa0U452Bnr| zf((bMi*$7i()IP%b#YYi@VD~y)Q<A^bLH|$EH2RvDN4*M&PgoEFS1f_3-$3)@N@Ka zRj_gOb@cRcaCC7Aat#i)<MK(&OD|1KPt^@cP0Y1Y@Nx8W4+S~d#>dAYCsQxKC>^23 zN`cGQ)7KT@KSMnOF6aEblGMBs-H^(HR4av&)QS@Qf}F(6JZpvIjKrei)Dqj!5I0>5 zggTJ3(o&0bUGtLjQ!?|?trRShGE2Aua!QL5b9CMEi*k#t6!Hqd++tfJYXu0?RwGYA z(N@7w)0&GRC_g<fHR<rOqTItfa&pQNi;8nV@#d6ToL!VzmYP$Xs*qTwP=r-gY951c LY7WTa)FK7|HG#GL literal 0 HcmV?d00001 diff --git a/applefruitmoth/locale/nb/LC_MESSAGES/django.po b/applefruitmoth/locale/nb/LC_MESSAGES/django.po new file mode 100644 index 00000000..78fbdcee --- /dev/null +++ b/applefruitmoth/locale/nb/LC_MESSAGES/django.po @@ -0,0 +1,33 @@ +# 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: 2016-04-08 16:28+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/applefruitmoth/index.html:25 +#: templates/applefruitmoth/index.html:27 +msgid "Apple fruit moth forecasting" +msgstr "Rognebærmøllvarsling" + +#: templates/applefruitmoth/index.html:32 +msgid "Description of apple fruit moth forecasting" +msgstr "Beskrivelse av rognebærmøllvarslingen" + +#: templates/applefruitmoth/index.html:33 +msgid "Messages" +msgstr "Meldinger" + diff --git a/applefruitmoth/migrations/__init__.py b/applefruitmoth/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/applefruitmoth/models.py b/applefruitmoth/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/applefruitmoth/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/applefruitmoth/static/applefruitmoth/js/map.js b/applefruitmoth/static/applefruitmoth/js/map.js new file mode 100644 index 00000000..9730a144 --- /dev/null +++ b/applefruitmoth/static/applefruitmoth/js/map.js @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2016 NIBIO <http://www.nibio.no/>. + * + * This file is part of VIPSWeb. + * VIPSWeb is free software: you can redistribute it and/or modify + * it under the terms of the NIBIO Open Source License as published by + * NIBIO, either version 1 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 + * NIBIO Open Source License for more details. + * + * You should have received a copy of the NIBIO Open Source License + * along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>. + * + */ + +var initMap = function(container, mapAttribution) +{ + // Creating background layer, Open Street Map is default + var backgroundLayer = new ol.layer.Tile({ + source: new ol.source.OSM({ + attributions: [ + new ol.Attribution({ + html: mapAttribution + }) + ] + }) + }); + + forecastLayer = new ol.layer.Vector({ + source: new ol.source.Vector({ + url: "http://" + settings.vipslogicServerName + "/rest/applefruitmoth/observationsites/kml/2016", + format: new ol.format.KML({"extractAttributes":true}), + projection: ol.proj.get('EPSG:3857') + }) + }); + // Layer for popup + var popOverlay = new ol.Overlay({ + element: document.getElementById("popover") + }); + + // Creating the map + map = new ol.Map({ + target: container, + layers: [backgroundLayer, forecastLayer], + overlays: [popOverlay], + renderer: 'canvas' + }); + + // Setting zoom and center for the map (need to do this after creating map. so that we can transform our + // center to correct map projection) + var view = new ol.View({ + center: ol.proj.transform([9,61], 'EPSG:4326', map.getView().getProjection().getCode()), + zoom: 6 + }); + map.setView(view); + + // Using Bootstrap's popover plugin. See http://getbootstrap.com/javascript/#popovers + var poiDetails = $("#popover"); + + // State cariable + var currentClickedFeature = false; + + // Displays popup with forecasts for a given station + // (if there is a station where the click event is fired) + var displayFeatureDetails = function(pixel, coordinate) { + var feature = map.forEachFeatureAtPixel(pixel, function(feature,layer){ + return feature; + }); + + if (feature) { + // Position the popup, and hiding it + // Resetting information from (possible) former popups + var geometry = feature.getGeometry(); + popOverlay.setPosition(geometry.getCoordinates()); + poiDetails.popover('destroy'); + currentClickedFeature = feature; + poiDetails.popover({ + animation: true, + trigger: 'manual', + html: true, + placement: "auto top", + title: feature.get("name"), + content: feature.get("description") + }); + + poiDetails.popover('show'); + } else { + currentClickedFeature = null; + poiDetails.popover('destroy'); + } + }; + // On click, display forecasts in popup + map.on('singleclick', function(evt) { + var pixel = map.getEventPixel(evt.originalEvent); + displayFeatureDetails(pixel); + }); +} \ No newline at end of file diff --git a/applefruitmoth/templates/applefruitmoth/index.html b/applefruitmoth/templates/applefruitmoth/index.html new file mode 100644 index 00000000..b1af8b4e --- /dev/null +++ b/applefruitmoth/templates/applefruitmoth/index.html @@ -0,0 +1,77 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% comment %} + +# +# Copyright (c) 2016 NIBIO <http://www.nibio.no/>. +# +# This file is part of VIPSWeb. +# VIPSWeb is free software: you can redistribute it and/or modify +# it under the terms of the NIBIO Open Source License as published by +# NIBIO, either version 1 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 +# NIBIO Open Source License for more details. +# +# You should have received a copy of the NIBIO Open Source License +# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>. +# + +{% endcomment %} +{% load i18n %} +{% block title%}{% trans "Apple fruit moth forecasting" %}{%endblock%} +{% block content %} +<h1>{% trans "Apple fruit moth forecasting" %}</h1> +<div class="singleBlockContainer"> + + <div class="row"> + <div class="col-md-6"> + <p>{% trans "Description of apple fruit moth forecasting"%}</p> + <h2>{% trans "Messages" %}</h2> + {% for message in vips_messages %} + <div class="panel-group" id="accordion"> + <div class="panel panel-default"> + <div class="panel-heading"> + <h4 class="panel-title"> + <a data-toggle="collapse" data-parent="#accordion" href="#collapse{{message.message_id}}"> + {{message.date_pub|date:"Y-m-d"}}: {{message.heading}}</a> + </h4> + </div> + <div id="collapse1" class="panel-collapse collapse{% if forloop.first %} in{% endif %}"> + <div class="panel-body"> + <p class="lead">{{message.lead_paragraph}}</p> + <p>{{message.body}}</p> + </div> + </div> + </div> + </div> + {% endfor %} + + </div> + <div class="col-md-6"> + <div id="appleFruitMothForecastMap" class="map" style="height: 600px;"><div id="popover"></div></div> + </div> + </div> +</div> + + +{% endblock %} +{% block customCSS %} +<link rel="stylesheet" href="{% static "css/3rdparty/ol.css" %}" type="text/css"> +{% endblock %} +{% block customJS %} +<script type="text/javascript" src="{% static "js/3rdparty/ol-debug.js" %}"></script> +<script type="text/javascript" src="{% url "views.settings_js" %}"></script> +<script type="text/javascript" src="{% static "js/util.js" %}"></script> +<script type="text/javascript" src="{% static "applefruitmoth/js/map.js" %}"></script> +<script type="text/javascript"> + $(document).ready(function() { + + + initMap("appleFruitMothForecastMap","{{settings.MAP_ATTRIBUTION|safe}}"); + }); +</script> +{% endblock %} \ No newline at end of file diff --git a/applefruitmoth/tests.py b/applefruitmoth/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/applefruitmoth/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/applefruitmoth/urls.py b/applefruitmoth/urls.py new file mode 100644 index 00000000..a4afed37 --- /dev/null +++ b/applefruitmoth/urls.py @@ -0,0 +1,25 @@ +# +# Copyright (c) 2016 NIBIO <http://www.nibio.no/>. +# +# This file is part of VIPSWeb. +# VIPSWeb is free software: you can redistribute it and/or modify +# it under the terms of the NIBIO Open Source License as published by +# NIBIO, either version 1 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 +# NIBIO Open Source License for more details. +# +# You should have received a copy of the NIBIO Open Source License +# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>. +# + +from django.conf.urls import patterns, url + +from applefruitmoth import views + +urlpatterns = patterns('', + url(r'^$', views.index, name='index'), +) \ No newline at end of file diff --git a/applefruitmoth/views.py b/applefruitmoth/views.py new file mode 100644 index 00000000..23230136 --- /dev/null +++ b/applefruitmoth/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +# Create your views here. +from vips_messages.models import Message, MessageTag + +def index(request): + vips_messages = Message.get_messages_by_tag(4) # Getting apple fruit moth messages + context = {"vips_messages": vips_messages} + return render(request, 'applefruitmoth/index.html', context) -- GitLab