Implementing a new action¶
Checklist¶
- Add new action signal name to
emails.signals.SignalNameEnumenum. - Define the context TypedDict in
emails.typesmodule. This should be a dictionary with keys and types of values that will be passed to the email template as context. - Define the kwargs TypedDict in
emails.typesmodule. This should be a dictionary with keys and types of values that will be passed to the action's constructor (when the signal for email is being sent). - Define the action class in a new module in
emails.actionspackage. This class should inherit fromBaseActionclass and implement all required methods. - If the action should allow for updating or cancelling, define additional classes
inheriting from
BaseActionUpdateandBaseActionCancelrespectively. -
Create receivers as instances of the action classes. Link the receivers to the appropriate signals in
emails.signalsmodule:receiver = MyAction() signal.connect(receiver) -
If the action consists of scheduling, updating, and cancelling, create
action_strategyandrun_action_strategyfunctions. Follow examples from other actions.
Using a new action¶
If the action contains a strategy, then using it is quite simple:
run_action_strategy(
action_strategy(object),
request,
object,
)
Strategies may accept other parameters, but the selected strategy and request (as in Django view request) are required.
The code above needs to be used in the places where we know user has taken some action (e.g. edited an event) and we want to either trigger a new scheduled email, update existing scheduled email, or cancel such email.