From bdb1cd8eac367761ee1ab3f10d57b186abcad28e Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@bioforsk.no>
Date: Fri, 26 Feb 2016 14:33:47 +0100
Subject: [PATCH] Added support for private forecasts

---
 VIPSWeb/static/js/frontpage.js            |  40 ++++++++++++++++++----
 VIPSWeb/templates/base.html               |   1 +
 VIPSWeb/templates/index.html              |   1 +
 VIPSWeb/templates/settings.js             |   4 ++-
 forecasts/locale/bg/LC_MESSAGES/django.mo | Bin 1470 -> 1470 bytes
 forecasts/locale/bg/LC_MESSAGES/django.po |  36 +++++++++++--------
 forecasts/locale/bs/LC_MESSAGES/django.mo | Bin 1518 -> 1518 bytes
 forecasts/locale/bs/LC_MESSAGES/django.po |  36 +++++++++++--------
 forecasts/locale/nb/LC_MESSAGES/django.mo | Bin 2079 -> 2129 bytes
 forecasts/locale/nb/LC_MESSAGES/django.po |  30 +++++++++++-----
 forecasts/models.py                       |  39 +++++++++++++++------
 forecasts/templates/forecasts/index.html  |  36 ++++++++++++++++++-
 forecasts/views.py                        |  11 +++---
 security/views.py                         |   1 +
 14 files changed, 176 insertions(+), 59 deletions(-)

diff --git a/VIPSWeb/static/js/frontpage.js b/VIPSWeb/static/js/frontpage.js
index 441420b3..487cd4de 100644
--- a/VIPSWeb/static/js/frontpage.js
+++ b/VIPSWeb/static/js/frontpage.js
@@ -248,7 +248,7 @@ function renderMyForecastConfigurationSummaries()
 	var myForecastSummariesTable = document.getElementById("myForecastSummariesTable");
 	var myForecastSummariesContainer = document.getElementById("myForecastSummariesContainer");
 	//console.log(myForecastConfigurationIds);	
-	if(myForecastConfigurationIds.length == 0)
+	if(myForecastConfigurationIds.length == 0 && cachedPrivateForecastSummaries.length == 0)
 	{
 		$(myForecastSummariesContainer).hide(1000);
 		myForecastSummariesTable.innerHTML = "";
@@ -258,6 +258,13 @@ function renderMyForecastConfigurationSummaries()
 	var myForecastConfigurations = [];
 	
 	//console.log(myForecastConfigurationIds );
+	for(var i in cachedPrivateForecastSummaries)
+	{
+		var forecastConfiguration = cachedPrivateForecastSummaries[i];
+		//console.log(forecastConfiguration.forecastConfigurationId);
+		myForecastConfigurations.push(forecastConfiguration);
+	}
+	
 	for(var i in cachedForecastSummaries)
 	{
 		var forecastConfiguration = cachedForecastSummaries[i];
@@ -276,7 +283,7 @@ function renderMyForecastConfigurationSummaries()
 		return;
 	}
 	
-	//console.log(myForecastConfigurations);
+	console.log(myForecastConfigurations);
 	
 	var mySummariesHTML = getforecastSummariesTableHTML(myForecastConfigurations,false, true);
 	myForecastSummariesTable.innerHTML = mySummariesHTML;
@@ -319,7 +326,14 @@ function getforecastSummariesTableHTML(forecastConfigurations, excludePoiName, i
 		summariesHTML.push(", " + getLocalizedOrganismName(forecastConfiguration.pestOrganismId));
 		summariesHTML.push(", <a href='/forecasts/models/" + forecastConfiguration.modelId + "' target='new'>" + modelLocalNames[forecastConfiguration.modelId] + "</a>");
 		//summariesHTML.push(" <button type=\"button\" onclick='" + (isFavouritesList ? "removeFrom" : "addTo") + "MyForecastConfigurations(" + forecastConfiguration.forecastConfigurationId + ");'><img src='/static/css/icons/" + (isFavouritesList ? "remove_from" : "add_to") + "_favourites.png' alt='" + (isFavouritesList ? gettext("Remove from my favourites") : gettext("Add to my favourites")) + "'/></button>");
-		summariesHTML.push(" <span onclick='" + (isFavouritesList ? "removeFrom" : "addTo") + "MyForecastConfigurations(" + forecastConfiguration.forecastConfigurationId + ");' class=\"" + (isFavouritesList ? "fa fa-minus-circle favouriteToggle" : "fa fa-star favouriteToggle") + "\"></span>")
+		if(!forecastConfiguration.isPrivate)
+		{
+			summariesHTML.push(" <span onclick='" + (isFavouritesList ? "removeFrom" : "addTo") + "MyForecastConfigurations(" + forecastConfiguration.forecastConfigurationId + ");' class=\"" + (isFavouritesList ? "fa fa-minus-circle favouriteToggle" : "fa fa-star favouriteToggle") + "\"></span>")
+		}
+		else
+		{
+			summariesHTML.push(" <span title='Private' class='fa fa-lock'></span>");
+		}
 		summariesHTML.push("</td></tr>");
 		
 		// Get correct list of summaries
@@ -479,7 +493,9 @@ function refreshForecasts()
 }
 
 // The globally available caching of forecast summaries
-var cachedForecastSummaries;
+var cachedForecastSummaries = [];
+// The globally available caching of private forecast summaries
+var cachedPrivateForecastSummaries = [];
 //The globally available caching of poi info
 var cachedPois;
 
@@ -491,12 +507,24 @@ function cacheForecastSummaries()
 {
 	$.getJSON( "http://" + settings.vipslogicServerName + "/rest/forecastconfigurationsummaries/" + settings.vipsOrganizationId, function( json ) {
 		  cachedForecastSummaries = json;
-		  updateForecastSummariesHeading(cachedForecastSummaries.length);
-		  updateForecastSummaries();
+		  cachePrivateForecastSummaries();
+		  
 		  });
 	
 }
 
+/**
+ * If user is logged in, this function fetches the private forecast summaries, if any
+ */
+function cachePrivateForecastSummaries()
+{
+	$.getJSON( "http://" + settings.vipslogicServerName + "/rest/forecastconfigurationsummaries/private/" + settings.userUuid , function( json ) {
+		cachedPrivateForecastSummaries = json;
+		updateForecastSummariesHeading(cachedForecastSummaries.length);
+		 updateForecastSummaries();
+	});
+}
+
 /**
  * Collects and caches points of interest
  */
diff --git a/VIPSWeb/templates/base.html b/VIPSWeb/templates/base.html
index 8b16ca75..823e99f1 100644
--- a/VIPSWeb/templates/base.html
+++ b/VIPSWeb/templates/base.html
@@ -147,6 +147,7 @@
 	<script type="text/javascript" src="{% static "security/js/crossdomainstorage.js" %}"></script>
 	<script src="{% static "security/js/loginHandler.js" %}"></script>
 	<script type="text/javascript">
+	
 	$(document).ready(function() {
 		var remoteStorage = new CrossDomainStorage("http://{{settings.VIPSLOGIC_SERVER_NAME}}", "/xdomain/xdomainserver.jsp");
 		remoteStorage.requestCookie("rememberedUser", function(name, value){
diff --git a/VIPSWeb/templates/index.html b/VIPSWeb/templates/index.html
index df89f89f..337bf374 100644
--- a/VIPSWeb/templates/index.html
+++ b/VIPSWeb/templates/index.html
@@ -53,6 +53,7 @@
 		restoreSelectedCropIds();
 		cacheMessages();
 		cacheObservations();
+		cachePrivateForecastSummaries();
 		// Collect all summaries of forecasts for this organization
 		cacheForecastSummaries();
 	});
diff --git a/VIPSWeb/templates/settings.js b/VIPSWeb/templates/settings.js
index f29a3873..87b2d20e 100644
--- a/VIPSWeb/templates/settings.js
+++ b/VIPSWeb/templates/settings.js
@@ -17,5 +17,7 @@ var settings = {
 		
 		systemTimeOffsetMonths: {{settings.SYSTEM_TIME_OFFSET_MONTHS}},
 		
-		frontpageMessageTagIds: {{settings.FRONTPAGE_MESSAGE_TAG_IDS}}
+		frontpageMessageTagIds: {{settings.FRONTPAGE_MESSAGE_TAG_IDS}},
+		
+		userUuid: {% if request.session.vips_logic_user == None %}null{% else %}"{{request.session.user_uuid}}"{% endif %}
 };
diff --git a/forecasts/locale/bg/LC_MESSAGES/django.mo b/forecasts/locale/bg/LC_MESSAGES/django.mo
index 36fb0d278c8ffcda1000b7ea6ec8af4c02da47fe..504d1207954e450e8ffdde7e41963e2dc8c00267 100644
GIT binary patch
delta 29
lcmdnTy^njt872WUT>~RsBQpg<6DuQgZ3Dy2cbFbA0RV%+2&4c2

delta 29
lcmdnTy^njt872W!T?0#9BSQs4Ln{+QZ3CmtcbFbA0RV%a2%i7|

diff --git a/forecasts/locale/bg/LC_MESSAGES/django.po b/forecasts/locale/bg/LC_MESSAGES/django.po
index 4a752f4f..d729573b 100644
--- a/forecasts/locale/bg/LC_MESSAGES/django.po
+++ b/forecasts/locale/bg/LC_MESSAGES/django.po
@@ -19,7 +19,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: VIPS BG\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-09-21 11:41+0200\n"
+"POT-Creation-Date: 2016-02-26 14:27+0100\n"
 "PO-Revision-Date: 2014-05-14 09:37+0200\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -40,10 +40,12 @@ msgid "Model"
 msgstr "Модел"
 
 #: templates/forecasts/detail.html:40 templates/forecasts/index.html:55
+#: templates/forecasts/index.html.py:76
 msgid "Location"
 msgstr "Място"
 
 #: templates/forecasts/detail.html:41 templates/forecasts/index.html:54
+#: templates/forecasts/index.html.py:75
 msgid "Weather station"
 msgstr "Климатична станция"
 
@@ -103,39 +105,45 @@ msgstr "Прогнози"
 msgid "Search"
 msgstr ""
 
-#: templates/forecasts/index.html:51
+#: templates/forecasts/index.html:51 templates/forecasts/index.html.py:72
 msgid "Crop"
 msgstr ""
 
-#: templates/forecasts/index.html:52
+#: templates/forecasts/index.html:52 templates/forecasts/index.html.py:73
 msgid "Pest"
 msgstr ""
 
-#: templates/forecasts/index.html:53
+#: templates/forecasts/index.html:53 templates/forecasts/index.html.py:74
 msgid "Model name"
 msgstr "Име на модела"
 
-#: templates/forecasts/index.html:56
+#: templates/forecasts/index.html:56 templates/forecasts/index.html.py:77
 msgid "Date start"
 msgstr "Начална дата"
 
-#: templates/forecasts/index.html:57
+#: templates/forecasts/index.html:57 templates/forecasts/index.html.py:78
 msgid "Date end"
 msgstr "Крайна дата"
 
-#: templates/forecasts/index.html:96
+#: templates/forecasts/index.html:67
+#, fuzzy
+#| msgid "Forecasts"
+msgid "Private forecasts"
+msgstr "Прогнози"
+
+#: templates/forecasts/index.html:92 templates/forecasts/index.html.py:130
 msgid "Results"
 msgstr "Резултати"
 
-#: templates/forecasts/index.html:112
+#: templates/forecasts/index.html:146
 msgid "Select crop"
 msgstr ""
 
-#: templates/forecasts/index.html:128
+#: templates/forecasts/index.html:162
 msgid "Select pest"
 msgstr ""
 
-#: templates/forecasts/index.html:144
+#: templates/forecasts/index.html:178
 msgid "Select model"
 msgstr ""
 
@@ -144,19 +152,19 @@ msgstr ""
 msgid "Models"
 msgstr "Модели"
 
-#: templates/models/detail.html:26
+#: templates/models/detail.html:28
 msgid "Description"
 msgstr "Описание"
 
-#: templates/models/detail.html:27
+#: templates/models/detail.html:29
 msgid "Interpretation of warning status"
 msgstr ""
 
-#: templates/models/detail.html:28
+#: templates/models/detail.html:30
 msgid "Technical usage"
 msgstr ""
 
-#: templates/models/detail.html:29
+#: templates/models/detail.html:31
 msgid "Sample configuration"
 msgstr "Конфигурация на пробата"
 
diff --git a/forecasts/locale/bs/LC_MESSAGES/django.mo b/forecasts/locale/bs/LC_MESSAGES/django.mo
index 08c3b94ffe8d78c4949535c8f17e424c68dd9de8..ccf4b3ed342bc48337b6bedd47ee3135c3b3739a 100644
GIT binary patch
delta 29
kcmaFI{f>KsCbNK<u7Q!Rk(q*_iItJLwt?YhOXjUi0DLV6lK=n!

delta 29
kcmaFI{f>KsCbNL4u7Rblk)eX2p_PfDwt>-ROXjUi0DKDvjsO4v

diff --git a/forecasts/locale/bs/LC_MESSAGES/django.po b/forecasts/locale/bs/LC_MESSAGES/django.po
index 3370bc67..338cf83a 100644
--- a/forecasts/locale/bs/LC_MESSAGES/django.po
+++ b/forecasts/locale/bs/LC_MESSAGES/django.po
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: VIPS\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-09-21 11:41+0200\n"
+"POT-Creation-Date: 2016-02-26 14:27+0100\n"
 "PO-Revision-Date: 2015-02-13 11:10+0100\n"
 "Last-Translator: Mladen Cucak <mladencucak@gmail.com>\n"
 "Language-Team: LANGUAGE <wvjeko@gmail.com>\n"
@@ -30,10 +30,12 @@ msgid "Model"
 msgstr "Model"
 
 #: templates/forecasts/detail.html:40 templates/forecasts/index.html:55
+#: templates/forecasts/index.html.py:76
 msgid "Location"
 msgstr "Lokacija"
 
 #: templates/forecasts/detail.html:41 templates/forecasts/index.html:54
+#: templates/forecasts/index.html.py:75
 msgid "Weather station"
 msgstr "Meteo stanica"
 
@@ -93,39 +95,45 @@ msgstr "Prognoze"
 msgid "Search"
 msgstr ""
 
-#: templates/forecasts/index.html:51
+#: templates/forecasts/index.html:51 templates/forecasts/index.html.py:72
 msgid "Crop"
 msgstr "Usjev"
 
-#: templates/forecasts/index.html:52
+#: templates/forecasts/index.html:52 templates/forecasts/index.html.py:73
 msgid "Pest"
 msgstr ""
 
-#: templates/forecasts/index.html:53
+#: templates/forecasts/index.html:53 templates/forecasts/index.html.py:74
 msgid "Model name"
 msgstr "Ime modela "
 
-#: templates/forecasts/index.html:56
+#: templates/forecasts/index.html:56 templates/forecasts/index.html.py:77
 msgid "Date start"
 msgstr "Datum početka"
 
-#: templates/forecasts/index.html:57
+#: templates/forecasts/index.html:57 templates/forecasts/index.html.py:78
 msgid "Date end"
 msgstr "Datum završetka "
 
-#: templates/forecasts/index.html:96
+#: templates/forecasts/index.html:67
+#, fuzzy
+#| msgid "Forecasts"
+msgid "Private forecasts"
+msgstr "Prognoze"
+
+#: templates/forecasts/index.html:92 templates/forecasts/index.html.py:130
 msgid "Results"
 msgstr "Rezultati "
 
-#: templates/forecasts/index.html:112
+#: templates/forecasts/index.html:146
 msgid "Select crop"
 msgstr ""
 
-#: templates/forecasts/index.html:128
+#: templates/forecasts/index.html:162
 msgid "Select pest"
 msgstr ""
 
-#: templates/forecasts/index.html:144
+#: templates/forecasts/index.html:178
 msgid "Select model"
 msgstr ""
 
@@ -134,19 +142,19 @@ msgstr ""
 msgid "Models"
 msgstr "Modeli"
 
-#: templates/models/detail.html:26
+#: templates/models/detail.html:28
 msgid "Description"
 msgstr "Opis"
 
-#: templates/models/detail.html:27
+#: templates/models/detail.html:29
 msgid "Interpretation of warning status"
 msgstr ""
 
-#: templates/models/detail.html:28
+#: templates/models/detail.html:30
 msgid "Technical usage"
 msgstr ""
 
-#: templates/models/detail.html:29
+#: templates/models/detail.html:31
 msgid "Sample configuration"
 msgstr "Primjer konfiguracije "
 
diff --git a/forecasts/locale/nb/LC_MESSAGES/django.mo b/forecasts/locale/nb/LC_MESSAGES/django.mo
index 1cbe1982c84867f243eb9b3ea30da82a07c2c55e..7490cf591d74a011971be1c0b40d1af2f97068dc 100644
GIT binary patch
delta 759
zcmbO)a8aQCo)F7a1_lNOB?blt83qOh9YzKQeFg>w8zzt_1H%s{1_m|;28N$Z3=AwF
zA!Y^!4h9AWR%QkUE(Qh$K4yrxBr^j8Hv<EM95Vw0I|BoQ7Bd5b2m=Fy5i<jW5Ca2)
zJCu%MW?<lCU|`5)W?)cYV5ny(hZ;D8nSp_ofq`Km)ZpdJ5Q{f4Lmajf%D)D+@Gdh0
zgCGL~!y~ALU!WHLVP;^kWME(rWP#}SW`Q^?h=qZHhk=114$9AFVPN26sApg(XJKIA
zXJBAxV}ZDA8Vdu190LQx0<Z!GhW$|ab1V!D*^CSf_gEkf^<slq5Woh}7Y?Np*&y=S
zY!HhJ*&rcS%f`SU2C|0@5+ZX!bUgzD!v;1;kR4`YV31&7U^vYN3EC%63*JNd-=GFD
zvNJF!GcYi4u|xFfu|s@j#t!j_Gdo0oFgpW-D9Fd`3=9qo3=Adgkf_?q4sqBnb_NDt
zP@ElOhXmy%sKgU?h)X}PLwv^0!N8yj3Q`V;Mdnc2g@b{Ck%56hmI0z(Zn7nlw5lQ~
zl`uf8mS=!C5ft#C)CKY$D6ADGS2C#^g3_EcC@nECFo-iSFbG3+!YC;i17tS?1B2w|
zi%g7+f&oRDWr-!J3TgR8smY1OCB>UBGTSf;nCTiA=^B|S7@AlanQI#uZkA<bVd8};
PE=w#b&e<%-&d3M=?p#J8

delta 710
zcmca8Fkhhlo)F7a1_lNOMFs{283qOh6-EXIeFg>w9VU<{1H%g@1_m|;28NeR3=Av`
z3=AKb7#KJh7#O}XF)(m3FfjasigPkEFmN+4Fz_)mFt9T)Fi0^oFo-ZPFeouIFbFX)
zFqlJWFJ=Y?P6h^sSY`$W1qOzChID3#fgQ{Y46F<c3=^3l22W>(SiFcC;;@xa{xN2V
zL(W1ix&*c87Bd5bB?AM)d#E~17KnokSQr?17#J9ApnOjj1_nL`28K`;1_pkHdIp9R
z7Kn>VSQr@O7#JAppbF-K6)-TYVPRm%W@KR4!vb-j1{=g-dTbDVrcm0R4I=N!2C>+m
z4dStAHU<VU1_p){Hb_WRL+L&?1_t(e1_p+OYzzz%3=9k_*&seY1hwESlz#<k(0w)r
z24w~Yh8G}>3=9lB>=2)cutW4IvNJG<f})O{fx&@+fx(F#5>n0V5C?TY=_%|C41x>{
z3=7y97;Hgtwuv3$!hP%zA6;c<U{GaXV7L#pfRzJckq`$110yt@fGm=o?8zjpssKqS
zU=kF5px6fmxHJO;gE#{ykQo@{CwDTb8-mi96ayrbKp`Rw)`K7<5lpZHB{n}~Vr1O>
ih1r@>z*N`3QrE~(!O+mk#8BJ7XtO;l3)AFa_J06_hB?gu

diff --git a/forecasts/locale/nb/LC_MESSAGES/django.po b/forecasts/locale/nb/LC_MESSAGES/django.po
index 2b529958..b38c7d03 100644
--- a/forecasts/locale/nb/LC_MESSAGES/django.po
+++ b/forecasts/locale/nb/LC_MESSAGES/django.po
@@ -21,7 +21,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-09-21 11:41+0200\n"
+"POT-Creation-Date: 2016-02-26 14:27+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"
@@ -43,11 +43,13 @@ msgstr "Modell"
 
 #: templates/forecasts/detail.html:40
 #: templates/forecasts/index.html:55
+#: templates/forecasts/index.html.py:76
 msgid "Location"
 msgstr "Plassering"
 
 #: templates/forecasts/detail.html:41
 #: templates/forecasts/index.html:54
+#: templates/forecasts/index.html.py:75
 msgid "Weather station"
 msgstr "Målestasjon"
 
@@ -109,38 +111,48 @@ msgid "Search"
 msgstr "Søk"
 
 #: templates/forecasts/index.html:51
+#: templates/forecasts/index.html.py:72
 msgid "Crop"
 msgstr "Kultur"
 
 #: templates/forecasts/index.html:52
+#: templates/forecasts/index.html.py:73
 msgid "Pest"
 msgstr "Skadegjører"
 
 #: templates/forecasts/index.html:53
+#: templates/forecasts/index.html.py:74
 msgid "Model name"
 msgstr "Modellnavn"
 
 #: templates/forecasts/index.html:56
+#: templates/forecasts/index.html.py:77
 msgid "Date start"
 msgstr "Startdato"
 
 #: templates/forecasts/index.html:57
+#: templates/forecasts/index.html.py:78
 msgid "Date end"
 msgstr "Sluttdato"
 
-#: templates/forecasts/index.html:96
+#: templates/forecasts/index.html:67
+msgid "Private forecasts"
+msgstr "Private varsler"
+
+#: templates/forecasts/index.html:92
+#: templates/forecasts/index.html.py:130
 msgid "Results"
 msgstr "Resultater"
 
-#: templates/forecasts/index.html:112
+#: templates/forecasts/index.html:146
 msgid "Select crop"
 msgstr "Velg kultur"
 
-#: templates/forecasts/index.html:128
+#: templates/forecasts/index.html:162
 msgid "Select pest"
 msgstr "Velg skadegjører"
 
-#: templates/forecasts/index.html:144
+#: templates/forecasts/index.html:178
 msgid "Select model"
 msgstr "Velg modell"
 
@@ -150,19 +162,19 @@ msgstr "Velg modell"
 msgid "Models"
 msgstr "Modeller"
 
-#: templates/models/detail.html:26
+#: templates/models/detail.html:28
 msgid "Description"
 msgstr "Beskrivelse"
 
-#: templates/models/detail.html:27
+#: templates/models/detail.html:29
 msgid "Interpretation of warning status"
 msgstr "Tolkning av varselstatus"
 
-#: templates/models/detail.html:28
+#: templates/models/detail.html:30
 msgid "Technical usage"
 msgstr "Teknisk bruksanvisning"
 
-#: templates/models/detail.html:29
+#: templates/models/detail.html:31
 msgid "Sample configuration"
 msgstr "Eksempelkonfigurasjon"
 
diff --git a/forecasts/models.py b/forecasts/models.py
index ad7b6011..f006666b 100644
--- a/forecasts/models.py
+++ b/forecasts/models.py
@@ -49,15 +49,18 @@ class ForecastResult:
     Currently this is a REST service
     """
     @staticmethod
-    def get_forecast_results(forecast_configuration_id, latest_days=30):
+    def get_forecast_results(forecast_configuration_id, user_uuid, latest_days=30):
         forecastResults = []
-        for item in ForecastResult.get_forecast_results_as_json(forecast_configuration_id, latest_days):
+        for item in ForecastResult.get_forecast_results_as_json(forecast_configuration_id, user_uuid, latest_days):
             forecastResults.append(ForecastResult.get_instance_from_dict(item))
         return forecastResults
     
     @staticmethod
-    def get_forecast_results_as_json(forecast_configuration_id, latest_days=30):
-        requestResult = requests.get("http://%s/rest/forecastresults/%s/%s" % (settings.VIPSLOGIC_SERVER_NAME,forecast_configuration_id, latest_days))
+    def get_forecast_results_as_json(forecast_configuration_id, user_uuid, latest_days=30):
+        auth_param = ""
+        if user_uuid != None:
+            auth_param = "?userUUID=%s" % user_uuid
+        requestResult = requests.get("http://%s/rest/forecastresults/%s/%s%s" % (settings.VIPSLOGIC_SERVER_NAME,forecast_configuration_id, latest_days, auth_param))
         return requestResult.json()
     
     @staticmethod
@@ -102,11 +105,11 @@ class ForecastResult:
         return plot_bands
 
     @staticmethod
-    def get_forecast_results_highcharts(forecast_results, forecast_id):
+    def get_forecast_results_highcharts(forecast_results, forecast_id, user_uuid):
         
         # We must narrow this down to only the most important ones
         # First: Get modelId
-        forecast_configuration = ForecastConfiguration.get_forecast_configuration(forecast_id)
+        forecast_configuration = ForecastConfiguration.get_forecast_configuration(forecast_id, user_uuid)
         if forecast_configuration == None:
             return None
         #print "Result 2: %s seconds from start" % (time.time() - start) 
@@ -227,8 +230,20 @@ class ForecastConfiguration:
         return request_result
     
     @staticmethod
-    def get_forecast_configuration(forecast_configuration_id):
-        forecast_configuration = ForecastConfiguration.get_instance_from_dict(ForecastConfiguration.get_forecast_configuration_as_json(forecast_configuration_id))
+    def get_private_forecast_configurations(user_uuid):
+        if user_uuid == None:
+            return []
+        forecasts = []
+        request_result = requests.get("http://%s/rest/forecastconfigurations/private/%s" % (settings.VIPSLOGIC_SERVER_NAME, user_uuid))
+        if request_result.status_code != 200:
+            return None
+        for item in request_result.json():
+            forecasts.append(ForecastConfiguration.get_instance_from_dict(item))
+        return forecasts
+    
+    @staticmethod
+    def get_forecast_configuration(forecast_configuration_id, user_uuid):
+        forecast_configuration = ForecastConfiguration.get_instance_from_dict(ForecastConfiguration.get_forecast_configuration_as_json(forecast_configuration_id, user_uuid))
         if forecast_configuration == None:
             return None
         forecast_configuration.set_model_local_name(Model.get_local_name_for_model(forecast_configuration.model_id))
@@ -236,8 +251,11 @@ class ForecastConfiguration:
         return forecast_configuration
         
     @staticmethod
-    def get_forecast_configuration_as_json(forecast_configuration_id):
-        requestResult = requests.get("http://%s/rest/forecastconfigurations/%s" % (settings.VIPSLOGIC_SERVER_NAME, forecast_configuration_id))
+    def get_forecast_configuration_as_json(forecast_configuration_id, user_uuid):
+        auth_param = ""
+        if user_uuid != None:
+            auth_param = "?userUUID=%s" % user_uuid
+        requestResult = requests.get("http://%s/rest/forecastconfigurations/%s%s" % (settings.VIPSLOGIC_SERVER_NAME, forecast_configuration_id, auth_param))
         try:
             return requestResult.json()
         except ValueError:
@@ -290,6 +308,7 @@ class ForecastConfiguration:
                                          Organism.get_instance_from_dict(theDict.get("cropOrganismId", None)),
                                          Organism.get_instance_from_dict(theDict.get("pestOrganismId", None))
                                          )
+        instance.set_model_local_name(Model.get_local_name_for_model(instance.model_id))
         return instance
 """
 A geographical point. Could be i.e. a weatherstation or a field. Fetched from VIPSLogic backend (REST)
diff --git a/forecasts/templates/forecasts/index.html b/forecasts/templates/forecasts/index.html
index ef4a4a77..c5994e82 100644
--- a/forecasts/templates/forecasts/index.html
+++ b/forecasts/templates/forecasts/index.html
@@ -3,7 +3,7 @@
 {% comment %}
 
 #
-# Copyright (c) 2014 NIBIO <http://www.nibio.no/>. 
+# 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
@@ -63,6 +63,40 @@
 		</tbody>
 	</table>
 </div>
+{% if private_forecast_configurations != None %}
+<h2>{% trans "Private forecasts" %}</h2>
+<div class="table-responsive">
+	<table class="table">
+		<thead>
+			<tr>
+				<th>{% trans "Crop" %}</th>
+				<th>{% trans "Pest" %}</th>
+				<th>{% trans "Model name" %}</th>
+				<th>{% trans "Weather station" %}</th>
+				<th>{% trans "Location" %}</th>
+				<th>{% trans "Date start" %}</th>
+				<th>{% trans "Date end" %}</th>
+				<th></th>
+			</tr> 
+		</thead>
+		<tbody>
+			{% for forecast_configuration in private_forecast_configurations %}
+			<tr>
+				<td>{{ forecast_configuration.crop_organism.local_name }}</td>
+				<td>{{ forecast_configuration.pest_organism.local_name }}</td>
+				<td><a href="/forecasts/models/{{forecast_configuration.model_id}}">{{ forecast_configuration.model_local_name }}</a></td>
+				<td>{{ forecast_configuration.weather_station_point_of_interest.name }}</td>
+				<td>{{ forecast_configuration.location_point_of_interest.name }}</td>
+				<td>{{ forecast_configuration.date_start }}</td>
+				<td>{{ forecast_configuration.date_end }}</td>
+				<td><a href="{% url 'forecasts:detail' forecast_configuration.forecast_configuration_id %}">{% trans "Results" %}</a></td>
+			</tr>
+			{% endfor %}
+		</tbody>
+	</table>
+</div>
+{% endif %}
+
 {% endblock %}
 {% block customJS %}
 <script type="text/javascript" src="{% static "js/3rdparty/moment.min.js" %}"></script>
diff --git a/forecasts/views.py b/forecasts/views.py
index 5a63777d..3a679890 100644
--- a/forecasts/views.py
+++ b/forecasts/views.py
@@ -25,22 +25,25 @@ from forecasts.models import ForecastConfiguration, ForecastResult, ResultParame
 
 def index(request):
     forecast_configurations = ForecastConfiguration.get_forecast_configurations_from_vipslogic(None).text
+    private_forecast_configurations = None
+    if request.session.get("user_uuid",None) != None:
+        private_forecast_configurations = ForecastConfiguration.get_private_forecast_configurations(request.session["user_uuid"])
     #forecast_configurations.sort(key=lambda x: x.date_start, reverse=False)
     context = {
                'forecast_configurations': forecast_configurations,
+               'private_forecast_configurations': private_forecast_configurations,
                'models_local_names' : Model.get_models_local_names().text
                }
     return render(request, 'forecasts/index.html', context)
 
 def detail_latest_days(request, forecast_id, latest_days):
-    
-    forecast_configuration = ForecastConfiguration.get_forecast_configuration(forecast_id)
+    forecast_configuration = ForecastConfiguration.get_forecast_configuration(forecast_id, request.session.get("user_uuid",None))
     if forecast_configuration == None:
         return render(request, 'forecasts/detail_error.html')
     #start = time.time()
-    forecast_results = ForecastResult.get_forecast_results(forecast_id, latest_days)
+    forecast_results = ForecastResult.get_forecast_results(forecast_id, request.session.get("user_uuid",None), latest_days)
     #forecast_results = forecast_results[0:1500]
-    forecast_result_highcharts = ForecastResult.get_forecast_results_highcharts(forecast_results, forecast_id)
+    forecast_result_highcharts = ForecastResult.get_forecast_results_highcharts(forecast_results, forecast_id, request.session.get("user_uuid",None))
     forecast_warning_statuses_highcharts = ForecastResult.get_forecast_warning_statuses_highcharts(forecast_results)
     #print "Result: %s seconds" % (time.time() - start) 
     result_parameters = None
diff --git a/security/views.py b/security/views.py
index b1d9fedf..eeb11ca8 100644
--- a/security/views.py
+++ b/security/views.py
@@ -30,6 +30,7 @@ def login_user_uuid(request, user_uuid):
     found_user = VipsLogicUser.find_by_uuid(user_uuid)
     if found_user != None:
         request.session["vips_logic_user"] = found_user
+        request.session["user_uuid"] = user_uuid
         request.session.set_expiry(0)
         return JsonResponse({"success":"true"})
     else:
-- 
GitLab