lino.utils.sendchanges

Send an email to a configurable list of addresses when a configurable database item has been changed.

This is deprecated and no longer being tested.

Importing this module will add a receiver to the on_ui_created, on_ui_updated and pre_ui_delete signals.

Usage example:

class Site(Site):
    title = "sendchanges example"

    def do_site_startup(self):
        super(Site, self).do_site_startup()
        from lino.utils.sendchanges import register, subscribe
        register('contacts.Person', 'first_name last_name birth_date',
                 'created_body.eml', 'updated_body.eml')
        e = register('contacts.Partner', 'name',
                     'created_body.eml', 'updated_body.eml')
        e.updated_subject = "Change in partner {master}"
        subscribe('john.doe@example.org')

TODO: Currently it will go through the global list of emiters for each update, create, delete. It would be better to analyze the emitters at startup and install receivers only for the needed models and events.

(This module's source code is available here.)

Functions

find_emitters(obj)

Yield all registered emitters for the given database object.

on_created([sender, request])

on_deleted([sender, request])

on_updated([sender, watcher, request])

register(*args, **kwargs)

Instantiate an Emitter for the given model.

subscribe(addr)

Subscribe the given email address for getting notified about changes.

Classes

Emitter([model, watched_fields, ...])

The object returned by register().

class lino.utils.sendchanges.Emitter(model=None, watched_fields=None, created_tpl=None, updated_tpl=None, deleted_tpl=None, master_field=None)

Bases: object

The object returned by register().

The instantiator takes the following arguments:

model is either a class object or a string with the global name of a model (e.g. 'contacts.Person').

watched_fields is a string with a space-separated list of field names to watch.

master_field can optionally specify a field which points to the "master".

register()

Register this emitter.

get_recipients(**kwargs)

Return the list of recipients. Default is to return the global list.

emit_created(request, obj, **context)

Send "created" mails for the given model instance obj.

emit_updated(request, cw, **context)

Send "updated" mails for the given ChangeWatcher cw.

emit_deleted(request, obj, **context)

Send "deleted" mails for the given model instance obj.

lino.utils.sendchanges.subscribe(addr)

Subscribe the given email address for getting notified about changes.

lino.utils.sendchanges.register(*args, **kwargs)

Instantiate an Emitter for the given model. args and kwargs are forwarded to Emitter.__init__().

lino.utils.sendchanges.find_emitters(obj)

Yield all registered emitters for the given database object.