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 ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
......@@ -113,6 +113,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'common.middleware.whodid.WhodidMiddleware'
#'django.middleware.locale.LocaleMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
......
......@@ -43,12 +43,19 @@ div.messages_illustration{
height: 400px;
}
#tooltip, #popover {
#tooltip{
position: absolute;
height: 1px;
width: 1px;
z-index: 100;
}
div.popover {
min-width: 250px;
max-width: 400px !important;
}
/*
.tooltip.in {
opacity: 1;
......
......@@ -124,7 +124,7 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname)
top: (pixel[1] - 15) + 'px'
});
*/
popOverlay.setPosition(coordinate);
popOverlay.setPosition(coordinate);
map.getFeatures({
pixel: pixel,
layers: [forecastLayer],
......@@ -162,15 +162,18 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname)
}
//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)
{
resultHTML.push(gettext("No forecasts found for") + " " + feature.get("name"));
}
// Testing
//resultHTML = ["Mange små ord mange små ord Få ord"];
poiDetails.popover({
animation: false,
animation: true,
trigger: 'manual',
html: true,
placement: "auto top",
......
This diff is collapsed.
......@@ -55,7 +55,7 @@
<ul class="nav navbar-nav">
<li><a href="/forecasts">{% trans "Forecasts" %}</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>
<ul class="dropdown-menu">
<li><a href="#">{% trans "Action" %}</a></li>
......@@ -64,7 +64,7 @@
<li><a href="#">{% trans "Separated link" %}</a></li>
<li><a href="#">{% trans "One more separated link" %}</a></li>
</ul>
</li>
</li-->
</ul>
</div><!-- /.navbar-collapse -->
......
......@@ -18,15 +18,17 @@
along with VIPSWeb. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
{% load i18n l10n staticfiles %}
{% load i18n l10n staticfiles forecast_extras %}
{% block title%}{% trans "Welcome" %}{%endblock%}
{% block customCSS %}
<link rel="stylesheet" href="http://ol3js.org/en/master/build/ol.css" type="text/css">
{% endblock %}
{% block customJS %}
<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 src="{% static "js/forecastmap.js" %}"></script>
<script type="text/javascript" src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></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">
$(document).ready(function() {
// Init frontpage map. Depending on forecastmap.js.
......@@ -38,20 +40,32 @@
{% block content %}
<div class="row">
<!-- Start map container -->
<div class="col-md-9">
<div class="col-md-8">
<div id="map" class="map">
<!-- Info window box -->
<div id="tooltip"></div>
<div id="popover"></div>
</div>
</div><!-- End map container -->
<div class="col-md-3">
<div class="col-md-4">
<h1>{% trans "Messages" %}</h1>
<ul>
{% for message in messages %}
<li><a href="{% url 'messages:detail' message.id %}">{{message.headline}}</a></li>
{% endfor %}
</ul>
<table class="table table-hover table-condensed table-striped">
{% for message_tag in message_tags %}
<thead>
<tr>
<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><!-- End row with sidebar and contents container -->
{% endblock %}
\ No newline at end of file
from django.shortcuts import render
from messages.models import Message
from django.conf import settings
from messages.models import Message, MessageTag
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
messages = Message.objects.order_by('pub_date').reverse()[:10]
context = {
'messages' : messages,
'message_tags': message_tags,
'messages_by_tag': messages_by_tag
}
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:
@staticmethod
def get_model(model_id):
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
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
return Model(model_id,name, description, usage,sample_config)
return Model(model_id,local_name, description, usage,sample_config)
@staticmethod
def get_local_name_for_model(model_id):
cur_language = translation.get_language()
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
"""
......
{% extends "base.html" %}
{% load i18n %}
{% block title%}{{model_name}} - {% trans "Models" %}{%endblock%}
{% block title%}{{model.local_name}} - {% trans "Models" %}{%endblock%}
{% block content %}
<h1>{{model_name}}</h1>
<h1>{{model.local_name}}</h1>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#modelDescription">{% trans "Description" %}</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('',
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'^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'),
)
\ No newline at end of file
......@@ -35,6 +35,12 @@ def models_detail(request, model_id):
context = {'model': model}
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
def detail_highcharts_json(request, forecast_id):
results_json = ForecastResult.get_forecast_results_as_json(forecast_id)
......
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.contrib.auth.models import User
from datetime import timedelta
# Create your models here.
class MessageTag(models.Model):
title = models.CharField(max_length=255)
def __unicode__(self):
return self.title
class Message(models.Model):
headline = models.CharField(max_length=255)
lead = models.TextField(blank=True)
body_text = models.TextField()
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
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):
return self.headline
......@@ -19,4 +30,6 @@ class Message(models.Model):
if self.valid_to_date == None:
self.valid_to_date = self.pub_date + timedelta(days=14)
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