summaryrefslogtreecommitdiff
path: root/chimere/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-10-30 23:01:10 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-10-30 23:01:10 +0100
commitbd6dea1a3128ab924eb82a63498cd512d0b27bfb (patch)
tree7681ec79d0858dd561455695ba1bb8f0f7acd228 /chimere/utils.py
parent5b41f143a3956fbd9d3a2288e607e6aa8d8c3451 (diff)
downloadChimère-bd6dea1a3128ab924eb82a63498cd512d0b27bfb.tar.bz2
Chimère-bd6dea1a3128ab924eb82a63498cd512d0b27bfb.zip
HTML-XSLT import: manage write on the database - import tests - fix pointwidget when using a name not equal to point
Diffstat (limited to 'chimere/utils.py')
-rw-r--r--chimere/utils.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/chimere/utils.py b/chimere/utils.py
index 894c13c..0344421 100644
--- a/chimere/utils.py
+++ b/chimere/utils.py
@@ -856,6 +856,7 @@ class HtmlXsltManager(ImportManager):
- updated items;
- error detail on error.
"""
+ from models import Marker
try:
main_page = urllib2.urlopen(self.importer_instance.source)
assert main_page.getcode() == 200
@@ -869,8 +870,9 @@ class HtmlXsltManager(ImportManager):
dom = etree.HTML(doc, etree.HTMLParser())
try:
xslt = etree.parse(self.importer_instance.source_file)
+ self.importer_instance.source_file.seek(0)
transform = etree.XSLT(xslt)
- except (etree.XSLTParseError, etree.XMLSyntaxError):
+ except (etree.XSLTParseError, etree.XMLSyntaxError, TypeError):
return (0, 0, _(u"The source file is not a valid XSLT file."))
newdom = transform(dom)
items = []
@@ -879,8 +881,9 @@ class HtmlXsltManager(ImportManager):
if self.importer_instance.source_file_alt:
try:
alt_xslt = etree.parse(self.importer_instance.source_file_alt)
+ self.importer_instance.source_file_alt.seek(0)
transform_child = etree.XSLT(alt_xslt)
- except (etree.XSLTParseError, etree.XMLSyntaxError):
+ except (etree.XSLTParseError, etree.XMLSyntaxError, TypeError):
return (0, 0,
_(u"The alt source file is not a valid XSLT file."))
base_url = u"/".join(self.importer_instance.source.split(u'/')[:-1])
@@ -915,4 +918,27 @@ class HtmlXsltManager(ImportManager):
for r, replaced in RE_CLEANS:
val = re.sub(r, replaced % {'base_url':base_url}, val)
item[k] = val
- return (42, 43, '')
+ updated_item, new_item = 0, 0
+ for item in items:
+ if not self.importer_instance.default_localisation and \
+ not "point" in item:
+ continue
+ cls = None
+ dct = {'origin':"<a href='%s'>%s</a>" % (item['link'],
+ self.importer_instance.origin),
+ 'license':self.importer_instance.license,
+ 'name':item['name']}
+ cls = Marker
+ if 'point' in item:
+ x, y = item['point'].split(",")
+ dct['point'] = 'SRID=4326;POINT(%s %s)' % (x, y)
+ else:
+ dct['point'] = self.importer_instance.default_localisation
+ dct['description'] = item['description']
+ key = item['key']
+ it, updated, created = self.create_or_update_item(cls, dct, key)
+ if updated:
+ updated_item += 1
+ if created:
+ new_item += 1
+ return (new_item, updated_item, '')