diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index b146c88..2589159 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -42,7 +42,7 @@ class ViewController(BaseController): errors = errors or {} error_summary = error_summary or {} vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'harvesters': get_registered_harvesters_info()} - + c.form = render('source/new_source_form.html', extra_vars=vars) return render('source/new.html') @@ -80,9 +80,9 @@ class ViewController(BaseController): data = data or old_data errors = errors or {} error_summary = error_summary or {} - #TODO: Use new description interface to build the types select and descriptions + vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'harvesters': get_registered_harvesters_info()} - + c.form = render('source/new_source_form.html', extra_vars=vars) return render('source/edit.html') diff --git a/ckanext/harvest/lib/__init__.py b/ckanext/harvest/lib/__init__.py index 364c64d..78a1926 100644 --- a/ckanext/harvest/lib/__init__.py +++ b/ckanext/harvest/lib/__init__.py @@ -194,6 +194,9 @@ def create_harvest_source(data_dict): if o in data and data[o] is not None: source.__setattr__(o,data[o]) + if 'active' in data_dict: + source.active = data['active'] + source.save() return _source_as_dict(source) @@ -213,14 +216,25 @@ def edit_harvest_source(source_id,data_dict): Session.rollback() raise ValidationError(errors,_error_summary(errors)) - fields = ['url','type','active','description','user_id','publisher_id'] + fields = ['url','type','description','user_id','publisher_id'] for f in fields: - if f in data_dict and data_dict[f] is not None and data_dict[f] != '': - source.__setattr__(f,data_dict[f]) + if f in data and data[f] is not None and data[f] != '': + source.__setattr__(f,data[f]) - source.config = data_dict['config'] + if 'active' in data_dict: + source.active = data['active'] + + if 'config' in data_dict: + source.config = data['config'] source.save() + # Abort any pending jobs + if not source.active: + jobs = HarvestJob.filter(source=source,status=u'New') + if jobs: + for job in jobs: + job.status = u'Aborted' + job.save() return _source_as_dict(source) diff --git a/ckanext/harvest/logic/schema.py b/ckanext/harvest/logic/schema.py index 37c804a..0145c7a 100644 --- a/ckanext/harvest/logic/schema.py +++ b/ckanext/harvest/logic/schema.py @@ -5,10 +5,11 @@ from ckan.lib.navl.validators import (ignore_missing, not_missing ) -from ckanext.harvest.logic.validators import harvest_source_id_exists, \ - harvest_source_url_validator, \ - harvest_source_type_exists, \ - harvest_source_config_validator +from ckanext.harvest.logic.validators import (harvest_source_id_exists, + harvest_source_url_validator, + harvest_source_type_exists, + harvest_source_config_validator, + harvest_source_active_validator,) def default_harvest_source_schema(): @@ -17,7 +18,7 @@ def default_harvest_source_schema(): 'url': [not_empty, unicode, harvest_source_url_validator], 'type': [not_empty, unicode, harvest_source_type_exists], 'description': [ignore_missing], - 'active': [ignore_missing], + 'active': [ignore_missing,harvest_source_active_validator], 'user_id': [ignore_missing], 'publisher_id': [ignore_missing], 'config': [ignore_missing,harvest_source_config_validator] diff --git a/ckanext/harvest/logic/validators.py b/ckanext/harvest/logic/validators.py index 87959a7..e851649 100644 --- a/ckanext/harvest/logic/validators.py +++ b/ckanext/harvest/logic/validators.py @@ -56,7 +56,7 @@ def harvest_source_url_validator(key,data,errors,context): for url,active in existing_sources: url = _normalize_url(url) if url == new_url: - raise Invalid('There already is an active Harvest Source for this URL: %s' % data[key]) + raise Invalid('There already is a Harvest Source for this URL: %s' % data[key]) return data[key] @@ -91,3 +91,11 @@ def harvest_source_config_validator(key,data,errors,context): else: return data[key] +def harvest_source_active_validator(value,context): + if isinstance(value,basestring): + if value.lower() == 'true': + return True + else: + return False + return bool(value) + diff --git a/ckanext/harvest/public/ckanext/harvest/style.css b/ckanext/harvest/public/ckanext/harvest/style.css index 163e43e..9f5aaca 100644 --- a/ckanext/harvest/public/ckanext/harvest/style.css +++ b/ckanext/harvest/public/ckanext/harvest/style.css @@ -58,3 +58,12 @@ body.index.ViewController #content { vertical-align: middle; margin: 0 5px; } + +.source-state-active{ + font-weight:bold; +} + +.source-state-inactive{ + font-weight:bold; + color: red; +} diff --git a/ckanext/harvest/templates/source/new_source_form.html b/ckanext/harvest/templates/source/new_source_form.html index 72c94e8..a455789 100644 --- a/ckanext/harvest/templates/source/new_source_form.html +++ b/ckanext/harvest/templates/source/new_source_form.html @@ -40,6 +40,21 @@