diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-02-11 18:02:42 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-02-11 18:02:42 +0100 | 
| commit | ec824db12597389c87184497796e8d0763c80b51 (patch) | |
| tree | fb53154ba33dc4e31fe9bb25677e14d1c8418701 /chimere/utils.py | |
| parent | c70c2c8f4f58436df8d1c694a74c457954bd1070 (diff) | |
| download | Chimère-ec824db12597389c87184497796e8d0763c80b51.tar.bz2 Chimère-ec824db12597389c87184497796e8d0763c80b51.zip | |
New importer type XML - XSLT. Importer: add relation between category key and categories
* new importer type XML - XSLT
  * associated form and UI modification
* add new model ImporterKeyCategories
  * associated migration
  * associated admin modification
* longer state field for Importers
  * associated migration
Diffstat (limited to 'chimere/utils.py')
| -rw-r--r-- | chimere/utils.py | 27 | 
1 files changed, 22 insertions, 5 deletions
| diff --git a/chimere/utils.py b/chimere/utils.py index f3ec751..73e38ba 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -73,7 +73,7 @@ class ImportManager(object):          raise NotImplementedError      def create_or_update_item(self, cls, values, import_key, version=None, -                              key='', pk=None): +                              key='', pk=None, category=None):          updated, created, item = False, False, None          import_key = unicode(import_key).replace(':', '^')          if not values.get('name'): @@ -138,8 +138,11 @@ class ImportManager(object):          if import_key:              item.set_key(key, import_key)          item.categories.clear() -        for cat in self.importer_instance.categories.all(): -            item.categories.add(cat) +        if category: +            item.categories.add(category) +        else: +            for cat in self.importer_instance.categories.all(): +                item.categories.add(cat)          return item, updated, created      @classmethod @@ -964,6 +967,8 @@ class HtmlXsltManager(ImportManager):                      val = re.sub(r, replaced % {'base_url':base_url}, val)                  item[k] = html_unescape(val)          updated_item, new_item = 0, 0 +        key_categories = self.importer_instance.get_key_category_dict() +        missing_cats = set()          for item in items:              if not self.importer_instance.default_localisation and \                 not "point" in item and not ("lat" in item and item['lat']): @@ -973,6 +978,12 @@ class HtmlXsltManager(ImportManager):                                          self.importer_instance.origin),                     'license':self.importer_instance.license,                     'name':item['name']} +            category = None +            if 'category' in item and item['category']: +                if item['category'] in key_categories: +                    category = key_categories[item['category']] +                else: +                    missing_cats.add(item['category'])              cls = Marker              if 'point' in item:                  x, y = item['point'].split(",") @@ -1008,12 +1019,18 @@ class HtmlXsltManager(ImportManager):                                int(values['day2']))                          break              key = item['key'] -            it, updated, created = self.create_or_update_item(cls, dct, key) +            it, updated, created = self.create_or_update_item(cls, dct, key, +                                                              category=category)              if updated:                  updated_item += 1              if created:                  new_item += 1 -        return (new_item, updated_item, '') +        msg = '' +        if missing_cats: +            msg = _(u"Names \"%s\" doesn't match existing categories. " +                u"Modify the import to match theses names with categories.") % ( +                    u'", "'.join(missing_cats)) +        return (new_item, updated_item, msg)  class XMLXsltManager(HtmlXsltManager):      PARSER = 'XMLParser' | 
