summaryrefslogtreecommitdiff
path: root/chimere/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/utils.py')
-rw-r--r--chimere/utils.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/chimere/utils.py b/chimere/utils.py
index 42f3b06..4a12e37 100644
--- a/chimere/utils.py
+++ b/chimere/utils.py
@@ -67,7 +67,7 @@ class ImportManager:
def get(self):
pass
- def put(self):
+ def put(self, extra_args={}):
pass
def create_or_update_item(self, cls, values, import_key, version=None,
@@ -323,6 +323,10 @@ class ShapefileManager(ImportManager):
if not srid:
# try with the default projection
srid = settings.CHIMERE_EPSG_DISPLAY_PROJECTION
+ msg = _(u"SRID cannot be guessed. The default SRID (%s) has "
+ u"been used.") % srid
+ #If imported items are not well located "
+ # u"ask your data provider for the SRID to use.") % srid
shapefilename = tmpdir + os.sep + sources[0]
ds = DataSource(shapefilename)
lyr = ds[0]
@@ -569,17 +573,22 @@ class GeoRSSManager(ImportManager):
if feed['bozo']:
return (0, 0, _(u"RSS feed is not well formed"))
for item in feed['items']:
- if "georss_point" not in item and 'georss_line' not in item:
+ if "georss_point" not in item and 'georss_line' not in item \
+ and not ("geo_lat" in item and "geo_long" in item):
continue
cls = None
dct = {'origin':self.importer_instance.origin,
'license':self.importer_instance.license}
- if 'georss_point' in item:
+ if 'georss_point' in item or "geo_lat" in item:
cls = Marker
- try:
- y, x = item['georss_point'].split(' ')
- except ValueError:
- continue
+ if 'georss_point' in item:
+ try:
+ y, x = item['georss_point'].split(' ')
+ except ValueError:
+ continue
+ else:
+ y = item['geo_lat']
+ x = item['geo_long']
dct['point'] = 'SRID=4326;POINT(%s %s)' % (x, y)
for k in ['description', 'summary', 'value']:
if k in item:
@@ -716,7 +725,7 @@ class OSMManager(ImportManager):
items.append(item)
return (new_item, updated_item, msg)
- def put(self):
+ def put(self, extra_args={}):
# first of all: reimport in order to verify that no changes has been
# made since the last import
from models import Marker
@@ -730,14 +739,26 @@ class OSMManager(ImportManager):
return 0, _(u"There are items from a former import not yet "
u"validated - validate them before exporting")
# start import
- api = OsmApi.OsmApi(api=settings.CHIMERE_OSM_API_URL,
- username=settings.CHIMERE_OSM_USER,
- password=settings.CHIMERE_OSM_PASSWORD)
+ api = settings.CHIMERE_OSM_API_URL
+ username = settings.CHIMERE_OSM_USER
+ password = settings.CHIMERE_OSM_PASSWORD
+ if extra_args:
+ try:
+ api = extra_args['api']
+ username = extra_args['username']
+ password = extra_args['password']
+ except KeyError:
+ return 0, _(u"Bad params - programming error")
+ username = username.encode('latin1')
+ password = password.encode('latin1')
+ api = OsmApi.OsmApi(api=api, username=username, password=password)
api.ChangesetCreate({u"comment": u"Import from Chimère %s" % \
get_version()})
hooks = RE_HOOK.findall(self.importer_instance.filtr)
if not hooks:
- return 0, _(u"Bad param")
+ hooks = RE_HOOK.findall(self.importer_instance.source)
+ if not hooks:
+ return 0, _(u"Bad param")
tags = {}
bbox = []
for hook in hooks: