Just watched a video about something completely irrelevant to what i'm about to talk about but the video talked about habits which consist of triggers and action (and rewards).
I think the idea of triggers
and actions
. This is just a thought but I'm thinking of having a structure maybe like:
app/
triggers/
SendMailTrigger.py
and SendMailTrigger.py might look something like:
from app.User import User
class SendMailTrigger(object):
def __init__(self):
pass
def action(self, obj):
obj.sendMail()
User.updateSomething()
def anotherAction(self, obj, anotherObj):
obj.sendWelcomeMail()
User.updateSomethingElse()
These classes can be "triggered" by doing something like:
Registering them inside config/triggers.py
TRIGGERS = {
'someAction' = 'path.to.module.class'
}
from masonite.helpers import trigger
# goes to the dashboard page
class DashboardController(object):
....
def show(self, request):
... do some code ...
obj = SomeObject()
# Will default to the `action` method
trigger('someAction', obj)
trigger('someAction@anotherAction', obj, secondObj)
This will come in the form of an addon with a publish command
The Setup
The setup should look something like:
$ pip install triggers
$ craft publish triggers
craft publish will create or append the config file for you as well as create a default trigger inside app/triggers/DefaultTrigger.py
as well as come with a new craft-vendor triggers create
command.
All you'll need to do is add any classes you want to trigger inside the TRIGGERS
config and then use the trigger
function wherever you want.