@@ -220,20 +220,15 @@ def create_instance(username, xml_file, media_files,
220
220
existing_instance_count = Instance .objects .filter (
221
221
xml = xml , xform__user = xform .user ).count ()
222
222
223
- if existing_instance_count == 0 :
224
- proceed_to_create_instance = True
225
- else :
223
+ if existing_instance_count > 0 :
226
224
existing_instance = Instance .objects .filter (
227
225
xml = xml , xform__user = xform .user )[0 ]
228
- if existing_instance .xform and \
229
- not existing_instance .xform .has_start_time :
230
- proceed_to_create_instance = True
231
- else :
226
+ if not existing_instance .xform or \
227
+ existing_instance .xform .has_start_time :
232
228
# Ignore submission as a duplicate IFF
233
229
# * a submission's XForm collects start time
234
230
# * the submitted XML is an exact match with one that
235
231
# has already been submitted for that user.
236
- proceed_to_create_instance = False
237
232
raise DuplicateInstance ()
238
233
239
234
# get new and depracated uuid's
@@ -249,12 +244,10 @@ def create_instance(username, xml_file, media_files,
249
244
transaction .commit ()
250
245
raise DuplicateInstance ()
251
246
252
- if proceed_to_create_instance :
253
- instance = save_submission (xform , xml , media_files , new_uuid ,
254
- submitted_by , status ,
255
- date_created_override )
256
- # commit all changes
257
- transaction .commit ()
247
+ instance = save_submission (xform , xml , media_files , new_uuid ,
248
+ submitted_by , status , date_created_override )
249
+ # commit all changes
250
+ transaction .commit ()
258
251
259
252
return instance
260
253
except Exception :
0 commit comments