summaryrefslogtreecommitdiff
path: root/chimere/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-11-19 01:08:51 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-11-19 01:08:51 +0100
commitded35ffba989c28d8dd515fc9c0f4e241038d668 (patch)
treee756e63c9dca53bdf0f23e68a367a16b927ab61b /chimere/forms.py
parent5db6ae2fc14ebbec4b52151c7250ca0bba98bc02 (diff)
parent7d8c3719bb2dfaa70b1d6c5e2a19c53588091d3b (diff)
downloadChimère-ded35ffba989c28d8dd515fc9c0f4e241038d668.tar.bz2
Chimère-ded35ffba989c28d8dd515fc9c0f4e241038d668.zip
Merge branch 'master' into saclay
Conflicts: chimere/admin.py chimere/models.py chimere/templates/chimere/detail.html chimere/templatetags/chimere_tags.py chimere/tests.py
Diffstat (limited to 'chimere/forms.py')
-rw-r--r--chimere/forms.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/chimere/forms.py b/chimere/forms.py
index 2380f3c..c6998c8 100644
--- a/chimere/forms.py
+++ b/chimere/forms.py
@@ -227,7 +227,7 @@ class MarkerAdminFormBase(forms.ModelForm):
Custom save method in order to manage associated properties
"""
new_marker = super(MarkerAdminFormBase, self).save(*args, **keys)
- if 'status' not in self.cleaned_data:
+ if 'status' not in self.cleaned_data and not new_marker.status:
new_marker.status = 'S'
if new_marker.status == 'A':
tz = UTC()
@@ -316,7 +316,7 @@ class RouteAdminForm(forms.ModelForm):
Custom save method in order to manage associated properties
"""
new_route = super(RouteAdminForm, self).save(*args, **keys)
- if 'status' not in self.cleaned_data:
+ if 'status' not in self.cleaned_data and not new_route.status:
new_route.status = 'S'
new_route.save()
return new_route
@@ -510,6 +510,17 @@ class AreaAdminForm(forms.ModelForm):
"""
Custom initialization method in order to manage area
"""
+ if args:
+ vals = args[0]
+ for k in ('upper_left_lat', 'upper_left_lon',
+ 'lower_right_lat', 'lower_right_lon'):
+ v = vals.get(k)
+ try:
+ v = float(v)
+ except ValueError:
+ v = None
+ if not v:
+ args[0][k] = None
if 'instance' in keys and keys['instance']:
instance = keys['instance']
dct = {'area':(instance.upper_left_corner,
@@ -520,6 +531,25 @@ class AreaAdminForm(forms.ModelForm):
keys['initial'] = dct
super(AreaAdminForm, self).__init__(*args, **keys)
+ def clean(self):
+ '''
+ Verify that the area is not empty
+ '''
+ if not self.cleaned_data.get('upper_left_lat') \
+ and not self.cleaned_data.get('upper_left_lon') \
+ and not self.cleaned_data.get('lower_right_lat') \
+ and not self.cleaned_data.get('lower_right_lon') \
+ and not self.cleaned_data.get('area'):
+ msg = _(u"No area selected.")
+ raise forms.ValidationError(msg)
+ if self.cleaned_data.get('order'):
+ q = Area.objects.filter(order=self.cleaned_data.get('order'))
+ if q.count():
+ msg= _(u"The area \"%s\" has the same order, you need to "
+ u" choose another one.") % unicode(q.all()[0])
+ raise forms.ValidationError(msg)
+ return self.cleaned_data
+
def save(self, *args, **keys):
"""
Custom save method in order to manage area