Commits

Mikhail Korobov committed 826a84f

Handling of empty addresses is fixed

  • Participants
  • Parent commits eeff5ca

Comments (0)

Files changed (3)

easy_maps/models.py

 from django.db import models
+from django.utils.encoding import smart_str
 from geopy import geocoders
 
+
+
 class Address(models.Model):
     address = models.CharField(max_length=255, db_index=True)
     computed_address = models.CharField(max_length=255, null=True, blank=True)
     geocode_error = models.BooleanField(default=False)
 
     def fill_geocode_data(self):
+        if not self.address:
+            self.geocode_error = True
+            return
         try:
             g = geocoders.Google(resource='maps')
-            address = self.address.encode('utf8')
+            address = smart_str(self.address)
             self.computed_address, (self.latitude, self.longtitude,) = g.geocode(address)
             self.geocode_error = False
         except (UnboundLocalError, ValueError,):

easy_maps/templatetags/easy_maps_tags.py

             address = self.address.resolve(context)
             template_name = self.template_name.resolve(context)
 
-            map, _ = Address.objects.get_or_create(address=address)
+            map, _ = Address.objects.get_or_create(address=address or '')
             context.update({
                 'map': map,
                 'width': self.width,
 #!/usr/bin/env python
 from distutils.core import setup
-version='0.5.3'
+version='0.5.4'
 
 setup(
     name = 'django-easy-maps',