From da469ab08eb1f198394d36255a1017a65b7cf844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Mercader?= Date: Wed, 23 Nov 2011 11:05:52 +0000 Subject: [PATCH] [base harvester] Custom tag munge function. TODO: check with flexible tags --- ckanext/harvest/harvesters/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ckanext/harvest/harvesters/base.py b/ckanext/harvest/harvesters/base.py index 5c38701..3a1d9ce 100644 --- a/ckanext/harvest/harvesters/base.py +++ b/ckanext/harvest/harvesters/base.py @@ -1,5 +1,5 @@ import logging - +import re from ckan import model from ckan.model import Session, Package @@ -7,7 +7,7 @@ from ckan.logic import ValidationError, NotFound, get_action from ckan.logic.schema import default_package_schema from ckan.lib.navl.validators import ignore_missing -from ckan.lib.munge import munge_title_to_name, munge_tag +from ckan.lib.munge import munge_title_to_name,substitute_ascii_equivalents from ckanext.harvest.model import HarvestJob, HarvestObject, HarvestGatherError, \ HarvestObjectError @@ -17,6 +17,11 @@ from ckanext.harvest.interfaces import IHarvester log = logging.getLogger(__name__) +def munge_tag(tag): + tag = substitute_ascii_equivalents(tag) + tag = tag.lower().strip() + return re.sub(r'[^a-zA-Z0-9 -]', '', tag).replace(' ', '-') + class HarvesterBase(SingletonPlugin): ''' Generic class for harvesters with helper functions