<commit_before>from sqlalchemy import event
from nautilus.network import dispatchAction

class CRUDNotificationCreator:

    nautilus_base = True

    @classmethod
    def onCreation(cls):
        # perform the intended behavior
        super().onCreation()
        # add the event listeners
        cls.addEventCreators()

    @classmethod
    def addEventCreators(cls):
        """ Adds the event creators to the class record """

        # on save, send an action with type <model>_created
        @event.listens_for(cls, 'after_insert')
        def dispatchSaveAction(mapper, connection, target):
            """ notifies the network of the new user model """
            dispatchAction({
                'type': 'user_created',
                'payload': target.__json__(),
            })

        # on delete, send an action with type <model>_deleted
        @event.listens_for(cls, 'after_delete')
        def dispatchDeleteAction(mapper, connection, target):
            """ notifies the network of the deleted user model """
            dispatchAction({
                'type': 'user_deleted',
                'payload': target.__json__(),
            })

        # on delete, send an action with type <model>_updated
        @event.listens_for(cls, 'after_update')
        def dispatchUPdateAction(mapper, connection, target):
            """ notifies the network of the updated model """
            dispatchAction({
                'type': 'user_updated',
                'payload': target.__json__(),
            })<commit_msg>cleanup<commit_after># external imports
from sqlalchemy import event
# local imports
from nautilus.network import dispatchAction

class CRUDNotificationCreator:

    nautilus_base = True # required to prevent self-application on creation

    @classmethod
    def dispatch(cls, type, target):
        dispatchAction({
            'type': '{}_{}'.format(cls.__name__.lower(), type),
            'payload': target.__json__(),
        })

    @classmethod
    def addListener(cls, db_event, action_type):
        # on event, dispatch the appropriate action
        @event.listens_for(cls, db_event)
        def dispatchSaveAction(mapper, connection, target):
            """ notifies the network of the new user model """
            cls.dispatch(action_type, target)


    @classmethod
    def onCreation(cls):
        # perform the intended behavior
        super().onCreation()

        cls.addListener('after_insert', 'create_success')
        cls.addListener('after_delete', 'delete_success')
        cls.addListener('after_update', 'update_success')
{'fraction_non_alphanumeric': 0.09799382716049383, 'fraction_numerical': 0.0, 'mean_word_length': 2.4946091644204853, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6613081', 'n_tokens_mistral': 676, 'n_tokens_neox': 652, 'n_words': 191}