[ui,logic] Expose source state (active/inactive) in the source form
This commit is contained in:
parent
4d7b8143b9
commit
2990353533
|
@ -80,7 +80,7 @@ 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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,21 @@
|
|||
<dd class="instructions basic">You can add your own notes here about what the URL above represents to remind you later.</dd>
|
||||
<dt><label class="field_opt" for="config">Configuration</label></dt>
|
||||
<dd><textarea id="config" name="config" cols="30" rows="2" style="height:75px">${data.get('config', '')}</textarea></dd>
|
||||
|
||||
<dt><label class="field_opt" for="active">State</label></dt>
|
||||
<dd>
|
||||
<select id="active" name="active">
|
||||
<option py:attrs="{'selected': 'selected' if data.get('active') or not 'active' in data else None}" value="True">active</option>
|
||||
<option py:attrs="{'selected': 'selected' if 'active' in data and not data.get('active') else None}" value="False">inactive</option>
|
||||
</select>
|
||||
<py:if test="data.get('active') or not 'active' in data">
|
||||
<div>This harvest source is <span class="source-state-active">Active</span></div>
|
||||
</py:if>
|
||||
<py:if test="'active' in data and not data.get('active')">
|
||||
<div>This harvest source is <span class="source-state-inactive">Inactive</span></div>
|
||||
</py:if>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<input id="save" name="save" value="Save" type="submit" /> or <a href="/harvest">Return to the harvest sources list</a>
|
||||
|
|
Loading…
Reference in New Issue