Skip to main content

Reusable app for Django introducing site preferences system

Project description

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

https://pypip.in/d/django-siteprefs/badge.png

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 some of those options to be exposed to the Django Admin interface.

Let’s say we expose MY_OPTION_1, MY_OPTION_2, MY_OPTION_42 options:

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 projects’ settings.py.

  • 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/

https://d2weczhvl823v0.cloudfront.net/idlesign/django-siteprefs/trend.png

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.2.1.tar.gz (17.8 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-siteprefs-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4bffbdb751a04c54246eaec928c03a92a0bae798833d72ec763b99747f27c2f3
MD5 6f1c6fda440c0dd76fdae474b55062e4
BLAKE2b-256 2f8f5c1a216e2d3b106415061c70d8593159e290638cb404b11e4c1e4d1b250d

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