#NEWLINE# @ classmethod #NEWLINE# def create( cls , data ) : #NEWLINE# #INDENT# "Creates and returns a notification instance.\n\n        :param data: a dict with notification data\n        :returns: a notification instance in case of notification\n            doesn't exist; otherwise - None\n        " #NEWLINE# topic = data . get ( 'topic' ) #NEWLINE# node_id = data . get ( 'node_id' ) #NEWLINE# task_uuid = data . pop ( 'task_uuid' , None ) #NEWLINE# message = data . get ( 'message' ) #NEWLINE# if ( ( topic == 'discover' ) and ( node_id is None ) ) : #NEWLINE# #INDENT# raise errors . CannotFindNodeIDForDiscovering ( 'No node id in discover notification' ) #NEWLINE# #UNINDENT# if ( 'datetime' not in data ) : #NEWLINE# #INDENT# data [ 'datetime' ] = datetime . now ( ) #NEWLINE# #UNINDENT# exist = None #NEWLINE# if task_uuid : #NEWLINE# #INDENT# task = Task . get_by_uuid ( task_uuid ) #NEWLINE# if ( task and node_id ) : #NEWLINE# #INDENT# exist = NotificationCollection . count ( NotificationCollection . filter_by ( None , node_id = node_id , message = message , task_id = task . id ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not exist ) : #NEWLINE# #INDENT# notification = super ( Notification , cls ) . create ( data ) #NEWLINE# logger . info ( 'Notification: topic: {0} message: {1}' . format ( data . get ( 'topic' ) , data . get ( 'message' ) ) ) #NEWLINE# return notification #NEWLINE# #UNINDENT# return None