Pyramid Events Inside Models

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.

+4
source share
1 answer

What is the use case for triggering pyramid events from your models? This would usually be a bad idea.

How to connect the application / model. Most of them are executed when initialize is called in your main (), which passes the model settings to give it connection settings and the like. I would make sure that any logic associated with the union would be limited to this single function call when the application starts.

In the end, although I would imagine what you want, it's better to do it differently.

+1
source

All Articles