Events

Portal uses and extends the PyDispatcher dispatcher which helps decouple applications by raising signals when actions occur in the Portal Framework, internally these events are known as signals and are similar to the implementation provided by Django.

Portal Vidispine interface signals

When working with the interface to Vidispine several signals are raised so that any registered listener can be notified before and after key events are made to the Vidispine backend.

These signals can be imported from:

  • portal.vidispine.signals.vidispine_pre_create & portal.vidispine.signals.vidispine_post_create

    Sent before or after an object or item is created in Vidispine

  • portal.vidispine.signals.vidispine_pre_modify & portal.vidispine.signals.vidispine_post_modify

    Sent before or after an object is modified or associated to another object in Vidispine

  • portal.vidispine.signals.vidispine_pre_delete & portal.vidispine.signals.vidispine_post_delete

    Sent before or after an object or item is deleted from Vidispine.

  • portal.vidispine.signals.vidispine_pre_get & portal.vidispine.signals.vidispine_post_get

    Sent when a notification on assets is received from Vidispine.

  • portal.vidispine_auto_import_ntfcn

    Sent before or after an object or item is retrieved from Vidispine. This is currently not used in the Portal framework.

For a complete list of signals please see built-in event documentation in the documentation.

Portal DB signals

When changing the internal database tables within Portal we raise signals on the pre-event, post-event state. Please contact us for more details on this if you wish to know about connecting to signals for internal Users, Groups and Roles, or things such as Themes.

Listening to signals

To receive a signal, you need to register a receiver function that gets called when the signal is sent. Because of the way django is loaded, you may need to defer loading of the signals until after your plugin has started. To do that, initiate the signal handler inside a IPluginBootstrap class.

Let’s see how this works by registering a signal that gets called before a user is created. We’ll be connecting to the vidispine_pre_create signal.

def test_vs_precreate(sender, **kwargs):
    print(kwargs)
    print(sender)

class TestPluginBootstrap(Plugin):

    implements(IPluginBootstrap)

    def bootstrap(self):
        from portal.vidispine.iuser import UserHelper
        from portal.vidispine.signals import vidispine_pre_create
        vidispine_pre_create.connect(test_vs_precreate, UserHelper)

TestPluginBootstrap()

Notice that the function takes a sender argument, along with wildcard keyword arguments (**kwargs); all signal handlers must take these arguments.

As the user is created in the UserHelper class, the listener is called whenever a pre_create signal is raised.

For more information on signals please refer to the django documentation https://docs.djangoproject.com/en/1.11/topics/signals/