summaryrefslogtreecommitdiff
path: root/chimere
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-01-30 21:27:32 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-01-30 21:27:32 +0100
commit600e2114ff29f1d87663bda0b300774ec3f5575b (patch)
tree176f8e232a9a3a0946463c5ba9c35f7b908d97bb /chimere
parentfea958d3e513c8237f509186bccb706cc655f363 (diff)
downloadChimère-600e2114ff29f1d87663bda0b300774ec3f5575b.tar.bz2
Chimère-600e2114ff29f1d87663bda0b300774ec3f5575b.zip
Small improve on KML import
Diffstat (limited to 'chimere')
-rw-r--r--chimere/utils.py15
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,