@@ -51,87 +51,6 @@ def post_api_objects_drafts_create(request):
5151 # Since bulk_request is an array, go over each
5252 # item in the array.
5353
54- if len (bulk_request ) == 1 :
55- creation_object = bulk_request [0 ]
56- standardized = creation_object ['prefix' ].upper ()
57- if 'add_' + standardized in prefix_perms and \
58- 'draft_' + standardized in prefix_perms :
59- if Group .objects .filter (
60- name = creation_object ['owner_group' ].lower ()).exists ():
61- constructed_name = object_naming_info ['uri_regex' ].replace (
62- 'root_uri' ,
63- object_naming_info ['root_uri' ]
64- )
65- constructed_name = constructed_name .replace ('prefix' , standardized )
66- prefix_location = constructed_name .index (standardized )
67- prefix_length = len (standardized )
68- constructed_name = constructed_name [0 :prefix_location + prefix_length ]
69- prefix_counter = prefix_table .objects .get (prefix = standardized )
70- creation_object ['object_id' ] = constructed_name + '_' + \
71- '{:06d}' .format (prefix_counter .n_objects ) + '/DRAFT'
72-
73- creation_object ['contents' ]['object_id' ] = creation_object ['object_id' ]
74- bco_id = creation_object ['object_id' ]
75- owner_group = Group .objects .get (name = creation_object ['owner_group' ])
76- creation_object ['owner_group' ] = owner_group .name
77- creation_object ['owner_user' ] = user .username
78- creation_object ['prefix' ] = standardized
79- creation_object ['state' ] = 'DRAFT'
80- creation_object ['last_update' ] = timezone .now ()
81- objects_written = db_utils .write_object (
82- p_app_label = 'api' ,
83- p_model_name = 'BCO' ,
84- p_fields = [
85- 'contents' ,
86- 'last_update' ,
87- 'object_id' ,
88- 'owner_group' ,
89- 'owner_user' ,
90- 'prefix' ,
91- 'schema' ,
92- 'state' ],
93- p_data = creation_object
94- )
95- prefix_counter .n_objects = prefix_counter .n_objects + 1
96- prefix_counter .save ()
97-
98- if objects_written < 1 :
99- # Issue with writing out to DB
100- return Response (
101- status = status .HTTP_400_BAD_REQUEST ,
102- data = 'The request could not be processed with the' \
103- ' parameters provided.'
104- )
105-
106- return Response (
107- status = status .HTTP_201_CREATED ,
108- data = {
109- 'request_status' : 'SUCCESS' ,
110- 'status_code' : '201' ,
111- 'message' : f'The object with ID { bco_id } was' \
112- ' created on the server.' ,
113- 'object_id' : bco_id
114- },
115- )
116-
117- else :
118- # Update the request status.
119- returning .append (db_utils .messages (parameters = {})
120- ['400_bad_request' ])
121- any_failed = True
122-
123- else :
124- # Update the request status.
125- return Response (
126- status = status .HTTP_401_UNAUTHORIZED ,
127- data = {
128- 'request_status' : 'FAILURE' ,
129- 'status_code' : '401' ,
130- 'message' : 'The token provided does not have draft' \
131- f'permissions for prefix { standardized } .'
132- }
133- )
134-
13554 for creation_object in bulk_request :
13655 # Standardize the prefix.
13756 standardized = creation_object ['prefix' ].upper ()
@@ -245,6 +164,6 @@ def post_api_objects_drafts_create(request):
245164 any_failed = True
246165
247166 if any_failed :
248- return Response (status = status .HTTP_300_MULTIPLE_CHOICES , data = returning )
167+ return Response (status = status .HTTP_207_MULTI_STATUS , data = returning )
249168
250169 return Response (status = status .HTTP_200_OK , data = returning )
0 commit comments