Added a form to change a fleet description
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 7 Aug 2010 14:24:15 +0000 (14:24 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 7 Aug 2010 14:24:15 +0000 (14:24 +0000)
bin/djais/urls.py
bin/djais/views.py
html_templates/fleet.html
html_templates/fleet_edit.html [new file with mode: 0644]

index 662a41d6b03d793f7f0bfb98dcf2df7d6b3afbe7..e4329a657152a61f0d303037b858a5d78d49e31a 100644 (file)
@@ -9,6 +9,7 @@ urlpatterns = patterns('',
     (r'^$', 'ais.djais.views.index'),
     (r'^fleet/$', 'ais.djais.views.fleets'),
     (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/$', 'ais.djais.views.fleet'),
+    (r'^fleet/(?P<fleetname>[ a-zA-Z0-9_]+)/edit$', 'ais.djais.views.fleet_edit'),
     (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'),
index f1b5cd45157a26e912362bd66f9941b5fdc0aa18..4e69f26e31a6ddd1c36494fe7aac9571a9699f7b 100644 (file)
@@ -407,6 +407,28 @@ def fleet(request, fleetname):
     return render_to_response('fleet.html', {'fleet':fleet}, RequestContext(request))
 
 
+class FleetEditForm(forms.Form):
+    description = forms.CharField(widget=forms.Textarea)
+
+@http_authenticate(auth, 'ais')
+def fleet_edit(request, fleetname):
+    fleet = get_object_or_404(Fleet, pk=fleetname)
+    if not FleetUser.objects.filter(fleet=fleetname, user=request.user.id).all():
+        return HttpResponseForbidden('<h1>Forbidden</h1>')
+
+    initial = {}
+    initial['description'] = fleet.description
+    if request.method == 'POST':
+        form = FleetEditForm(request.POST, initial=initial)
+        if form.is_valid():
+            fleet.description = form.cleaned_data['description']
+            fleet.save()
+            return HttpResponseRedirect('/fleet/%s/' % fleet.name)
+    else: # GET
+        form = FleetEditForm(initial=initial)
+    return render_to_response('fleet_edit.html', {'fleet':fleet, 'form':form}, RequestContext(request))
+
+
 @http_authenticate(auth, 'ais')
 def fleet_vessels(request, fleetname):
     fleet = get_object_or_404(Fleet, pk=fleetname)
index 5f4779c3a686826a44699ac597d075bfcb48e344..6a53ccabf22f1948603fb269834f0accd95966d6 100644 (file)
@@ -11,4 +11,6 @@
 <a href=lastpos class=button>Last positions in Google Earth</a><br>
 <a href=list class=button>Vessel list</a> ({{ fleet.vessel_count }} vessels)<br>
 <a href=users class=button>User list</a> ({{ fleet.user_count }} users)<br>
+<a href=edit class=button>Change descrription</a><br>
+
 {% endblock %}
diff --git a/html_templates/fleet_edit.html b/html_templates/fleet_edit.html
new file mode 100644 (file)
index 0000000..0dd371b
--- /dev/null
@@ -0,0 +1,19 @@
+{% extends "fleet.html" %}
+
+{% block breadcrumbs %}
+{{ block.super }}
+/ <a href="/fleet/{{fleet.name}}/edit">edit</a>
+{% endblock %}
+
+{% block content %}
+<h3>Edition of fleet {{ fleet.name }}</h3>
+<form method=post>
+{% include "fragment_formerror.html" %}
+<table>
+<tr><th>name<td>{{ fleet.name }}
+{{ form.as_table }}
+<tr><th><td>
+<input type=submit value=Save>
+</table>
+</form>
+{% endblock %}