<commit_before>from django import forms
from django.forms.util import ErrorList

from molly.conf import applications

from utils import geocode, reverse_geocode

METHOD_CHOICES = (
    ('html5', 'HTML5'),
    ('gears', 'Google Gears'),
    ('manual', 'Manual update'),
    ('geocoded', 'Geocoded'),
    ('other', 'Other method'),
    ('denied', 'Update denied by user'),
    ('error', 'Error updating location'),
)

class LocationUpdateForm(forms.Form):
    latitude = forms.FloatField(required=False)
    longitude = forms.FloatField(required=False)
    accuracy = forms.FloatField(required=False)
    method = forms.ChoiceField(required=False, choices=METHOD_CHOICES)
    name = forms.CharField(required=False)
 
    def clean_latitude(self):
        latitude = self.cleaned_data.get('latitude')
        if latitude is not None and not (-180 <= latitude < 180):
            raise forms.ValidationError('Must be in the range [-180, 180).')
        return latitude

    def clean_longitude(self):
        longitude = self.cleaned_data.get('longitude')
        if longitude is not None and not (-90 <= longitude < 90):
            raise forms.ValidationError('Must be in the range [-90, 90).')
        return longitude

    def clean(self):
        cleaned_data = self.cleaned_data

        if cleaned_data['method'] in ('html5', 'gears', 'manual', 'geocoded', 'other'):
            print "CD1", cleaned_data
            if cleaned_data['method'] == 'geocoded':
                results = geocode(cleaned_data['name'])
                if len(results) > 0:
                    cleaned_data.update(results[0])
                    cleaned_data['longitude'], cleaned_data['latitude'] = cleaned_data['location']
                else:
                    raise forms.ValidationError("Unable to find that location.")

            print "CD2", cleaned_data
            for key in ('latitude', 'longitude', 'accuracy'):<commit_msg>The 'location not found' message now contains the location name that couldn't be found.<commit_after>from django import forms
from django.forms.util import ErrorList

from molly.conf import applications

from utils import geocode, reverse_geocode

METHOD_CHOICES = (
    ('html5', 'HTML5'),
    ('gears', 'Google Gears'),
    ('manual', 'Manual update'),
    ('geocoded', 'Geocoded'),
    ('other', 'Other method'),
    ('denied', 'Update denied by user'),
    ('error', 'Error updating location'),
)

class LocationUpdateForm(forms.Form):
    latitude = forms.FloatField(required=False)
    longitude = forms.FloatField(required=False)
    accuracy = forms.FloatField(required=False)
    method = forms.ChoiceField(required=False, choices=METHOD_CHOICES)
    name = forms.CharField(required=False)
 
    def clean_latitude(self):
        latitude = self.cleaned_data.get('latitude')
        if latitude is not None and not (-180 <= latitude < 180):
            raise forms.ValidationError('Must be in the range [-180, 180).')
        return latitude

    def clean_longitude(self):
        longitude = self.cleaned_data.get('longitude')
        if longitude is not None and not (-90 <= longitude < 90):
            raise forms.ValidationError('Must be in the range [-90, 90).')
        return longitude

    def clean(self):
        cleaned_data = self.cleaned_data

        if cleaned_data['method'] in ('html5', 'gears', 'manual', 'geocoded', 'other'):
            print "CD1", cleaned_data
            if cleaned_data['method'] == 'geocoded':
                results = geocode(cleaned_data['name'])
                if len(results) > 0:
                    cleaned_data.update(results[0])
                    cleaned_data['longitude'], cleaned_data['latitude'] = cleaned_data['location']
                else:
                    raise forms.ValidationError("Unable to find a location that matches '%s'." % cleaned_data['name'])

            print "CD2", cleaned_data
            for key in ('latitude', 'longitude', 'accuracy'):
{'fraction_non_alphanumeric': 0.12449392712550607, 'fraction_numerical': 0.013663967611336033, 'mean_word_length': 2.8679060665362037, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129963', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1085, 'n_words': 304}