Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 1, 2012
2 parents e2073a3 + 5c63f30 commit 99adf3d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _form_to_db_schema(self, group_type=None):
def _db_to_form_schema(self, group_type=None):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
return lookup_group_plugin(group_type).form_to_db_schema()
return lookup_group_plugin(group_type).db_to_form_schema()

def _setup_template_variables(self, context, data_dict, group_type=None):
return lookup_group_plugin(group_type).\
Expand Down Expand Up @@ -100,7 +100,7 @@ def read(self, id):
group_type = self._get_group_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._form_to_db_schema(group_type=group_type),
'schema': self._db_to_form_schema(group_type=group_type),
'for_view': True, 'extras_as_string': True}
data_dict = {'id': id}
# unicode format (decoded from utf8)
Expand Down
18 changes: 12 additions & 6 deletions ckan/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,6 @@ def history_template(self):
def group_form(self):
return 'group/new_group_form.html'

def form_to_db_schema(self):
return logic.schema.group_form_schema()

def form_to_db_schema_options(self, options):
''' This allows us to select different schemas for different
purpose eg via the web interface or via the api or creation vs
Expand All @@ -366,11 +363,20 @@ def form_to_db_schema_options(self, options):

if options.get('api'):
if options.get('type') == 'create':
return logic.schema.default_group_schema()
return self.form_to_db_schema_api_create()
else:
return logic.schema.default_update_group_schema()
return self.form_to_db_schema_api_update()
else:
return logic.schema.group_form_schema()
return self.form_to_db_schema()

def form_to_db_schema_api_create(self):
return logic.schema.default_group_schema()

def form_to_db_schema_api_update(self):
return logic.schema.default_update_group_schema()

def form_to_db_schema(self):
return logic.schema.group_form_schema()

def db_to_form_schema(self):
'''This is an interface to manipulate data from the database
Expand Down
8 changes: 8 additions & 0 deletions ckan/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ def group_create(context, data_dict):
except AttributeError:
schema = group_plugin.form_to_db_schema()

if 'api_version' not in context:
# old plugins do not support passing the schema so we need
# to ensure they still work
try:
group_plugin.check_data_dict(data_dict, schema)
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'), data_dict.get('name'), data_dict)
Expand Down
8 changes: 8 additions & 0 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ def group_update(context, data_dict):

_check_access('group_update', context, data_dict)

if 'api_version' not in context:
# old plugins do not support passing the schema so we need
# to ensure they still work
try:
group_plugin.check_data_dict(data_dict, schema)
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
log.debug('group_update validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'),
Expand Down

0 comments on commit 99adf3d

Please sign in to comment.