diff --git a/ckanext/datastore/db.py b/ckanext/datastore/db.py index e4eb48e6704..ff88870ff67 100644 --- a/ckanext/datastore/db.py +++ b/ckanext/datastore/db.py @@ -801,8 +801,8 @@ def delete_data(context, data_dict): def validate(context, data_dict): all_fields = _get_fields(context, data_dict) - all_field_ids = _pluck('id', all_fields) - all_field_ids.insert(0, '_id') + column_names = _pluck('id', all_fields) + column_names.insert(0, '_id') data_dict_copy = copy.deepcopy(data_dict) # TODO: Convert all attributes that can be a comma-separated string to @@ -817,7 +817,7 @@ def validate(context, data_dict): for plugin in p.PluginImplementations(interfaces.IDatastore): data_dict_copy = plugin.datastore_validate(context, data_dict_copy, - all_field_ids) + column_names) # Remove default elements in data_dict del data_dict_copy['connection_url'] @@ -846,8 +846,8 @@ def validate(context, data_dict): def search_data(context, data_dict): validate(context, data_dict) all_fields = _get_fields(context, data_dict) - all_field_ids = _pluck('id', all_fields) - all_field_ids.insert(0, '_id') + column_names = _pluck('id', all_fields) + column_names.insert(0, '_id') query_dict = { 'select': [], @@ -857,7 +857,7 @@ def search_data(context, data_dict): for plugin in p.PluginImplementations(interfaces.IDatastore): query_dict = plugin.datastore_search(context, data_dict, - all_field_ids, query_dict) + column_names, query_dict) where_clause, where_values = _where(query_dict['where']) diff --git a/ckanext/datastore/interfaces.py b/ckanext/datastore/interfaces.py index d605f27d80d..fc2194c0fe8 100644 --- a/ckanext/datastore/interfaces.py +++ b/ckanext/datastore/interfaces.py @@ -4,7 +4,7 @@ class IDatastore(interfaces.Interface): '''Allow modifying Datastore queries''' - def datastore_validate(self, context, data_dict, all_field_ids): + def datastore_validate(self, context, data_dict, column_names): '''Validates the ``data_dict`` sent by the user This is the first method that's called. It's used to guarantee that @@ -29,12 +29,12 @@ def datastore_validate(self, context, data_dict, all_field_ids): :type context: dictionary :param data_dict: the parameters received from the user :type data_dict: dictionary - :param all_field_ids: the current resource's column names - :type all_field_ids: list + :param column_names: the current resource's column names + :type column_names: list ''' return data_dict - def datastore_search(self, context, data_dict, all_field_ids, query_dict): + def datastore_search(self, context, data_dict, column_names, query_dict): '''Modify queries made on datastore_search The overall design is that every IDatastore extension will receive the @@ -79,8 +79,8 @@ def datastore_search(self, context, data_dict, all_field_ids, query_dict): :type context: dictionary :param data_dict: the parameters received from the user :type data_dict: dictionary - :param all_field_ids: the current resource's column names - :type all_field_ids: list + :param column_names: the current resource's column names + :type column_names: list :param query_dict: the current query_dict, as changed by the IDatastore extensions that ran before yours :type query_dict: dictionary @@ -90,7 +90,7 @@ def datastore_search(self, context, data_dict, all_field_ids, query_dict): ''' return query_dict - def datastore_delete(self, context, data_dict, all_field_ids, query_dict): + def datastore_delete(self, context, data_dict, column_names, query_dict): '''Modify queries made on datastore_delete The overall design is that every IDatastore extension will receive the @@ -130,8 +130,8 @@ def datastore_delete(self, context, data_dict, all_field_ids, query_dict): :type context: dictionary :param data_dict: the parameters received from the user :type data_dict: dictionary - :param all_field_ids: the current resource's column names - :type all_field_ids: list + :param column_names: the current resource's column names + :type column_names: list :param query_dict: the current query_dict, as changed by the IDatastore extensions that ran before yours :type query_dict: dictionary diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py index f59d570384c..2755ba279b4 100644 --- a/ckanext/datastore/plugin.py +++ b/ckanext/datastore/plugin.py @@ -271,14 +271,14 @@ def before_show(self, resource_dict): connection.close() return resource_dict - def datastore_validate(self, context, data_dict, all_field_ids): + def datastore_validate(self, context, data_dict, column_names): fields = data_dict.get('fields') if fields: - data_dict['fields'] = list(set(fields) - set(all_field_ids)) + data_dict['fields'] = list(set(fields) - set(column_names)) filters = data_dict.get('filters', {}) for key in filters.keys(): - if key in all_field_ids: + if key in column_names: del filters[key] q = data_dict.get('q') @@ -299,7 +299,7 @@ def datastore_validate(self, context, data_dict, all_field_ids): sort_clauses = data_dict.get('sort') if sort_clauses: invalid_clauses = [c for c in sort_clauses - if not self._is_valid_sort(c, all_field_ids)] + if not self._is_valid_sort(c, column_names)] data_dict['sort'] = invalid_clauses limit = data_dict.get('limit') @@ -319,7 +319,7 @@ def datastore_validate(self, context, data_dict, all_field_ids): return data_dict - def _is_valid_sort(self, clause, all_field_ids): + def _is_valid_sort(self, clause, column_names): clause = clause.encode('utf-8') clause_parts = shlex.split(clause) @@ -332,24 +332,24 @@ def _is_valid_sort(self, clause, all_field_ids): field, sort = unicode(field, 'utf-8'), unicode(sort, 'utf-8') - if field not in all_field_ids: + if field not in column_names: return False if sort.lower() not in ('asc', 'desc'): return False return True - def datastore_delete(self, context, data_dict, all_field_ids, query_dict): - query_dict['where'] += self._where(data_dict, all_field_ids) + def datastore_delete(self, context, data_dict, column_names, query_dict): + query_dict['where'] += self._where(data_dict, column_names) return query_dict - def datastore_search(self, context, data_dict, all_field_ids, query_dict): + def datastore_search(self, context, data_dict, column_names, query_dict): fields = data_dict.get('fields') if fields: field_ids = datastore_helpers.get_list(fields) else: - field_ids = all_field_ids + field_ids = column_names ts_query, rank_column = self._textsearch_query(data_dict) limit = data_dict.get('limit', 100) @@ -370,11 +370,11 @@ def datastore_search(self, context, data_dict, all_field_ids, query_dict): return query_dict - def _where(self, data_dict, all_field_ids): + def _where(self, data_dict, column_names): filters = data_dict.get('filters', {}) clauses = [] for field, value in filters.iteritems(): - if field not in all_field_ids: + if field not in column_names: continue clause = (u'"{0}" = %s'.format(field), value) clauses.append(clause) diff --git a/ckanext/datastore/tests/sample_datastore_plugin.py b/ckanext/datastore/tests/sample_datastore_plugin.py index b090b76ad92..488bbc9ae5e 100644 --- a/ckanext/datastore/tests/sample_datastore_plugin.py +++ b/ckanext/datastore/tests/sample_datastore_plugin.py @@ -6,7 +6,7 @@ class SampleDataStorePlugin(p.SingletonPlugin): p.implements(interfaces.IDatastore, inherit=True) - def datastore_validate(self, context, data_dict, all_field_ids): + def datastore_validate(self, context, data_dict, column_names): valid_filters = ('age_between', 'age_not_between', 'insecure_filter') filters = data_dict.get('filters', {}) for key in filters.keys(): @@ -15,11 +15,11 @@ def datastore_validate(self, context, data_dict, all_field_ids): return data_dict - def datastore_search(self, context, data_dict, all_field_ids, query_dict): + def datastore_search(self, context, data_dict, column_names, query_dict): query_dict['where'] += self._where(data_dict) return query_dict - def datastore_delete(self, context, data_dict, all_field_ids, query_dict): + def datastore_delete(self, context, data_dict, column_names, query_dict): query_dict['where'] += self._where(data_dict) return query_dict