HistoryForm provide genuine support for --duration argument, drop of --start --end...
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 17 Apr 2011 08:52:53 +0000 (08:52 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 17 Apr 2011 08:52:53 +0000 (08:52 +0000)
bin/djais/views.py

index 613e95cfdf0a1e67f3c23f0f1787310748308326..47b6b6be1b7b8641e0baabf4bbf2afd02dde098d 100644 (file)
@@ -197,14 +197,7 @@ class HistoryForm(forms.Form):
         cleaned_data = self.cleaned_data
         period_type = self.cleaned_data.get('period_type', None)
         start_date = self.cleaned_data.get('start_date', None)
-        #duration = self.cleaned_data.get('duration', None)
         end_date = self.cleaned_data.get('end_date', None)
-        #if period_type in (u'date_date', u'start_duration') and start_date is None:
-        #    self._errors["start_date"] = self.error_class(['That field is required.'])
-        #if period_type in (u'duration', u'start_duration') and duration is None:
-        #    self._errors["duration"] = self.error_class(['That field is required.'])
-        #if period_type in (u'date_date',) and end_date is None:
-        #    self._errors["end_date"] = self.error_class(['That field is required.'])
         if period_type == u'date_date' and start_date is not None and end_date is not None:
             if start_date >= end_date:
                 self._errors["start_date"] = self.error_class(['Start date must be before end date.'])
@@ -216,17 +209,6 @@ class HistoryForm(forms.Form):
         Returns (command, extension)
         '''
         data = self.cleaned_data
-        if data['period_type'] == 'duration':
-            date_start = datetime.utcnow() - timedelta(0, data['duration'])
-            date_end = None # Now
-        elif data['period_type'] == 'date_date':
-            date_start = data['start_date']
-            date_end = data['end_date']
-        else:
-            assert data['period_type'] == 'start_duration', ('Invalid period type %s' % data['period_type'])
-            date_start = data['start_date']
-            date_end = date_start + timedelta(0, data['duration'])
-
         format = data['format']
 
         if format == u'track':
@@ -244,16 +226,25 @@ class HistoryForm(forms.Form):
             extension = u'csv'
         else:
             raise Http404(u'Invalid archive format')
-        
-        command += u' --start=\'' + date_start.strftime('%Y%m%d') + u'\''
+       
+        date_start = data.get('start_date', None)
+        if date_start:
+            command += u' --start \'' + date_start.strftime('%Y%m%d') + u'\''
+
+        date_end = data.get('end_date', None)
         if date_end:
-            command += u' --end=\'' + date_end.strftime('%Y%m%d') + u'\''
-        
+            command += u' --end \'' + date_end.strftime('%Y%m%d') + u'\''
+
+        duration = data.get('duration', None)
+        if duration:
+            command += u' --duration \'' + unicode(duration) + u'\''
+
         grain = data['grain']
-        command += u' --granularity=' + unicode(grain)
+        command += u' --granularity ' + unicode(grain)
 
         return command, extension
 
+
 @http_authenticate(auth, 'ais')
 def vessel(request, strmmsi):
     mmsi = strmmsi_to_mmsi(strmmsi)