Skip to content

Commit

Permalink
[#2204] Add option to create views on particular datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Feb 17, 2015
1 parent 18cef33 commit 855f6af
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions ckan/lib/cli.py
Expand Up @@ -2192,22 +2192,28 @@ def __init__(self, name):
help='''Automatic yes to prompts. Assume "yes"
as answer to all prompts and run non-interactively''')

self.parser.add_option('-d', '--no-default-filters',
self.parser.add_option('-d', '--dataset', dest='dataset_id',
action='append',
help='''Create views on a particular dataset.
You can use the dataset id or name, and it can be defined multiple times.''')

self.parser.add_option('--no-default-filters',
dest='no_default_filters',
action='store_true',
default=False,
help='''Do not add default filters for relevant
resource formats for the view types provided. Note that filters are not added
by default anyway if an unsupported view type is provided or when using the
`-s` or `--search` options.''')
`-s` or `-d` options.''')

self.parser.add_option('-s', '--search', dest='search_params',
action='store',
default=False,
help='''Extra search parameters that will be
used for getting the datasets to create the resource views on. It must be a
JSON object like the one used by the `package_search` API call. Supported
fields are `q`, `fq` and `fq_list`. Check the documentation for examples.''')
fields are `q`, `fq` and `fq_list`. Check the documentation for examples.
Not used when using the `-d` option.''')

def command(self):
self._load_config()
Expand Down Expand Up @@ -2384,12 +2390,20 @@ def _search_datasets(self, page=1, view_types=[]):
}

if (not self.options.no_default_filters and
not self.options.search_params):
not self.options.search_params and
not self.options.dataset_id):
self._add_default_filters(search_data_dict, view_types)

if self.options.search_params:
if (self.options.search_params and
not self.options.dataset_id):
self._update_search_params(search_data_dict)

if self.options.dataset_id:
search_data_dict['q'] = ' OR '.join(
['id:{0} OR name:"{0}"'.format(dataset_id)
for dataset_id in self.options.dataset_id]
)

if not search_data_dict.get('q'):
search_data_dict['q'] = '*:*'

Expand Down

0 comments on commit 855f6af

Please sign in to comment.