10.6.9. Class cerebro.events.BeforeEventChangingOfAttachments

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

Bases: cerebro.events.EventChangingOfAttachments

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



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_ATTACHMENT_HASHTAGS:
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.


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
                tasks = event.messages()
                for message in messages:
                        print('Message name', message.name())
                        print('<Previous activity type', message.activity())
                print('New activity type', event.new_value())                                   
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.Attachment class to define the type.

        attachment_name = event.new_value()
        if attachment_name.isupper() == False:
                new_name = attachment_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