Handler Configuration¶
Typically there is a config setting for each type of handler, the value of which may be set to the spec of the desired handler class. The setting name pattern may vary somewhat; there is not a strict convention.
The app handler will have a method to do the config lookup. It should define a default/fallback spec in case nothing is explicitly configured.
So to configure the handler, you must first determine the required setting name, then set the value. This may be done in one of four ways:
Via Settings Table¶
Create or edit the setting by name (e.g. via web app), and set value to the desired spec. Some example setting names:
wutta.auth.handlerwutta.email.handler
This is (usually) the “preferred” setting which takes priority over the others below.
In some cases, the web app may expose a dedicated config UI, where you can simply choose the preferred handler from a dropdown. But under the hood it’s writing a settings table record.
Via Config File¶
Technically the syntax here can vary, but convention is to give each aspect of the app a separate config section. For instance:
[wutta.auth]
handler = wuttjamaican.auth:AuthHandler
[wutta.email]
handler = wuttjamaican.email:EmailHandler
Config files are (usually) given lower priority than the settings table, so if you customize here it is still possible for the settings table to override it (i.e. if the setting exists there).
That can potentially lead to confusion if values exist in both places, so probably config file should only be used for settings which are unlikely to be added to the DB.
Via Config Extension¶
If you have defined a config extension then you can set default values within that:
from wuttjamaican.conf import WuttaConfigExtension
class PoserConfigExtension(WuttaConfigExtension):
key = "poser"
def configure(self, config):
config.setdefault("wutta.auth.handler", "poser.auth:PoserAuthHandler")
config.setdefault("wutta.email.handler", "poser.email:PoserEmailHandler")
This can still be overridden via config file or settings table, but it makes clear which handler the app itself considers to be the preferred default. Can be very useful in many cases.
One caveat is that only one such config.setdefault() call will
actually take effect, for any given setting name. So if multiple
config extensions try to do this for the same setting, results are
indeterminate.
Via App Handler¶
If you are using a custom app handler, you can explicitly override the default/fallback spec:
from wuttjamaican.app import AppHandler
class PoserAppHandler(AppHandler):
default_auth_handler_spec = "poser.auth:PoserAuthHandler"
default_email_handler_spec = "poser.email:PoserEmailHandler"
This is probably most useful for packages which aim to be both an app as well as a framework, so to speak. The advantage here is that a subsequent app (e.g. built atop Poser, in this example) can inherit the default handler customization, but can still override their effective defaults via the config extension method (and/or config file, settings table).