10.6.12. Class cerebro.events.BeforeEventChangingOfMessages

class cerebro.events.BeforeEventChangingOfMessages(event_type, event_id)[source]

Bases: cerebro.events.EventChangingOfMessages

The class for message properties change - for a single message or several messages at once. It grants access to the data of the modified messages before writing it into the database.

Methods

Warning

this class is used to handle the changes of most part of the properties, but not all of them. In order to handle, for example, tag modifying, some other classes should be used. See the complete list of event classes.

The class object is input into the functions before_event and error_event (in case of error) of the module event.

def before_event(event):        
        if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_APPROVED:
                ...
new_value()[source]
Returns:a new value of the property undergoing changing.

The type of the returning value depends on the Property being changed. Check the methods on getting the values of similar properties of the cerebro.aclasses.Message class to define the type.

Note

Use the corresponding methods of the tasks being edited messages() to find out the current values.

def before_event(event):        
        if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS: # activity type is being changed
        
                messages = event.messages()
                for message in messages:
                        print('Message name', message.name())
                        print('<Previous activity type', message.activity())
                
                print('New activity type', event.new_value())                                   
set_new_value(val)[source]
Parameters:val – parameter value.

Sets a new value of the property being changed.

The type of the new value depends on the property being changed. Check the methods of setting up similar properties of the cerebro.aclasses.Message class to define the type.

if event.type() == event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS:
        message_name = event.new_value()
        if task_name.isupper() == False:
                new_name = task_name.upper() # changing the symbols to the upper register
                event.set_new_value(new_name) # substituting the value entered by user for the new one