I am using Pyramid 1.4. I would like to generate some Pyramid custom events from within my model classes. Events are generated as follows:
request.registry.notify(MyCustomEventType("Here it comes"))
As you can see, I need access to the application registry. I know get_current_registry() . But I am also concerned about this comment from the Pyramid website:
"This function should be used extremely sparingly, usually only in a unit test code."
Questions
- Is generating Pyramid events from the data layer (SQLAlchemy models) a generally bad idea?
- If not, how to access the application registry in a more civilized way? (Perhaps an extension of the
Base model?) - If so, is there any alternative I could use. I know SQLAlchemy events, but I could not find the ability to create custom events.
Justification
Basically, I divided my application into functions, and I try to untie them. To do this, I sometimes need IoC: I planned to use events as averages for this. For example, whenever a user answers a question, an event occurs. Then such an event can be signed in other parts of the application. I like to maintain application logic in models, not in views. Therefore, the described problem.
source share