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

More support for forecast and message output

parent 28a3a2e1
No related branches found
No related tags found
No related merge requests found
Showing
with 225 additions and 29 deletions
...@@ -8,7 +8,7 @@ msgid "" ...@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-01-16 12:46+0100\n" "POT-Creation-Date: 2014-01-16 14:40+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
......
...@@ -113,6 +113,7 @@ MIDDLEWARE_CLASSES = ( ...@@ -113,6 +113,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'common.middleware.whodid.WhodidMiddleware'
#'django.middleware.locale.LocaleMiddleware', #'django.middleware.locale.LocaleMiddleware',
# Uncomment the next line for simple clickjacking protection: # Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware', # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
......
...@@ -43,12 +43,19 @@ div.messages_illustration{ ...@@ -43,12 +43,19 @@ div.messages_illustration{
height: 400px; height: 400px;
} }
#tooltip, #popover { #tooltip{
position: absolute; position: absolute;
height: 1px; height: 1px;
width: 1px; width: 1px;
z-index: 100; z-index: 100;
} }
div.popover {
min-width: 250px;
max-width: 400px !important;
}
/* /*
.tooltip.in { .tooltip.in {
opacity: 1; opacity: 1;
......
...@@ -124,7 +124,7 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) ...@@ -124,7 +124,7 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname)
top: (pixel[1] - 15) + 'px' top: (pixel[1] - 15) + 'px'
}); });
*/ */
popOverlay.setPosition(coordinate); popOverlay.setPosition(coordinate);
map.getFeatures({ map.getFeatures({
pixel: pixel, pixel: pixel,
layers: [forecastLayer], layers: [forecastLayer],
...@@ -162,15 +162,18 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) ...@@ -162,15 +162,18 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname)
} }
//console.log(forecastConfiguration); //console.log(forecastConfiguration);
resultHTML.push("<div class=\"" + alertClass + "\">" + new Date(data.results[index].resultValidTime) + ": <a href=\"/forecasts/" + forecastConfiguration.forecastConfigurationId + "\" class=\"alert-link\">" + forecastConfiguration.modelId + "</a></div>"); resultHTML.push("<div class=\"" + alertClass + "\">" + moment(data.results[index].resultValidTime).format("YYYY-MM-DD") + ": <a href=\"/forecasts/" + forecastConfiguration.forecastConfigurationId + "\" class=\"alert-link\">" + modelLocalNames[forecastConfiguration.modelId] + "</a></div>");
} }
if(resultHTML.length == 0) if(resultHTML.length == 0)
{ {
resultHTML.push(gettext("No forecasts found for") + " " + feature.get("name")); resultHTML.push(gettext("No forecasts found for") + " " + feature.get("name"));
} }
// Testing
//resultHTML = ["Mange små ord mange små ord Få ord"];
poiDetails.popover({ poiDetails.popover({
animation: false, animation: true,
trigger: 'manual', trigger: 'manual',
html: true, html: true,
placement: "auto top", placement: "auto top",
......
This diff is collapsed.
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="/forecasts">{% trans "Forecasts" %}</a></li> <li><a href="/forecasts">{% trans "Forecasts" %}</a></li>
<li><a href="/messages">{% trans "Messages" %}</a></li> <li><a href="/messages">{% trans "Messages" %}</a></li>
<li class="dropdown"> <!--li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Dropdown" %} <b class="caret"></b></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Dropdown" %} <b class="caret"></b></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#">{% trans "Action" %}</a></li> <li><a href="#">{% trans "Action" %}</a></li>
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<li><a href="#">{% trans "Separated link" %}</a></li> <li><a href="#">{% trans "Separated link" %}</a></li>
<li><a href="#">{% trans "One more separated link" %}</a></li> <li><a href="#">{% trans "One more separated link" %}</a></li>
</ul> </ul>
</li> </li-->
</ul> </ul>
</div><!-- /.navbar-collapse --> </div><!-- /.navbar-collapse -->
......
...@@ -18,15 +18,17 @@ ...@@ -18,15 +18,17 @@
along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>. along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %} {% endcomment %}
{% load i18n l10n staticfiles %} {% load i18n l10n staticfiles forecast_extras %}
{% block title%}{% trans "Welcome" %}{%endblock%} {% block title%}{% trans "Welcome" %}{%endblock%}
{% block customCSS %} {% block customCSS %}
<link rel="stylesheet" href="http://ol3js.org/en/master/build/ol.css" type="text/css"> <link rel="stylesheet" href="http://ol3js.org/en/master/build/ol.css" type="text/css">
{% endblock %} {% endblock %}
{% block customJS %} {% block customJS %}
<script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script> <script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script>
<script src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></script> <script type="text/javascript" src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></script>
<script src="{% static "js/forecastmap.js" %}"></script> <script type="text/javascript" src="/forecasts/models/js/modelLocalNames.js"></script>
<script type="text/javascript" src="{% static "js/moment.min.js" %}"></script>
<script type="text/javascript" src="{% static "js/forecastmap.js" %}"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
// Init frontpage map. Depending on forecastmap.js. // Init frontpage map. Depending on forecastmap.js.
...@@ -38,20 +40,32 @@ ...@@ -38,20 +40,32 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<!-- Start map container --> <!-- Start map container -->
<div class="col-md-9"> <div class="col-md-8">
<div id="map" class="map"> <div id="map" class="map">
<!-- Info window box --> <!-- Info window box -->
<div id="tooltip"></div> <div id="tooltip"></div>
<div id="popover"></div> <div id="popover"></div>
</div> </div>
</div><!-- End map container --> </div><!-- End map container -->
<div class="col-md-3"> <div class="col-md-4">
<h1>{% trans "Messages" %}</h1> <h1>{% trans "Messages" %}</h1>
<ul> <table class="table table-hover table-condensed table-striped">
{% for message in messages %} {% for message_tag in message_tags %}
<li><a href="{% url 'messages:detail' message.id %}">{{message.headline}}</a></li> <thead>
{% endfor %} <tr>
</ul> <th colspan="2">{{message_tag.title}}</th>
</tr>
</thead>
<tbody>
{% for message in messages_by_tag|lookup:message_tag.id %}
<tr>
<td>{{ message.pub_date|date:"Y-m-d" }}</td>
<td><a href="{% url 'messages:detail' message.id %}">{{message.headline}}</a></td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
</div> </div>
</div><!-- End row with sidebar and contents container --> </div><!-- End row with sidebar and contents container -->
{% endblock %} {% endblock %}
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.conf import settings
from messages.models import Message from messages.models import Message, MessageTag
def index(request): def index(request):
# Get frontpage categories. This is defined in local_settings.py
message_tags = []
messages_by_tag = {}
for message_tag_id in settings.FRONTPAGE_MESSAGE_TAG_IDS:
message_tag = MessageTag.objects.get(pk=message_tag_id)
print message_tag
message_tags.append(message_tag)
messages = Message.objects.filter(message_tags__pk=message_tag_id)
messages_by_tag[message_tag_id] = messages
#for message in messages:
# print message
#messages_ordered.append(message_tagged)
# Last 10 messages # Last 10 messages
messages = Message.objects.order_by('pub_date').reverse()[:10] messages = Message.objects.order_by('pub_date').reverse()[:10]
context = { context = {
'messages' : messages, 'messages' : messages,
'message_tags': message_tags,
'messages_by_tag': messages_by_tag
} }
return render(request, 'index.html', context) return render(request, 'index.html', context)
......
"""
Copyright (C) 2014 Bioforsk/mindlace
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/>.
"""
"""
Add user created_by and modified_by foreign key refs to any model automatically.
Found here: https://gist.github.com/mindlace/3918300
"""
from django.db.models import signals
from django.utils.functional import curry
class WhodidMiddleware(object):
def process_request(self, request):
if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
if hasattr(request, 'user') and request.user.is_authenticated():
user = request.user
else:
user = None
mark_whodid = curry(self.mark_whodid, user)
signals.pre_save.connect(mark_whodid, dispatch_uid = (self.__class__, request,), weak = False)
def process_response(self, request, response):
signals.pre_save.disconnect(dispatch_uid = (self.__class__, request,))
return response
def mark_whodid(self, user, sender, instance, **kwargs):
print instance
if not getattr(instance, 'created_by_id', None):
instance.created_by = user
if hasattr(instance,'modified_by_id'):
instance.modified_by = user
\ No newline at end of file
...@@ -180,17 +180,23 @@ class Model: ...@@ -180,17 +180,23 @@ class Model:
@staticmethod @staticmethod
def get_model(model_id): def get_model(model_id):
cur_language = translation.get_language() cur_language = translation.get_language()
name = Model.get_local_name_for_model(model_id) local_name = Model.get_local_name_for_model(model_id)
description = requests.get("http://%s/models/%s/description/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text description = requests.get("http://%s/models/%s/description/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text
usage = requests.get("http://%s/models/%s/usage/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text usage = requests.get("http://%s/models/%s/usage/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text
sample_config = requests.get("http://%s/models/%s/sampleconfig" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id)).text sample_config = requests.get("http://%s/models/%s/sampleconfig" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id)).text
return Model(model_id,name, description, usage,sample_config) return Model(model_id,local_name, description, usage,sample_config)
@staticmethod @staticmethod
def get_local_name_for_model(model_id): def get_local_name_for_model(model_id):
cur_language = translation.get_language() cur_language = translation.get_language()
return requests.get("http://%s/models/%s/name/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text return requests.get("http://%s/models/%s/name/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME, model_id, cur_language)).text
@staticmethod
def get_models_local_names():
cur_language = translation.get_language()
model_ids = requests.get("http://%s/models/json/%s" % (settings.VIPSCOREMANAGER_SERVER_NAME,cur_language))
return model_ids.json()
""" """
STUFF IN LOCAL DATABASE STUFF IN LOCAL DATABASE
""" """
......
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% block title%}{{model_name}} - {% trans "Models" %}{%endblock%} {% block title%}{{model.local_name}} - {% trans "Models" %}{%endblock%}
{% block content %} {% block content %}
<h1>{{model_name}}</h1> <h1>{{model.local_name}}</h1>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#modelDescription">{% trans "Description" %}</a></li> <li class="active"><a data-toggle="tab" href="#modelDescription">{% trans "Description" %}</a></li>
<li><a data-toggle="tab" href="#modelUsage">{% trans "Usage" %}</a></li> <li><a data-toggle="tab" href="#modelUsage">{% trans "Usage" %}</a></li>
......
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* 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/>.
*
*/
/**
* Include this in your HTML page if you want to avoid fetching local names
* of the models asynchronously from VIPSLogic
*
* @copyright 2014 <a href="http://www.bioforsk.no/">Bioforsk</a>
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
{% load forecast_extras %}
var modelLocalNames= {};
{% for model in models_local_names %}
modelLocalNames["{{model|lookup:'modelId'}}"] = "{{model|lookup:'modelName'}}";
{% endfor %}
\ No newline at end of file
...@@ -9,6 +9,7 @@ urlpatterns = patterns('', ...@@ -9,6 +9,7 @@ urlpatterns = patterns('',
url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', 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+)/$', 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', 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'),
) )
\ No newline at end of file
...@@ -35,6 +35,12 @@ def models_detail(request, model_id): ...@@ -35,6 +35,12 @@ def models_detail(request, model_id):
context = {'model': model} context = {'model': model}
return render(request, 'models/detail.html', context) return render(request, 'models/detail.html', context)
def model_local_names_js(request):
models_local_names = Model.get_models_local_names()
#print models_local_names
context = {'models_local_names': models_local_names}
return render(request,'models/modelLocalNames.js', context, content_type="application/javascript;charset=UTF-8")
# Converting JSON results to Highcharts timeseries # Converting JSON results to Highcharts timeseries
def detail_highcharts_json(request, forecast_id): def detail_highcharts_json(request, forecast_id):
results_json = ForecastResult.get_forecast_results_as_json(forecast_id) results_json = ForecastResult.get_forecast_results_as_json(forecast_id)
......
from django.contrib import admin from django.contrib import admin
from messages.models import Message from messages.models import Message, MessageTag
admin.site.register(Message) class MessageAdmin(admin.ModelAdmin):
list_display = ['pub_date','headline','created_by']
list_filter = ['message_tags']
admin.site.register(Message, MessageAdmin)
admin.site.register(MessageTag)
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-01-16 15:31+0100\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/messages/index.html:3
#: templates/messages/index.html.py:5
msgid "Messages"
msgstr "Meldinger"
#: templates/messages/index.html:12
msgid "Publish date"
msgstr "Publiseringsdato"
#: templates/messages/index.html:13
msgid "Headline"
msgstr "Overskrift"
#: templates/messages/index.html:14
msgid "Author"
msgstr "Forfatter"
#: templates/messages/index.html:24
msgid "Details"
msgstr "Detaljer"
from django.db import models from django.db import models
from django.contrib.auth.models import User
from datetime import timedelta from datetime import timedelta
# Create your models here. # Create your models here.
class MessageTag(models.Model):
title = models.CharField(max_length=255)
def __unicode__(self):
return self.title
class Message(models.Model): class Message(models.Model):
headline = models.CharField(max_length=255) headline = models.CharField(max_length=255)
lead = models.TextField(blank=True) lead = models.TextField(blank=True)
body_text = models.TextField() body_text = models.TextField()
pub_date = models.DateField() pub_date = models.DateField()
mod_date = models.DateField()
valid_to_date = models.DateField(blank=True) # Default is 14 days after pub_date. See self.save valid_to_date = models.DateField(blank=True) # Default is 14 days after pub_date. See self.save
illustration = models.ImageField(upload_to='images/messages', blank=True) illustration = models.ImageField(upload_to='images/messages', blank=True)
created_by = models.ForeignKey(User, related_name='messages_message_created_by', editable=False)
modified_by = models.ForeignKey(User, related_name='messages_message_modified_by', editable=False)
created_date = models.DateTimeField(auto_now_add=True, editable=False)
modified_date = models.DateTimeField(auto_now=True, editable=False)
message_tags = models.ManyToManyField(MessageTag)
def __unicode__(self): def __unicode__(self):
return self.headline return self.headline
...@@ -19,4 +30,6 @@ class Message(models.Model): ...@@ -19,4 +30,6 @@ class Message(models.Model):
if self.valid_to_date == None: if self.valid_to_date == None:
self.valid_to_date = self.pub_date + timedelta(days=14) self.valid_to_date = self.pub_date + timedelta(days=14)
super(Message, self).save(*args, **kwargs) super(Message, self).save(*args, **kwargs)
\ No newline at end of file
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment