Slightly improved vessel history download form
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 7 Nov 2010 17:36:23 +0000 (17:36 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 7 Nov 2010 17:36:23 +0000 (17:36 +0000)
bin/djais/views.py
html_templates/vessel.html

index 0e37e408da8bfe4c38c6c664e77ffde486d75138..6e070dc3f9b73995d81e31e40d0c3a718c1fccbe 100644 (file)
@@ -364,19 +364,43 @@ def vessel_manual_input(request, strmmsi):
 
 @http_authenticate(auth, 'ais')
 def vessel_history(request, strmmsi, format=None):
-    ndays = request.REQUEST.get('ndays', 90)
+    """
+    That view is called from Google Earth, so that it must support GET method.  
+    """
+    ndays = request.REQUEST.get('ndays', None)
+    if ndays is not None:
+        try:
+            ndays = int(ndays)
+        except ValueError:
+            ndays = 90
+        period = ndays * 86400
+    else:
+        period = request.REQUEST.get('period', u'1')
+        try:
+            period = int(period)
+        except ValueError:
+            period = 1
+        period_type = request.REQUEST.get('period_type', u'86400')
+        try:
+            period_type = int(period_type)
+        except ValueError:
+            period_type = 86400
+
+    grain = request.REQUEST.get('grain', 1)
     try:
-        ndays = int(ndays)
+        grain = int(grain)
     except ValueError:
-        ndays = 90
-    grain = request.REQUEST.get('grain', 3600)
+        grain = 1
+    grain_type = request.REQUEST.get('grain_type', 3600)
     try:
-        grain = int(grain)
+        grain_type = int(grain_type)
     except ValueError:
-        grain = 3600
+        grain_type = 3600
+
     date_end = datetime.utcnow()
-    date_start = date_end - timedelta(ndays)
-    nmea_iterator = NmeaFeeder(strmmsi, date_end, date_start, granularity=grain)
+    date_start = date_end - timedelta(0,period*period_type)
+    print date_start
+    nmea_iterator = NmeaFeeder(strmmsi, date_end, date_start, granularity=grain*grain_type)
     
     if format is None:
         format = request.REQUEST.get('format', u'track')
index 40f232a0638517ba77386007d33cc6dad30f9792..94c97fbb096968f87dd192c7ea256de30e72b2bf 100644 (file)
@@ -44,9 +44,23 @@ Format: <select name=format onchange="if (this.value=='csv') $('#csvhint').show(
 <option value=animation>Animation (Google Earth)</option>
 <option value=csv>Coma separated values (SpreadSheet)</option>
 </select><br>
-Last <input name=ndays size=3 value=7> days <br>
-Definition <input name=grain size=4 value=3600> seconds<br>
-<span id=csvhint style="display:none;">Make sure you select "Charset: UTF-8" and "Separated by: Comma" when you <a href="/oocalc_howto.png">choose import options</a>.<br></span>
+
+For the last <input name=period size=3 value=7><select name=period_type>
+<option value=3600>hour(s)</option>
+<option value=86400 selected>day(s)</option>
+<option value=2592000>month(es)</option>
+</select>
+<br>
+One position every <input name=grain size=3 value=1><select name=grain_type>
+<option value=1>second(s)</option>
+<option value=60>minute(s)</option>
+<option value=3600 selected>hour(s)</option>
+<option value=86400>day(s)</option>
+</select>
+<br>
+<span id=csvhint style="display:none;">Make sure you select "Charset: UTF-8" and "Separated by: Coma" when you <a href="/oocalc_howto.png">choose import options</a>.<br></span>
 <input type=submit value=Get>
 </form>
+
+
 {% endblock %}