[base harvester] Custom tag munge function. TODO: check with flexible tags

This commit is contained in:
Adrià Mercader 2011-11-23 11:05:52 +00:00
parent cfaba6e1e8
commit da469ab08e
1 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import logging import logging
import re
from ckan import model from ckan import model
from ckan.model import Session, Package 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.logic.schema import default_package_schema
from ckan.lib.navl.validators import ignore_missing 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, \ from ckanext.harvest.model import HarvestJob, HarvestObject, HarvestGatherError, \
HarvestObjectError HarvestObjectError
@ -17,6 +17,11 @@ from ckanext.harvest.interfaces import IHarvester
log = logging.getLogger(__name__) 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): class HarvesterBase(SingletonPlugin):
''' '''
Generic class for harvesters with helper functions Generic class for harvesters with helper functions