Rollback the "always_return_data" and code cleanup in project copy API
authordurandn
Mon, 20 Jul 2015 19:12:18 +0200
changeset 1406 de1b8dfbb637
parent 1405 1878f6371f87
child 1407 fc9654218d53
Rollback the "always_return_data" and code cleanup in project copy API
src/ldt/ldt/api/ldt/resources/project.py
--- a/src/ldt/ldt/api/ldt/resources/project.py	Mon Jul 20 18:38:38 2015 +0200
+++ b/src/ldt/ldt/api/ldt/resources/project.py	Mon Jul 20 19:12:18 2015 +0200
@@ -12,6 +12,7 @@
 from tastypie.exceptions import BadRequest
 from tastypie.resources import Bundle, ModelResource, ALL
 from tastypie.utils import dict_strip_unicode_keys
+from distutils.util import strtobool
 
 from ldt.api.ldt.authentication import (SessionAuthentication,
     MultiAuthentication, ApiKeyAuthentication)
@@ -39,8 +40,7 @@
             'state' : ALL,
             'ldt_id' : ALL,
             'title' : ALL
-        },
-        always_return_data = True
+        }
         # In the future version :
         # detail_uri_name = 'ldt_id'
     
@@ -81,11 +81,12 @@
             try: 
                 source_proj = Project.objects.get(ldt_id=bundle.data['source'])
             except ObjectDoesNotExist:
-                return http.HttpNotFound("A model instance matching the provided arguments could not be found.")
+                raise BadRequest("Source project could not be found")
+            publish_bool = False
             if check_object_perm_for_user(source_proj, "change_project", request.user):
                 bundle.data["title"] = bundle.data.get("title", source_proj.title)
                 bundle.data["description"] = bundle.data.get("description", source_proj.description)
-                publish_bool = {'true': True, 'false': False, "0": False, "1": True}.get(bundle.data.get('publish', 'false').lower())
+                publish_bool = bool(strtobool(bundle.data.get('publish', 'false').lower()))
             else:
                 raise BadRequest("User has no right to change the project.")
             bundle.obj = source_proj.copy_project(user=request.user, title=bundle.data["title"], description=bundle.data["description"])