Merge branch '2.0-dataset-sources' into 4-new-auth-for-2.0

Conflicts:
	ckanext/harvest/logic/action/get.py
This commit is contained in:
amercader 2013-01-09 11:09:34 +00:00
commit 1342463f8a
3 changed files with 27 additions and 17 deletions

View File

@ -3,9 +3,12 @@ from pylons import request
from ckan import logic
from ckan import model
import ckan.lib.helpers as h
import ckan.plugins as p
from ckanext.harvest.model import UPDATE_FREQUENCIES
from ckanext.harvest.plugin import DATASET_TYPE_NAME
def package_list_for_source(source_id):
'''
Creates a dataset list with the ones belonging to a particular harvest
@ -46,3 +49,17 @@ def package_list_for_source(source_id):
out += pager.pager()
return out
def harvesters_info():
context = {'model': model, 'user': p.toolkit.c.user or p.toolkit.c.author}
return logic.get_action('harvesters_info_show')(context,{})
def harvester_types():
harvesters = harvesters_info()
return [{'text': p.toolkit._(h['title']), 'value': h['name']}
for h in harvesters]
def harvest_frequencies():
return [{'text': p.toolkit._(f.title()), 'value': f}
for f in UPDATE_FREQUENCIES]

View File

@ -12,7 +12,6 @@ from ckanext.harvest import logic as harvest_logic
from ckanext.harvest.model import setup as model_setup
from ckanext.harvest.model import HarvestSource, HarvestJob, HarvestObject
from ckanext.harvest.model import UPDATE_FREQUENCIES
log = getLogger(__name__)
@ -108,20 +107,9 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
return 'source/edit.html'
def setup_template_variables(self, context, data_dict):
harvesters_info = logic.get_action('harvesters_info_show')(context,{})
p.toolkit.c.harvest_source = p.toolkit.c.pkg
p.toolkit.c.frequencies = [
{'text': p.toolkit._(f.title()), 'value': f}
for f in UPDATE_FREQUENCIES
]
p.toolkit.c.harvester_types = [
{'text': p.toolkit._(h['title']), 'value': h['name']}
for h in harvesters_info
]
p.toolkit.c.harvesters_info = harvesters_info
p.toolkit.c.dataset_type = DATASET_TYPE_NAME
def form_to_db_schema_options(self, options):
@ -283,7 +271,12 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
## ITemplateHelpers
def get_helpers(self):
from ckanext.harvest import helpers as harvest_helpers
return {'package_list_for_source': harvest_helpers.package_list_for_source}
return {
'package_list_for_source': harvest_helpers.package_list_for_source,
'harvesters_info': harvest_helpers.harvesters_info,
'harvester_types': harvest_helpers.harvester_types,
'harvest_frequencies': harvest_helpers.harvest_frequencies,
}
def _get_auth_functions(module_root, auth_functions = {}):

View File

@ -19,16 +19,16 @@
{{ form.markdown('notes', id='field-notes', label=_('Description'), value=data.notes, error=errors.notes) }}
{{ form.select('source_type', id='field-source_type', label=_('Source type'), options=c.harvester_types, selected=data.source_type, error=errors.source_type) }}
{{ form.select('source_type', id='field-source_type', label=_('Source type'), options=h.harvester_types(), selected=data.source_type, error=errors.source_type) }}
<div class="controls">
<ul>
{% for harvester in c.harvesters_info %}
{% for harvester in h.harvesters_info() %}
<li><b>{{ harvester['title']}}</b>: {{harvester['description'] }}</li>
{% endfor %}
</ul>
</div>
{{ form.select('frequency', id='field-frequency', label=_('Frequency of update'), options=c.frequencies, selected=data.frequency, error=errors.frequency) }}
{{ form.select('frequency', id='field-frequency', label=_('Frequency of update'), options=h.harvest_frequencies(), selected=data.frequency, error=errors.frequency) }}
{{ form.textarea('config', id='field-config', label=_('Configuration'), value=data.config, error=errors.config) }}