Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding validator and parser for default_groups and tags config #196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions ckanext/spatial/harvesters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,20 @@ def validate_config(self, source_config):
if 'default_tags' in source_config_obj:
if not isinstance(source_config_obj['default_tags'],list):
raise ValueError('default_tags must be a list')
elif not isinstance(source_config_obj['default_tags'][0], dict):
# This check is taken from ckanext-harvest CKANHarvester to ensure consistency
# between harversters.
raise ValueError('default_tags must be a list of dicts like {"name": "name-of-tag"}')

if 'default_extras' in source_config_obj:
if not isinstance(source_config_obj['default_extras'],dict):
raise ValueError('default_extras must be a dictionary')

if 'default_groups' in source_config_obj:
# Also taken from CKANHarvester to ensure consistency.
if not isinstance(source_config_obj['default_groups'], list):
raise ValueError('default_groups must be a *list* of group names/ids')

for key in ('override_extras', 'clean_tags'):
if key in source_config_obj:
if not isinstance(source_config_obj[key],bool):
Expand Down Expand Up @@ -211,17 +220,29 @@ def get_package_dict(self, context, data_dict):
tags_val = [munge_tag(tag) if do_clean else tag[:100] for tag in iso_values['tags']]
tags = [{'name': tag} for tag in tags_val]

# Add default_tags from config
default_tags = self.source_config.get('default_tags', [])
if default_tags:
for tag in default_tags:
tags.append({'name': tag})

# Add default_tags from config.
# For consistency with CKANHarvester `default_tags` is now a list of
# dicts, which we can add to tags without further parsing.
tags.extend(self.source_config.get('default_tags', []))

# Adding default_groups from config. This was previously not supported
# by ckanext-spatial.
context = {'model': model, 'user': p.toolkit.c.user}
groups = []
for group_name_or_id in self.source_config.get('default_groups', []):
try:
group = p.toolkit.get_action('group_show')(context, {'id': group_name_or_id})
groups.append({'id': group['id'], 'name': group['name']})
except p.toolkit.ObjectNotFound, e:
logging.error('Default group %s not found, proceeding without.' % group_name_or_id)

package_dict = {
'title': iso_values['title'],
'notes': iso_values['abstract'],
'tags': tags,
'tags': dict((tag['name'], tag) for tag in tags).values(),
'resources': [],
'groups': dict((group['id'], group) for group in groups).values(),
}

# We need to get the owner organization (if any) from the harvest
Expand Down
3 changes: 3 additions & 0 deletions ckanext/spatial/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ def _params_for_solr_spatial_field_search(self, bbox, search_params):
+spatial_geom:"Intersects(ENVELOPE({minx}, {miny}, {maxx}, {maxy}))
'''
if bbox['maxx'] > 180:
bbox['maxx'] = -180 + (bbox['maxx'] - 180)

search_params['fq_list'] = search_params.get('fq_list', [])
search_params['fq_list'].append('+spatial_geom:"Intersects(ENVELOPE({minx}, {maxx}, {maxy}, {miny}))"'
.format(minx=bbox['minx'], miny=bbox['miny'], maxx=bbox['maxx'], maxy=bbox['maxy']))
Expand Down