#NEWLINE# @ detail_route ( methods = [ 'post' ] ) #NEWLINE# def update_elements( self , request , pk ) : #NEWLINE# #INDENT# '\n        REST API operation to update projector elements. It expects a POST\n        request to /rest/core/projector/<pk>/update_elements/ with a\n        dictonary to update the projector config. This must be a dictionary\n        with UUIDs as keys and projector element dictionaries as values.\n\n        Example:\n\n        {\n            "191c0878cdc04abfbd64f3177a21891a": {\n                "name": "core/countdown",\n                "stable": true,\n                "status": "running",\n                "countdown_time": 1374321600.0,\n                "visable": true,\n                "default": 42\n            }\n        }\n        ' #NEWLINE# if ( not isinstance ( request . data , dict ) ) : #NEWLINE# #INDENT# raise ValidationError ( { #NEWLINE# #INDENT# 'detail' : 'Data must be a dictionary.' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# error = { #NEWLINE# #INDENT# 'detail' : 'Data must be a dictionary with UUIDs as keys and dictionaries as values.' , #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , value ) in request . data . items ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# uuid . UUID ( hex = str ( key ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValidationError ( projector_instance ) #NEWLINE# #UNINDENT# if ( not isinstance ( value , dict ) ) : #NEWLINE# #INDENT# raise ValidationError ( error ) #NEWLINE# #UNINDENT# #UNINDENT# projector_instance = self . get_object ( ) #NEWLINE# projector_config = projector_instance . config #NEWLINE# for ( key , value ) in request . data . items ( ) : #NEWLINE# #INDENT# if ( key not in projector_config ) : #NEWLINE# #INDENT# raise ValidationError ( { #NEWLINE# #INDENT# 'detail' : 'Invalid projector element. Wrong UUID.' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# projector_config [ key ] . update ( request . data [ key ] ) #NEWLINE# #UNINDENT# serializer = self . get_serializer ( projector_instance , data = { #NEWLINE# #INDENT# 'config' : projector_config , #NEWLINE# #UNINDENT# } , partial = False ) #NEWLINE# serializer . is_valid ( raise_exception = True ) #NEWLINE# serializer . save ( ) #NEWLINE# return Response ( serializer . data )