wuttasync.app

App handler supplement for WuttaSync

class wuttasync.app.WuttaSyncAppProvider(config)[source]

The app provider for WuttaSync.

This adds some methods to the app handler, which are specific to import/export.

It also declares some email modules and email templates for the app.

We have two concerns when doing lookups etc. for import/export handlers:

  • which handlers are available - i.e. they exist and are discoverable

  • which handlers are designated - only one designated handler per key

All “available” handlers will have a key, but some keys may be referenced by multiple handlers. For each key, only one handler can be “designated” - there is a default, but config can override.

get_all_import_handlers()[source]

Returns all import/export handler classes which are known to exist, i.e. are discoverable.

See also get_import_handler() and get_designated_import_handlers().

The discovery process is as follows:

  • load handlers from registered entry points

  • check config for designated handlers

Checking for designated handler config is not a reliable way to discover handlers, but it’s done just in case any new ones might be found.

Registration via entry points is the only way to ensure a handler is discoverable. The entry point group name is always wuttasync.importing regardless of app name; entries are like "handler_key" = "handler_spec". For example:

[project.entry-points."wuttasync.importing"]
"export.to_csv.from_poser" = "poser.exporting.csv:FromPoserToCsv"
"import.to_poser.from_csv" = "poser.importing.csv:FromCsvToPoser"
Returns:

List of all import/export handler classes

get_designated_import_handler_spec(key, require=False)[source]

Returns the designated import/export handler spec string for the given type key.

This just checks config for the designated handler, using the wuttasync.importing prefix regardless of app name. For instance:

[wuttasync.importing]
export.to_csv.from_poser.handler = poser.exporting.csv:FromPoserToCsv
import.to_poser.from_csv.handler = poser.importing.csv:FromCsvToPoser

See also get_designated_import_handlers() and get_import_handler().

Parameters:
  • key – Unique key indicating the type of import/export handler.

  • require – Flag indicating whether an error should be raised if no handler is found.

Returns:

Spec string for the designated handler. If none is configured, then None is returned unless the require param is true, in which case an error is raised.

get_designated_import_handlers()[source]

Returns all designated import/export handler instances.

Each import/export handler has a “key” which indicates the “type” of import/export job it performs. For instance the CSV → Wutta import has the key: import.to_wutta.from_csv

More than one handler can be defined for that key; however only one such handler will be “designated” for each key.

This method first loads all available import handlers, then organizes them by key, and tries to determine which handler should be designated for each key.

See also get_all_import_handlers() and get_designated_import_handler_spec().

Returns:

List of designated import/export handler instances

get_import_handler(key, require=False, **kwargs)[source]

Returns the designated import/export handler instance for the given import/export key.

See also get_all_import_handlers() and get_designated_import_handlers().

Parameters:
  • key – Key indicating the type of import/export handler, e.g. "import.to_wutta.from_csv"

  • require – Set this to true if you want an error raised when no handler is found.

  • **kwargs – Remaining kwargs are passed as-is to the handler constructor.

Returns:

The import/export handler instance. If no handler is found, then None is returned, unless require param is true, in which case error is raised.