@@ -193,6 +193,24 @@ def validate_file(self, file):
193193 return file
194194
195195
196+ # NOTE: Separate serializer for partial updating EAPFile instance
197+ class EAPFileUpdateSerializer (BaseEAPSerializer ):
198+ id = serializers .IntegerField (required = True )
199+ file = serializers .FileField (required = False )
200+
201+ class Meta :
202+ model = EAPFile
203+ fields = "__all__"
204+ read_only_fields = (
205+ "created_by" ,
206+ "modified_by" ,
207+ )
208+
209+ def validate_file (self , file ):
210+ validate_file_type (file )
211+ return file
212+
213+
196214ALLOWED_MAP_TIMEFRAMES_VALUE = {
197215 OperationActivity .TimeFrame .YEARS : list (OperationActivity .YearsTimeFrameChoices .values ),
198216 OperationActivity .TimeFrame .MONTHS : list (OperationActivity .MonthsTimeFrameChoices .values ),
@@ -286,35 +304,35 @@ class SimplifiedEAPSerializer(
286304 enable_approaches = EnableApproachSerializer (many = True , required = False )
287305
288306 # FILES
289- cover_image_details = EAPFileSerializer (source = "cover_image" , read_only = True )
290- hazard_impact_file_details = EAPFileSerializer (source = "hazard_impact_file " , many = True , read_only = True )
291- selected_early_actions_file_details = EAPFileSerializer (source = "selected_early_actions_file " , many = True , read_only = True )
292- risk_selected_protocols_file_details = EAPFileSerializer (source = "risk_selected_protocols_file " , many = True , read_only = True )
307+ cover_image_file = EAPFileUpdateSerializer (source = "cover_image" , required = False , allow_null = True )
308+ hazard_impact_images_details = EAPFileSerializer (source = "hazard_impact_images " , many = True , read_only = True )
309+ selected_early_actions_file_details = EAPFileSerializer (source = "selected_early_actions_images " , many = True , read_only = True )
310+ risk_selected_protocols_file_details = EAPFileSerializer (source = "risk_selected_protocols_images " , many = True , read_only = True )
293311
294312 # Admin2
295313 admin2_details = Admin2Serializer (source = "admin2" , many = True , read_only = True )
296314
297315 class Meta :
298316 model = SimplifiedEAP
299- fields = "__all__"
300317 read_only_fields = [
301318 "version" ,
302319 "is_locked" ,
303320 ]
321+ exclude = ("cover_image" ,)
304322
305- def validate_hazard_impact_file (self , images ):
323+ def validate_hazard_impact_images (self , images ):
306324 if images and len (images ) > self .MAX_NUMBER_OF_IMAGES :
307325 raise serializers .ValidationError (f"Maximum { self .MAX_NUMBER_OF_IMAGES } images are allowed to upload." )
308326 validate_file_type (images )
309327 return images
310328
311- def validate_risk_selected_protocols_file (self , images ):
329+ def validate_risk_selected_protocols_images (self , images ):
312330 if images and len (images ) > self .MAX_NUMBER_OF_IMAGES :
313331 raise serializers .ValidationError (f"Maximum { self .MAX_NUMBER_OF_IMAGES } images are allowed to upload." )
314332 validate_file_type (images )
315333 return images
316334
317- def validate_selected_early_actions_file (self , images ):
335+ def validate_selected_early_actions_images (self , images ):
318336 if images and len (images ) > self .MAX_NUMBER_OF_IMAGES :
319337 raise serializers .ValidationError (f"Maximum { self .MAX_NUMBER_OF_IMAGES } images are allowed to upload." )
320338 validate_file_type (images )
0 commit comments