From bff3eb442f7b0b088405d63423fc0853e49eb1e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Michel=20Nirgal=20Vourg=C3=A8re?= Date: Sun, 17 Apr 2011 08:52:53 +0000 Subject: [PATCH] HistoryForm provide genuine support for --duration argument, drop of --start --end conversion --- bin/djais/views.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/bin/djais/views.py b/bin/djais/views.py index 613e95c..47b6b6b 100644 --- a/bin/djais/views.py +++ b/bin/djais/views.py @@ -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) -- 2.30.2