def get_location(self): location_raw = self.cleaned_data.get('location_raw') city_state_location = None # Sometimes the user doesn't actually select an autocomplete option, and the input will not contain a comma. # This causes the unpacking to crash. Don't let that happen. if ',' in location_raw: city, state = map(lambda x: x.strip().lower(), location_raw.split(',')) else: city, state = location_raw.strip().lower(), '' try: city_state_location = map_citystate_to_location(city, state) except LocationMatchingException as e: logging.error( e.msg + 'location_raw - {} did not match a location in the DB'.format( self.cleaned_data.get('location_raw'), exc_info=True, stack_info=True, )) raise forms.ValidationError( 'Something is wrong with that location!', code='invalid_location') return city_state_location
def get_location(self): location_raw = self.cleaned_data.get('location_raw') city_state_location = None # Sometimes the user doesn't actually select an autocomplete option, and the input will not contain a comma. # This causes the unpacking to crash. Don't let that happen. if ',' in location_raw: city, state = map(lambda x: x.strip().lower(), location_raw.split(',')) else: city, state = location_raw.strip().lower(), '' try: city_state_location = map_citystate_to_location(city, state) except LocationMatchingException as e: logging.error(e.msg + 'location_raw - {} did not match a location in the DB' .format(self.cleaned_data.get('location_raw'), exc_info=True, stack_info=True, ) ) raise forms.ValidationError('Something is wrong with that location!', code='invalid_location') return city_state_location