Allow removal from a vessel from a fleet.
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 22 Oct 2011 15:48:00 +0000 (15:48 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 22 Oct 2011 15:48:00 +0000 (15:48 +0000)
bin/djais/urls.py
bin/djais/views.py
www_templates/fleet_vessels.html

index 4adf8a9056833fe904adaa8ae41609040e314594..31191178a26299fcfd638d0b28d6d0033ff89fbd 100644 (file)
@@ -15,6 +15,7 @@ urlpatterns = patterns('',
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/list$', 'ais.djais.views.fleet_vessels'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/add$', 'ais.djais.views.fleet_vessel_add'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/add_vessel$', 'ais.djais.views.fleet_vessel_add2'),
+    (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/remove_vessel$', 'ais.djais.views.fleet_vessel_remove'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/users$', 'ais.djais.views.fleet_users'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/lastpos$', 'ais.djais.views.fleet_lastpos'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/history$', 'ais.djais.views.fleet_history'),
index 4c8307c73954336efd92d50f3b35ef21b2dad2cb..59716d1fa233feefe4d5fd8fe6209ec84a27085f 100644 (file)
@@ -793,6 +793,27 @@ def fleet_vessel_add2(request, fleetname):
     return render_to_response('fleet_vessel_add.html', {'form': form, 'fleet': fleet}, RequestContext(request))
 
 
+@http_authenticate(auth, 'ais')
+def fleet_vessel_remove(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>')
+    strmmsi = request.REQUEST['mmsi']
+    mmsi = strmmsi_to_mmsi(strmmsi)
+    try:
+        vessel = Vessel.objects.get(pk=mmsi)
+    except Vessel.DoesNotExist:
+        request.user.error('No such vessel')
+    else:
+        try:
+            fv = FleetVessel.objects.get(fleet=fleet, vessel=vessel)
+            fv.delete()
+            request.user.info(u'Vessel %s removed from fleet %s.' % (vessel.name, fleetname))
+        except FleetVessel.DoesNotExist:
+            request.user.error(u'Vessel %s is not in fleet %s.' % (vessel.name, fleetname))
+    return HttpResponseRedirect('/fleet/%s/list' % fleetname)
+
+
 @http_authenticate(auth, 'ais')
 def fleet_users(request, fleetname):
     fleet = get_object_or_404(Fleet, name=fleetname)
index 7160acbaca9e6ca210138399e68cfe4eccf985e4..8fe9965c530284b03d5b7fa40c1720e935ef1352 100644 (file)
@@ -31,6 +31,7 @@ Fleet {{ fleet.name }} vessels
   <td>{{ nmea.get_callsign }}
   <td>{{ nmea.get_shiptype }}
   <td>{{ nmea.get_last_updated_delta_str }}
+  <td><a href='remove_vessel?mmsi={{nmea.strmmsi}}'>remove from fleet</a>
 {% endwith %}
 {% endfor %}
 </table>