Skip to main content

Reusable app for Django introducing site preferences system

Project description

http://github.com/idlesign/django-siteprefs

https://img.shields.io/pypi/v/django-siteprefs.svg https://img.shields.io/pypi/dm/django-siteprefs.svg https://img.shields.io/pypi/l/django-siteprefs.svg https://img.shields.io/coveralls/idlesign/django-siteprefs/master.svg https://img.shields.io/travis/idlesign/django-siteprefs/master.svg https://landscape.io/github/idlesign/django-siteprefs/master/landscape.svg?style=flat

What’s that

django-siteprefs allows Django applications settings to come alive

Let’s suppose you have your pretty settings.py file with you application:

from django.conf import settings

MY_OPTION_1 = getattr(settings, 'MY_APP_MY_OPTION_1', True)
MY_OPTION_2 = getattr(settings, 'MY_APP_MY_OPTION_2', 'No alien utopia // Will long survive our bravery')
MY_OPTION_42 = getattr(settings, 'MY_APP_MY_OPTION_42', 42)

Now you want these options to be exposed to Django Admin interface:

from django.conf import settings

MY_OPTION_1 = getattr(settings, 'MY_APP_MY_OPTION_1', True)
MY_OPTION_2 = getattr(settings, 'MY_APP_MY_OPTION_2', 'No alien utopia // Will long survive our bravery')
MY_OPTION_42 = getattr(settings, 'MY_APP_MY_OPTION_42', 42)


# To be sure our app is still functional without django-siteprefs
# we use this try-except block.
try:
    from siteprefs.toolbox import patch_locals, register_prefs

    patch_locals()  # This bootstrap is required before `register_prefs` step.

    # And that's how we expose our options to Admin.
    register_prefs(MY_OPTION_1, MY_OPTION_2, MY_OPTION_42)

except ImportError:
    pass

We’re done with the app. Now to your settings.py of your project.

  • Add siteprefs into INSTALLED_APPS;

  • Use siteprefs autodiscover_siteprefs function to locate all the options exposed by apps in your project:

    from siteprefs.toolbox import autodiscover_siteprefs
    
    autodiscover_siteprefs()

Now you can view your settings in Django Admin.

If you want those settings to be editable through the Admin - siteprefs allows that too, and even more.

Read the docs ;)

Documentation

http://django-siteprefs.readthedocs.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-siteprefs-0.6.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

django_siteprefs-0.6.1-py2.py3-none-any.whl (18.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-siteprefs-0.6.1.tar.gz.

File metadata

File hashes

Hashes for django-siteprefs-0.6.1.tar.gz
Algorithm Hash digest
SHA256 5edbb16df435cc1daecf6e686e8322dddedaeb4460fbf7e54b11c733a317280e
MD5 a9f526d8de5d9fc3b1dfeef23522820c
BLAKE2b-256 8d474ce57142256099b7c4739a4256bdd71c784cb70c8266f7ee1115bdfa106a

See more details on using hashes here.

Provenance

File details

Details for the file django_siteprefs-0.6.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_siteprefs-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9e073b5d6ec44e3c94ce3cf9b2ed28aafcfbb59911fd37c98e812f5c988ca016
MD5 9badd9d154160f0c6a5406b32e180ff5
BLAKE2b-256 b36cd472a2a1ed9e7f18104919cf149c8855caa74327046578e824472b0fec9a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page