Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #274 from alphagov/add-deprecation-warning
Browse files Browse the repository at this point in the history
Add deprecation warning for write API by name
  • Loading branch information
robyoung committed Apr 30, 2014
2 parents 288db2d + 962c971 commit 84ac2a6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions backdrop/write/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ def write_by_group(data_group, data_type):
@app.route('/<data_set:data_set_name>', methods=['POST'])
@cache_control.nocache
def post_to_data_set(data_set_name):
app.logger.warning("Deprecated use of write API by name: {}".format(
data_set_name))
data_set_config = data_set_repository.retrieve(name=data_set_name)
return _write_to_data_set(data_set_config)
return _write_to_data_set(
data_set_config,
ok_message="Deprecation Warning: accessing by data-set name is "
"deprecated, Please use the /data-group/data-type form.")


@app.route('/data-sets/<dataset_name>', methods=['POST'])
Expand Down Expand Up @@ -153,7 +158,7 @@ def _allow_create_collection(auth_header):
return _allow_modify_collection(auth_header)


def _write_to_data_set(data_set_config):
def _write_to_data_set(data_set_config, ok_message=None):
if data_set_config is None:
return jsonify(status="error",
message='Could not find data_set_config'), 404
Expand All @@ -175,8 +180,11 @@ def _write_to_data_set(data_set_config):

data_set = DataSet(db, data_set_config)
data_set.parse_and_store(data)
if ok_message:
return jsonify(status='ok', message=ok_message)
else:
return jsonify(status='ok')

return jsonify(status='ok')
except (ParseError, ValidationError) as e:
return jsonify(status="error", message=str(e)), 400

Expand Down

0 comments on commit 84ac2a6

Please sign in to comment.