def clean_location(self): location = self.data.get('location', '') if not location: return location = check_location(location) if not location: error_msg = ugettext_lazy("Specified location is invalid") raise forms.ValidationError(error_msg) return Location.create(location)
def clean_location(self): location = self.data.get('location', '') if not location: return location = check_location(location) if not location: error_msg = ugettext_lazy( "Specified location is invalid" ) raise forms.ValidationError(error_msg) return Location.create(location)
def handle(self, *args, **options): commit = options['commit'] empty = 0 fine = 0 fixable = 0 bad = [] for location in Location.objects.all(): user_count = User.objects.filter(location=location).count() if not user_count: logging.info("Empty location: %s", location) if commit: location.delete() logging.info('Deleted') empty += 1 continue l = check_location(location.name) if l == location.name: logging.info('Location fine: %s', location) fine += 1 continue if not commit: if l: fixable += 1 else: bad.append((location, user_count)) continue elif l is not None: new_loc = Location.create(l) User.objects.filter(location=location).update(location=new_loc) user_count = User.objects.filter(location=location).count() if not user_count: logging.error("missed users!") else: location.delete() elif l is None: logging.info('Bad location: %s', location) location.approved = False location.save() if not commit: [logging.error('Bad Loc: %s, count: %s', l, c) for l, c in bad] logging.info('Empty: %s, Fine: %s, fixable: %s', empty, fine, fixable) logging.info('Add --commit to fix locations')
def test_location_check(self): location = check_location(u'wrocław') self.assertEqual(location, 'Wroclaw, Poland')