Skip to main content

Django appregister

https://secure.travis-ci.org/saltstack/salt.png?branch=develop

Django appregister is a building blocks app to implement a class registry system for your django app. It uses a similar approach to the Django admin, allowing you to register classes and supports an autodiscover feature.

A registry system that provides a good base for making an app plugable and extendable by third parties as they can register their own subclasses for Use within the main code base.

Installation

Use pip:

pip install django-appregister

Quick Example Usage

First, you should create your base class that all registered classes must be a subclass of. Often this is a base Model class in your models.py or it can be anywhere in your project:

>>> class AppPlugin(object):
...     pass

Then you need to create your own registry, the base can either be a class, or a dotted string that points to the base class, such as "myapp.AppPlugin". After that, you can go ahead and create an instance of the registry - creating it at the module level makes it easy to re-use across the project but you can have as many instances as you need. It’s good practice to create your registry in its own module, such as myapp/register.py:

>>> from appregister import Registry

>>> class MyRegistry(Registry):
...     base = AppPlugin
...     discovermodule = 'plugins'

>>> plugins = MyRegistry()

Now that you have the registry, you can start to add subclasses to it. This can be done by using the class decorator on your register:

>>> @plugins.register
... class MyPlugin(AppPlugin):
...     pass

Note, If you are using version 2.5 or below of Python you can’t use the class based decorator, you will need to call it manually. The above example would then become:

>>> class MySecondPlugin(AppPlugin):
...     pass
>>> plugins.register(MySecondPlugin)
<class 'MySecondPlugin'>

Registering an invalid object will raise an InvalidOperation exception:

>>> # Note that this class does not inherit from the base we specified.
>>> class MyNonSubclass(object):
...     pass

>>> plugins.register(MyNonSubclass)
Traceback (most recent call last):
    ...
InvalidOperation: Object 'MyNonSubclass' is not a subclass of 'AppPlugin'

Finally, now you can get all your objects back - this includes those registered by a third party:

>>> len(plugins)
2

>>> for plugin in plugins:
...     print plugin
<class 'MySecondPlugin'>
<class 'MyPlugin'>

The order of registration is not stored. Since we can’t tell what order they would be registered, if you want a sorted set you will need to sort them after they have all been registered:

>>> plugins.clear()
>>> len(plugins)
0

Metadata

Release files for django-appregister 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-appregister 0.3.1
File Size Uploaded Provenance Actions
django-appregister-0.3.1.tar.gz 7.7 kB Without provenance Details for django-appregister-0.3.1.tar.gz

Release files / django-appregister-0.3.1.tar.gz

Download URL django-appregister-0.3.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7642f166b9e864b37059927c426518fb971fa36d47274f412e2c06fa72b15d91
BLAKE2b-256 checksum
How to use checksums
8e45b669c9e2e5b04132d99f0e6dab5c98b4a2a8aca498f61689e2857b85a529
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-appregister 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page