summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chimere/utils.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/chimere/utils.py b/chimere/utils.py
index 5289600..0dfe588 100644
--- a/chimere/utils.py
+++ b/chimere/utils.py
@@ -22,12 +22,13 @@ Utilitaries
"""
import csv
+import collections
import datetime
import feedparser
+import json
import os
import re
import StringIO
-import json
import tempfile
import urllib2
import unicodedata
@@ -683,7 +684,8 @@ class JsonManager(ImportManager):
vals = source.read().replace('\n', ' ')
try:
- values = json.JSONDecoder().decode(vals)
+ values = json.JSONDecoder(
+ object_pairs_hook=collections.OrderedDict).decode(vals)
except ValueError as e:
return (new_item, updated_item,
_(u"JSON file is not well formed: " + e.message))
@@ -704,20 +706,38 @@ class JsonManager(ImportManager):
_(u"A key must be associated to \"%s\" in the "
u"filter.") % k)
+ default_dct = {'origin': self.importer_instance.origin,
+ 'license': self.importer_instance.license}
+ if 'prefix_title' in filtr:
+ default_dct['title'] = filtr.pop('prefix_title')
+ if 'prefix_description' in filtr:
+ default_dct['description'] = filtr.pop('prefix_description')
+ if self.importer_instance.default_localisation:
+ default_dct['point'] = self.importer_instance.default_localisation
+
for item in values:
- dct = {'origin': self.importer_instance.origin,
- 'license': self.importer_instance.license}
+ dct = default_dct.copy()
for k in filtr:
if k in item and item[k]:
- dct[filtr[k]] = item[k]
+ if filtr[k] not in dct:
+ dct[filtr[k]] = ""
+ else:
+ if filtr[k] == 'description':
+ dct[filtr[k]] += "<br/>"
+ else:
+ dct[filtr[k]] += " "
+ dct[filtr[k]] += item[k]
if 'point' in item:
x, y = item['point'].split(",")
dct['point'] = 'SRID=4326;POINT(%s %s)' % (x, y)
- elif 'lat' in item and item['lat']:
+ elif 'lat' in item and item['lat'] \
+ and 'lon' in item and item['lon']:
dct['point'] = 'SRID=4326;POINT(%s %s)' % (item['lon'],
item['lat'])
- else:
- dct['point'] = self.importer_instance.default_localisation
+ elif 'x' in item and item['x'] \
+ and 'y' in item and item['y']:
+ dct['point'] = 'SRID=4326;POINT(%s %s)' % (item['x'],
+ item['y'])
if not dct['point']:
continue
cls = Marker