Fleet name can now be changed
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 6 Nov 2010 20:14:33 +0000 (20:14 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 6 Nov 2010 20:14:33 +0000 (20:14 +0000)
bin/djais/views.py
html_templates/fleet.html
html_templates/fleet_edit.html

index 5870d73dfcecd249c5a17bae59265d39265b78be..f3408cab4001fdfe64ffd987847980ae774d9b74 100644 (file)
@@ -445,9 +445,19 @@ def fleet(request, fleetname):
 
 
 class FleetEditForm(forms.Form):
-    #name = forms.CharField()
+    name = forms.CharField(max_length=50)
     description = forms.CharField(widget=forms.Textarea)
 
+    def clean_name(self):
+        name = self.cleaned_data['name']
+        if name == u'add':
+            raise forms.ValidationError("Sorry that name is reserved. Try another one.")
+        if name != self.initial.get('name', None):
+            if Fleet.objects.filter(name=name).count():
+                raise forms.ValidationError("Sorry that fleet name is already in use. Try another one.")
+        return remove_decoration(name).replace(u' ', u'_')
+        
+
 @http_authenticate(auth, 'ais')
 def fleet_edit(request, fleetname):
     # TODO fleetname = None => add
@@ -456,14 +466,15 @@ def fleet_edit(request, fleetname):
         return HttpResponseForbidden('<h1>Forbidden</h1>')
 
     initial = {}
+    initial['name'] = fleet.name
     initial['description'] = fleet.description
-    initial['id'] = fleet.name
     if request.method == 'POST':
         form = FleetEditForm(request.POST, initial=initial)
         if form.is_valid():
+            fleet.name = form.cleaned_data['name']
             fleet.description = form.cleaned_data['description']
             fleet.save()
-            request.user.info('Fleet description updated')
+            request.user.info('Fleet updated')
             return HttpResponseRedirect('/fleet/%s/' % fleet.name)
     else: # GET
         form = FleetEditForm(initial=initial)
index af8e64330f05c073b1d6b7ab228c8678f742c5a4..995a20130f06cc9e76878276a7a54c724ed5b459 100644 (file)
@@ -11,6 +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 }} vessel{{ fleet.vessel_count|pluralize }})<br>
 <a href=users class=button>User list</a> ({{ fleet.user_count }} user{{ fleet.user_count|pluralize }})<br>
-<a href=edit class=button>Change description</a><br>
+<a href=edit class=button>Change details</a><br>
 
 {% endblock %}
index 0dd371bb4759b32a21c298dd8fd9477970b0f690..b7cd0a1f7d967752346255179ea40a5a95a8976a 100644 (file)
@@ -10,7 +10,6 @@
 <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>