Skip to content

Commit

Permalink
Renamed post_method_decorator_function to post_form_preprocessor.
Browse files Browse the repository at this point in the history
As noted by Jeffrey Finkelstein the original name of `post_method_decorator_function` implies that the function to which it refers decorates the POST method.
  • Loading branch information
Libor Nenadál committed Jun 16, 2012
1 parent dd43122 commit 7a87cad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions flask_restless/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def create_api_blueprint(self, model, methods=READONLY_METHODS,
authentication_function=None,
include_columns=None, validation_exceptions=None,
results_per_page=10,
post_method_decorator_function=None):
post_form_preprocessor=None):
"""Creates an returns a ReSTful API interface as a blueprint, but does
not register it on any :class:`flask.Flask` application.
Expand Down Expand Up @@ -284,7 +284,7 @@ def create_api_blueprint(self, model, methods=READONLY_METHODS,
positive integer, pagination will be disabled (warning: this may result
in large responses). For more information, see :ref:`pagination`.
`post_method_decorator_function` is a callback function which takes
`post_form_preprocessor` is a callback function which takes
POST input parameters loaded from JSON and enhances them with other
key/value pairs. The example use of this is when your ``model``
requires to store user identity and for security reasons the identity
Expand Down Expand Up @@ -337,7 +337,7 @@ def create_api_blueprint(self, model, methods=READONLY_METHODS,
authentication_required_for,
authentication_function, include_columns,
validation_exceptions, results_per_page,
post_method_decorator_function)
post_form_preprocessor)
# suffix an integer to apiname according to already existing blueprints
blueprintname = self._next_blueprint_name(apiname)
# add the URL rules to the blueprint: the first is for methods on the
Expand Down
12 changes: 6 additions & 6 deletions flask_restless/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class API(ModelView):
def __init__(self, session, model, authentication_required_for=None,
authentication_function=None, include_columns=None,
validation_exceptions=None, results_per_page=10,
post_method_decorator_function=None, *args, **kw):
post_form_preprocessor=None, *args, **kw):
"""Instantiates this view with the specified attributes.
`session` is the SQLAlchemy session in which all database transactions
Expand Down Expand Up @@ -420,7 +420,7 @@ def __init__(self, session, model, authentication_required_for=None,
positive integer, pagination will be disabled (warning: this may result
in large responses). For more information, see :ref:`pagination`.
`post_method_decorator_function` is a callback function which takes
`post_form_preprocessor` is a callback function which takes
POST input parameters loaded from JSON and enhances them with other
key/value pairs. The example use of this is when your ``model``
requires to store user identity and for security reasons the identity
Expand Down Expand Up @@ -450,7 +450,7 @@ def __init__(self, session, model, authentication_required_for=None,
self.results_per_page = results_per_page
self.paginate = (isinstance(self.results_per_page, int)
and self.results_per_page > 0)
self.post_method_decorator_function = post_method_decorator_function
self.post_form_preprocessor = post_form_preprocessor

def _add_to_relation(self, query, relationname, toadd=None):
"""Adds a new or existing related model to each model specified by
Expand Down Expand Up @@ -864,9 +864,9 @@ def post(self):
except (TypeError, ValueError, OverflowError):
return jsonify_status_code(400, message='Unable to decode data')

# If post_method_decorator_function is specified, call it
if self.post_method_decorator_function:
params = self.post_method_decorator_function(params)
# If post_form_preprocessor is specified, call it
if self.post_form_preprocessor:
params = self.post_form_preprocessor(params)

# Getting the list of relations that will be added later
cols = _get_columns(self.model)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def test_alternate_primary_key(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(loads(response.data), dict(name='Earth'))

def test_post_method_decorator_function(self):
def test_post_form_preprocessor(self):
"""Tests POST method decoration using a custom function."""
def decorator_function(params):
if params:
Expand All @@ -842,7 +842,7 @@ def decorator_function(params):
# test for function that decorates parameters with 'other' attribute
self.manager.create_api(self.Person, methods=['POST'],
url_prefix='/api/v2',
post_method_decorator_function=decorator_function)
post_form_preprocessor=decorator_function)

response = self.app.post('/api/v2/person',
data=dumps({'name': u'Lincoln', 'age': 23}))
Expand Down

0 comments on commit 7a87cad

Please sign in to comment.