Skip to main content

Django Preferences

Django app allowing users to set app specific preferences through the admin interface.

https://travis-ci.org/praekelt/django-preferences.svg?branch=develop https://coveralls.io/repos/github/praekelt/django-preferences/badge.svg?branch=develop https://badge.fury.io/py/django-preferences.svg

Provides singleton admin views for Preferences objects and a simple interface to preference values. Singleton views ensure only one preference instance per site is available for each Preferences class.

Requires and supports Django’s “sites” framework, which means you can have multiple preferences, each associated with a particular site.

Requirements

  1. Python 2.7, 3.5-3.7

  2. Django 1.11, 2.0, 2.1

  3. django.contrib.sites

Installation

  1. Install or add django-preferences to your Python path.

  2. Add preferences to your INSTALLED APPS setting.

  3. Add django.contrib.sites to your INSTALLED APPS setting. django-preferences associates preferences to specific sites and thus requires Django’s “sites” framework to be installed.

  4. Optionally, add preferences.context_processors.preferences_cp to your template option settings. This will automatically add a preferences variable to your template context:

    TEMPLATES = [{
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'preferences.context_processors.preferences_cp',
            ],
        },
    }]

Usage

To create preferences for your app create a Django ORM model as usual, with the model inheriting from preferences.models.Preferences. Also specify preferences.models as your model’s module:

from django.db import models
from preferences.models import Preferences

class MyPreferences(Preferences):
    portal_contact_email = models.EmailField()

Admin classes are specified as per usual, except that they have to inherit from or be registered with preferences.admin.PreferencesAdmin, i.e.:

from django.contrib import admin

from preferences.admin import PreferencesAdmin
from <my_app>.models import MyPreferences

admin.site.register(MyPreferences, PreferencesAdmin)

When your model is registered with admin it will show up under the Preferences app label in Django admin.

Preferences can be accessed in Python by importing the preferences module and traversing to your required preference in the form preferences.<ModelName>.<field>, i.e.:

from preferences import preferences

portal_contact_email = preferences.MyPreferences.portal_contact_email

If you’ve specified the preferences.context_processors.preferences_cp as a TEMPLATES you can similarly access your preferences within templates through the preferences variable, i.e.:

{{ preferences.MyPreferences.portal_contact_email }}

Authors

Praekelt Consulting

  • Shaun Sephton

  • Euan Jonker

  • Hedley Roos

Changelog

next

  1. Django 2 and Python 3.5 compatibility. Django 1.9 is no longer supported.

1.0.0 — #. Support Django 1.11, 2.0 & 2.1 remove support for Django < 1.11 #. Support Python 2.7, 3.5-3.7 #. Added tests coverage

0.2

  1. Move to tox for tests.

  2. Django 1.9 to 1.11 support. The official minimum supported version is 1.9.

0.1

  1. Cleanup and fixing of tests courtesy of senyor.

  2. Rewrite distinct query so it works with Oracle backend.

0.0.6

  1. Better packaging.

0.0.5 (2011-08-17)

  1. Added sites support.

  2. Added unittests.

0.0.4 (2011-08-11)

  1. Cleanup. Docs polish.

0.0.3

  1. Spelling correction, thanks tiktuk.

0.0.2

  1. Doc update to indicate importance of placing url include before admin url include.

0.0.1

  1. First super alpha release.

Metadata

Release files for django-preferences 1.0.0

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-preferences 1.0.0
File Size Uploaded Provenance Actions
django-preferences-1.0.0.tar.gz 23.3 kB Without provenance Details for django-preferences-1.0.0.tar.gz

Release files / django-preferences-1.0.0.tar.gz

Download URL django-preferences-1.0.0.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1601c932da2eafb464bfc0ded6d69371d2c610870a7f27c81769a50f8da522e9
BLAKE2b-256 checksum
How to use checksums
1ef78a70ef59880fe4ed36a5cd6255026dcab824287438f69f03b7ba96d28d2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Security for django-preferences 1.0.0

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.

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