Custom Users + Signals (reusable app)

Showing 1-3 of 3 messages
Custom Users + Signals (reusable app) Val Neekman 10/29/13 6:42 PM

I am to release an app as a reusable app. However, the app makes the use of post_save signals raised by the User model and there is a problem.

With the limitation of a Custom User + Signals in mind, I cannot really call it a "true" reusable app, if it doesn't work for setups that have rolled out their own custom users.

I wonder if anyone has come across the same issue when releasing a "true" reusable app?



Re: Custom Users + Signals (reusable app) charettes 10/29/13 8:10 PM
It is possible to attach signals to `settings.AUTH_USER_MODEL` while taking its swappable nature into account.

There might be a better way but that's how I've done it for a reusable application of mine using the `class_prepared` signal.

The technique involves looking up the model cache by app_label and model (retrieved from splitting `settings.AUTH_USER_MODEL` by '.') and falling back to `class_prepared` if it's not loaded yet. When you have a reference to the model, either through `get_model` or `class_prepared` callback, you can proceed to signal connecting.

It's a shame `class_prepared`'s sender is the model class and not a str of the `app_label.ModelName` form (just like related fields handle deferred reference). I wonder if it could be possible to change its behavior while maintaining backward compatibility by making a `model_class` an instance of a `Signal` subclass instead.

Re: Custom Users + Signals (reusable app) charettes 10/29/13 9:23 PM
Here's a POC which passes all tests on Py2 SQLite.