@@ -31,17 +31,39 @@ def convert_deserialized_civ_data(*, deserialized_civ_data):
3131 """Takes deserialized CIV data and returns list of CIVData objects."""
3232 civ_data_objects = []
3333 for civ in deserialized_civ_data :
34+ if "interface" not in civ :
35+ raise serializers .ValidationError ("An interface must be specified" )
36+
37+ possible_keys = [
38+ "image" ,
39+ "value" ,
40+ "file" ,
41+ "user_upload" ,
42+ "upload_session" ,
43+ ("image_name" , "user_uploads" ),
44+ ]
45+
3446 interface = civ ["interface" ]
3547
3648 keys = set (civ .keys ()) - {"interface" }
3749
50+ if not keys :
51+ raise serializers .ValidationError (
52+ f"You must provide at least one of { possible_keys } ."
53+ )
54+
3855 keys_not_none = {key for key in keys if civ [key ] is not None }
3956
40- if keys_not_none == {"image_name" , "user_uploads" }:
41- value = DICOMUploadWithName (
42- name = civ ["image_name" ],
43- user_uploads = civ ["user_uploads" ],
44- )
57+ if len (keys_not_none ) > 1 :
58+ if keys_not_none == {"image_name" , "user_uploads" }:
59+ value = DICOMUploadWithName (
60+ name = civ ["image_name" ],
61+ user_uploads = civ ["user_uploads" ],
62+ )
63+ else :
64+ raise serializers .ValidationError (
65+ f"You can only provide one of { possible_keys } for each socket."
66+ )
4567 elif not keys_not_none :
4668 value = None
4769 else :
0 commit comments