]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Cleans up bulk_body generation in quantum.api.v2.base.prepare_request_body()
authorZhongyue Luo <zhongyue.nah@intel.com>
Mon, 24 Dec 2012 07:16:04 +0000 (15:16 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Wed, 2 Jan 2013 13:04:56 +0000 (21:04 +0800)
Defined a lambda function for code readability

Change-Id: Ic538b16d4643e064b222b76af80478161fd3e318

quantum/api/v2/base.py

index de462ac50381a48f07593677aa0802e089929c4b..44d31ec8b4a6a8e3aa1a38dae9c1a9d3bf5ebeea 100644 (file)
@@ -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