def json_post_required(*decorator_args):
def decorator(method):<EOL><INDENT>@wraps(method)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>field = decorator_args[<NUM_LIT:0>]<EOL>if len(decorator_args) == <NUM_LIT:2>:<EOL><INDENT>request_name = decorator_args[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>request_name = field<EOL><DEDENT>request = args[<NUM_LIT:0>]<EOL>if request.method != '<STR_LIT:POST>':<EOL><INDENT>logger.error('<STR_LIT>')<EOL>raise Http404('<STR_LIT>')<EOL><DEDENT>if field not in request.POST:<EOL><INDENT>s = '<STR_LIT>' % field<EOL>logger.error(s)<EOL>raise Http404(s)<EOL><DEDENT>setattr(request, request_name, json.loads(request.POST[field]))<EOL>return method(*args, **kwargs)<EOL><DEDENT>return wrapper<EOL><DEDENT>return decorator<EOL>
View decorator that enforces that the method was called using POST and
    contains a field containing a JSON dictionary. This method should
    only be used to wrap views and assumes the first argument of the method
    being wrapped is a ``request`` object.

    .. code-block:: python

        @json_post_required('data', 'json_data')
        def some_view(request):
            username = request.json_data['username']

    :param field:
        The name of the POST field that contains a JSON dictionary
    :param request_name:
        [optional] Name of the parameter on the request to put the
        deserialized JSON data. If not given the field name is used