diff options
Diffstat (limited to 'chimere/utils.py')
| -rw-r--r-- | chimere/utils.py | 15 | 
1 files changed, 8 insertions, 7 deletions
| diff --git a/chimere/utils.py b/chimere/utils.py index 8a9855a..fe1a8a1 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -50,7 +50,7 @@ def unicode_normalize(string):          (c for c in unicodedata.normalize('NFD', string)          if unicodedata.category(c) != 'Mn')) -class ImportManager: +class ImportManager(object):      u"""      Generic class for specific importers      """ @@ -74,6 +74,8 @@ class ImportManager:                                key='', pk=None):          updated, created, item = False, False, None          import_key = unicode(import_key).replace(':', '^') +        if not values.get('name'): +            values['name'] = self.default_name          if not key:              key = self.importer_instance.importer_type          if import_key or pk: @@ -84,7 +86,10 @@ class ImportManager:                  if pk:                      ref_item = cls.objects.get(pk=pk)                  else: -                    ref_item = cls.objects.get(**dct_import) +                    ref_item = cls.objects.filter(**dct_import) +                    if not ref_item.count(): +                        raise ObjectDoesNotExist +                    ref_item = ref_item.all()[0]                  if version and ref_item.import_version == int(version):                      # no update since the last import                      return ref_item, None, None @@ -196,7 +201,7 @@ class KMLManager(ImportManager):      XPATH = '//kml:Folder/kml:name[text()="%s"]/../kml:Placemark'      DEFAULT_XPATH = '//kml:Placemark'      def __init__(self, importer_instance, ns=''): -        self.importer_instance = importer_instance +        super(KMLManager, self).__init__(importer_instance)          self.ns = ns      def get(self): @@ -674,8 +679,6 @@ class OSMManager(ImportManager):                      name = item.attrib.get('v')                  if item.tag == 'nd':                      points.append(item.get('ref')) -            if not name: -                name = self.default_name              if not points:                  continue              wkt = 'SRID=4326;LINESTRING(%s)' % ",".join([nodes[point_id] @@ -709,8 +712,6 @@ class OSMManager(ImportManager):                  k = item.attrib.get('k')                  if k == 'name':                      name = item.attrib.get('v') -            if not name: -                name = self.default_name              point = 'SRID=4326;POINT(%s %s)' % (node.get('lon'),                                                  node.get('lat'))              dct = {'point':point, | 
