|
22 | 22 | Job, |
23 | 23 | annotate_input_output_counts, |
24 | 24 | ) |
| 25 | +from grandchallenge.cases.widgets import DICOMUploadWithName |
25 | 26 | from grandchallenge.components.backends.exceptions import ( |
26 | 27 | CIVNotEditableException, |
27 | 28 | ) |
@@ -310,35 +311,30 @@ def validate_inputs_and_return_matching_interface(self, *, inputs): |
310 | 311 | @staticmethod |
311 | 312 | def reformat_inputs(*, serialized_civs): |
312 | 313 | """Takes serialized CIV data and returns list of CIVData objects.""" |
313 | | - possible_keys = [ |
314 | | - "image", |
315 | | - "value", |
316 | | - "file", |
317 | | - "user_upload", |
318 | | - "upload_session", |
319 | | - ] |
320 | 314 |
|
321 | 315 | data = [] |
322 | 316 | for civ in serialized_civs: |
323 | | - found_keys = [ |
324 | | - key for key in possible_keys if civ.get(key) is not None |
325 | | - ] |
326 | | - |
327 | | - if not found_keys: |
328 | | - raise serializers.ValidationError( |
329 | | - f"You must provide at least one of {possible_keys}" |
330 | | - ) |
331 | | - |
332 | | - if len(found_keys) > 1: |
333 | | - raise serializers.ValidationError( |
334 | | - f"You can only provide one of {possible_keys} for each interface." |
335 | | - ) |
336 | | - |
| 317 | + interface = civ["interface"] |
| 318 | + upload_session = civ.get("upload_session") |
| 319 | + user_upload = civ.get("user_upload") |
| 320 | + image = civ.get("image") |
| 321 | + value = civ.get("value") |
| 322 | + user_uploads = civ.get("user_uploads") |
| 323 | + image_name = civ.get("image_name") |
| 324 | + dicom_upload_with_name = ( |
| 325 | + DICOMUploadWithName(name=image_name, user_uploads=user_uploads) |
| 326 | + if user_uploads and image_name |
| 327 | + else None |
| 328 | + ) |
337 | 329 | try: |
338 | 330 | data.append( |
339 | 331 | CIVData( |
340 | | - interface_slug=civ["interface"].slug, |
341 | | - value=civ[found_keys[0]], |
| 332 | + interface_slug=interface.slug, |
| 333 | + value=upload_session |
| 334 | + or user_upload |
| 335 | + or image |
| 336 | + or value |
| 337 | + or dicom_upload_with_name, |
342 | 338 | ) |
343 | 339 | ) |
344 | 340 | except ValidationError as e: |
|
0 commit comments