Michael Hall has proposed merging lp:~mhall119/loco-directory/fixes-612997 into
lp:loco-directory.
Requested reviews:
loco-directory-dev (loco-directory-dev)
Related bugs:
#612997 IntegrityError: duplicate key value violates unique constraint
"venues_venue_longitude_2d904d039bce1526"
https://bugs.launchpad.net/bugs/612997
Check for duplicate long/lat in existing venues during form validation
--
https://code.launchpad.net/~mhall119/loco-directory/fixes-612997/+merge/31865
Your team loco-directory-dev is requested to review the proposed merge of
lp:~mhall119/loco-directory/fixes-612997 into lp:loco-directory.
=== modified file 'loco_directory/venues/forms.py'
--- loco_directory/venues/forms.py 2010-07-09 14:04:25 +0000
+++ loco_directory/venues/forms.py 2010-08-05 17:04:51 +0000
@@ -3,9 +3,10 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
from models import Venue
+from django.forms.fields import EMPTY_VALUES
def validate_name(name):
- if not name.strip():
+ if not name or not name.strip():
raise forms.ValidationError(_(u'Please use a descriptive name for the venue.'))
return name
@@ -17,6 +18,13 @@
model = Venue
def clean(self):
+ if self.cleaned_data.has_key('longitude') and self.cleaned_data['longitude'] not in EMPTY_VALUES \
+ and self.cleaned_data.has_key('latitude') and self.cleaned_data['latitude'] not in EMPTY_VALUES:
+ dup = Venue.objects.filter(longitude=self.cleaned_data['longitude'], latitude=self.cleaned_data['latitude'])
+ if self.cleaned_data.has_key('id'):
+ dup = dup.exclude(pk=self.cleaned_data['id'])
+ if dup is not None and len(dup) > 0:
+ raise forms.ValidationError(_('A Venue already exists at these coordinate: %s'%dup[0].name))
self.cleaned_data['name'] = validate_name(self.cleaned_data['name'])
return self.cleaned_data
_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help : https://help.launchpad.net/ListHelp