diff options
Diffstat (limited to 'chimere/utils.py')
| -rw-r--r-- | chimere/utils.py | 32 | 
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, '') | 
