if start_date >= end_date:
self._errors["start_date"] = self.error_class(['Start date must be before end date.'])
return cleaned_data
+
+ def get_cmdext(self):
+ '''
+ Must not be called unless is_valid
+ 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':
+ command = u'show_targets_ships'
+ command += u' --format=track'
+ extension = u'kmz'
+
+ elif format == u'animation':
+ command = u'show_targets_ships'
+ command += u' --format=animation'
+ extension = u'kmz'
+
+ elif format == u'csv':
+ command = u'common'
+ extension = u'csv'
+ else:
+ raise Http404(u'Invalid archive format')
+
+ command += u' --start=\'' + date_start.strftime('%Y%m%d') + u'\''
+ if date_end:
+ command += u' --end=\'' + date_end.strftime('%Y%m%d') + u'\''
+
+ grain = data['grain']
+ command += u' --granularity=' + unicode(grain)
+
+ return command, extension
@http_authenticate(auth, 'ais')
def vessel(request, strmmsi):
def clean_latitude(self):
data = self.cleaned_data['latitude']
- data = data.replace(u"''", u'"') # commong mistake
+ data = data.replace(u"''", u'"') # common mistake
data = data.replace(u' ', u'') # remove spaces
sides = u'SN'
if not data:
def clean_longitude(self):
data = self.cleaned_data['longitude']
- data = data.replace(u"''", u'"') # commong mistake
+ data = data.replace(u"''", u'"') # common mistake
data = data.replace(u' ', u'') # remove spaces
sides = u'WE'
if not data:
if request.method == 'POST':
form = HistoryForm(request.POST, initial=initial)
if form.is_valid():
- data = form.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':
- command = u'show_targets_ships'
- command += u' --format=track'
- extension = u'kmz'
-
- elif format == u'animation':
- command = u'show_targets_ships'
- command += u' --format=animation'
- extension = u'kmz'
-
- elif format == u'csv':
- command = u'common'
- extension = u'csv'
- else:
- raise Http404(u'Invalid archive format')
-
- command += u' --start=\'' + date_start.strftime('%Y%m%d %H%M%S') + u'\''
- if date_end:
- command += u' --end=\'' + date_end.strftime('%Y%m%d %H%M%S') + u'\''
-
- grain = data['grain']
- command += u' --granularity=' + unicode(grain)
+ command, extension = form.get_cmdext()
command += u' ' + strmmsi
response['Content-Disposition'] = 'attachment; filename=%s.kmz' % fleetname
return response
+@http_authenticate(auth, 'ais')
+def fleet_history(request, fleetname):
+ fleet = get_object_or_404(Fleet, name=fleetname)
+ if not FleetUser.objects.filter(fleet=fleet.id, user=request.user.id).all():
+ return HttpResponseForbidden('<h1>Forbidden</h1>')
+ initial = {}
+ if request.method == 'POST':
+ form = HistoryForm(request.POST, initial=initial)
+ if form.is_valid():
+ command, extension = form.get_cmdext()
+
+ command += u' @' + fleetname
+
+ job = Job()
+ job.friendly_filename = u'%s.%s' % (fleetname, extension)
+ job.user = request.user
+ job.command = command
+ job.save()
+ if not jobrunner.wakeup_daemon():
+ return HttpResponseServerError(jobrunner.DAEMON_WAKEUP_ERROR)
+ return HttpResponseRedirect('/job/%s/download' % job.id)
+ else: # GET
+ form = HistoryForm(initial=initial)
+ return render_to_response('fleet_history.html', {'fleet': fleet, 'form':form}, RequestContext(request))
+
@http_authenticate(auth, 'ais')
def jobs_index(request):