Skip to content

Commit

Permalink
[#1725] Rename datastore_validate_query() to datastore_validate()
Browse files Browse the repository at this point in the history
The previous name sounded like we were validating the `query_dict`, but we're
actually validating the `data_dict`. I felt `datastore_validate_data_dict()`
would be too big, so `datastore_validate()` seems better.
  • Loading branch information
vitorbaptista committed Jun 10, 2014
1 parent 00943d1 commit 3c38dce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions ckanext/datastore/db.py
Expand Up @@ -791,7 +791,7 @@ def _insert_links(data_dict, limit, offset):


def delete_data(context, data_dict):
validate_query(context, data_dict)
validate(context, data_dict)
fields = _get_fields(context, data_dict)
field_ids = set([field['id'] for field in fields])

Expand All @@ -812,7 +812,7 @@ def delete_data(context, data_dict):
_execute_single_statement(context, sql_string, where_values)


def validate_query(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')
Expand All @@ -825,9 +825,9 @@ def validate_query(context, data_dict):
data_dict_copy['fields'] = fields

for plugin in p.PluginImplementations(interfaces.IDatastore):
data_dict_copy = plugin.datastore_validate_query(context,
data_dict_copy,
all_field_ids)
data_dict_copy = plugin.datastore_validate(context,
data_dict_copy,
all_field_ids)

# Remove default elements in data_dict
del data_dict_copy['connection_url']
Expand All @@ -850,7 +850,7 @@ def validate_query(context, data_dict):


def search_data(context, data_dict):
validate_query(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')
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/interfaces.py
Expand Up @@ -4,7 +4,7 @@
class IDatastore(interfaces.Interface):
'''Allow modifying Datastore queries'''

def datastore_validate_query(self, context, data_dict, all_field_ids):
def datastore_validate(self, context, data_dict, all_field_ids):
'''Validates the ``data_dict`` sent by the user
This is the first method that's called. It's used to guarantee that
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/plugin.py
Expand Up @@ -269,7 +269,7 @@ def before_show(self, resource_dict):
connection.close()
return resource_dict

def datastore_validate_query(self, context, data_dict, all_field_ids):
def datastore_validate(self, context, data_dict, all_field_ids):
fields = data_dict.get('fields')
if fields:
data_dict['fields'] = list(set(fields) - set(all_field_ids))
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/tests/sample_datastore_plugin.py
Expand Up @@ -6,7 +6,7 @@
class SampleDataStorePlugin(p.SingletonPlugin):
p.implements(interfaces.IDatastore, inherit=True)

def datastore_validate_query(self, context, data_dict, all_field_ids):
def datastore_validate(self, context, data_dict, all_field_ids):
valid_filters = ('age_between', 'age_not_between', 'insecure_filter')
filters = data_dict.get('filters', {})
for key in filters.keys():
Expand Down

0 comments on commit 3c38dce

Please sign in to comment.