From: Zhongyue Luo Date: Mon, 24 Dec 2012 07:16:04 +0000 (+0800) Subject: Cleans up bulk_body generation in quantum.api.v2.base.prepare_request_body() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=412a5c8b03523bf35eaa07d4616f1b823273ea80;p=openstack-build%2Fneutron-build.git Cleans up bulk_body generation in quantum.api.v2.base.prepare_request_body() Defined a lambda function for code readability Change-Id: Ic538b16d4643e064b222b76af80478161fd3e318 --- diff --git a/quantum/api/v2/base.py b/quantum/api/v2/base.py index de462ac50..44d31ec8b 100644 --- a/quantum/api/v2/base.py +++ b/quantum/api/v2/base.py @@ -460,23 +460,22 @@ class Controller(object): if not body: raise webob.exc.HTTPBadRequest(_("Resource body required")) - body = body or {resource: {}} - if collection in body and allow_bulk: - bulk_body = [Controller.prepare_request_body( - context, {resource: b}, is_create, resource, attr_info, - allow_bulk) if resource not in b - else Controller.prepare_request_body( - context, b, is_create, resource, attr_info, allow_bulk) - for b in body[collection]] - + prep_req_body = lambda x: Controller.prepare_request_body( + context, + x if resource in x else {resource: x}, + is_create, + resource, + attr_info, + allow_bulk) + if collection in body: + if not allow_bulk: + raise webob.exc.HTTPBadRequest(_("Bulk operation " + "not supported")) + bulk_body = [prep_req_body(item) for item in body[collection]] if not bulk_body: raise webob.exc.HTTPBadRequest(_("Resources required")) - return {collection: bulk_body} - elif collection in body and not allow_bulk: - raise webob.exc.HTTPBadRequest("Bulk operation not supported") - res_dict = body.get(resource) if res_dict is None: msg = _("Unable to find '%s' in request body") % resource