Skip to main content

Configuration models for Django allowing config management with auditing.

Project description

Part of edX code.

django-config-models CI Codecov

Overview

This app allows other apps to easily define a configuration model that can be hooked into the admin site to allow configuration management with auditing.

Installation

Add config_models to your INSTALLED_APPS list.

Usage

Create a subclass of ConfigurationModel, with fields for each value that needs to be configured:

class MyConfiguration(ConfigurationModel):
    frobble_timeout = IntField(default=10)
    frazzle_target = TextField(defalut="debug")

This is a normal django model, so it must be synced and migrated as usual.

The default values for the fields in the ConfigurationModel will be used if no configuration has yet been created.

Register that class with the Admin site, using the ConfigurationAdminModel:

from django.contrib import admin

from config_models.admin import ConfigurationModelAdmin

admin.site.register(MyConfiguration, ConfigurationModelAdmin)

Use the configuration in your code:

def my_view(self, request):
    config = MyConfiguration.current()
    fire_the_missiles(config.frazzle_target, timeout=config.frobble_timeout)

Use the admin site to add new configuration entries. The most recently created entry is considered to be current.

Configuration

The current ConfigurationModel will be cached in the configuration django cache, or in the default cache if configuration doesn’t exist. The configuration and default caches are specified in the django CACHES setting. The caching can be per-process, per-machine, per-cluster, or some other strategy, depending on the cache configuration.

You can specify the cache timeout in each ConfigurationModel by setting the cache_timeout property.

You can change the name of the cache key used by the ConfigurationModel by overriding the cache_key_name function.

Extension

ConfigurationModels are just django models, so they can be extended with new fields and migrated as usual. Newly added fields must have default values and should be nullable, so that rollbacks to old versions of configuration work correctly.

Documentation

The full documentation is at https://config_models.readthedocs.org.

License

The code in this repository is licensed under the AGPL 3.0 unless otherwise noted.

Please see LICENSE.txt for details.

How To Contribute

Contributions are very welcome.

Please read How To Contribute for details.

Even though they were written with edx-platform in mind, the guidelines should be followed for Open edX code in general.

Reporting Security Issues

Please do not report security issues in public. Please email security@edx.org.

Mailing List and IRC Channel

You can discuss this code in the edx-code Google Group or in the #edx-code IRC channel on Freenode.

Change Log

Unreleased

[2.3.0] - 2022-01-19

  • Added Support for Django40 in CI

  • Dropped Support for Django22, 30, 31

[2.2.2] - 2021-20-12

  • Updated dependencies after removing unnecessary constraint on edx-django-utils, so the constraint will no longer be advertised.

[2.2.1] - 2021-20-12

  • Replaced deprecated ‘django.utils.translation.ugettext’ with ‘django.utils.translation.gettext’

[2.2.0] - 2021-07-14

  • Added support for django3.2

[2.1.2] - 2021-06-24

  • Move out django pin from base.in. Now it is coming from global constraint. Ran make upgrade.

[2.1.1] - 2021-01-28

  • Fix deprecated reference of util.memcache.safe_key

[2.1.0] - 2021-01-12

  • Dropped Python 3.5 Support

[2.0.2] - 2020-05-10

  • Fix html escaping of edit links in admin

[2.0.1] - 2020-05-08

  • Dropped support for Django<2.2

  • Dropped support for python3.6

  • Added support for python3.8

[2.0.0] - 2020-02-06

  • Dropping support for Python 2.7

  • Switch to using edx-django-utils TieredCache (a two-layer cache that uses both Django’s cache and an internal request-level cache) to reduce the number of memcached roundtrips. This was a major performance issue that accounted for 10-20% of transaction time for certain courseware views in edx-platform.

  • It is now REQUIRED to add RequestCacheMiddleware to middleware to use ConfigModels.

  • Remove usage of the “configuration” cache setting. ConfigModels now always use the default Django cache.

  • Django Rest Framework 3.7 and 3.8 are no longer supported.

[1.0.1] - 2019-04-23

  • Fix auto publishing to PyPI

[1.0.0] - 2019-04-23

Changed

  • Unpin django-rest-framework requirements. This is a potentially breaking change if people were relying on this package to ensure the correct version of djangorestframework was being installed.

[0.2.0] - 2018-07-13

Added

  • Support for Python 3.6

Removed

  • Testing against Django 1.8 - 1.10

Changed

  • Updated dependency management to follow OEP-18

[0.1.10] - 2018-05-21

Changed

  • Don’t assume the user model is Django’s default auth.User

[0.1.9] - 2017-08-07

Changed

  • Updated Django REST Framework dependency to 3.6 as we were not actually compatible with 3.2.

[0.1.8] - 2017-06-19

Added

  • Support for Django 1.11.

[0.1.7] - 2017-06-19

  • Unreleased version number

[0.1.6] - 2017-06-01

Added

  • Support for Django 1.10.

[0.1.1] - [0.1.5] - 2017-06-01

Added

  • Add quality testing to travis run.

  • Add encrypted password for package PyPI.

Removed

  • Remove the quality condition on deployment.

  • Remove the version combos known to fail.

Changed

  • Allow for lower versions of djangorestframework, to be compatible with edx-platform.

  • Constrict DRF to version that works.

  • Update versions of requirements via pip-compile.

  • Use different test target - test-all instead of validate.

Fixed

  • Fix name and supported versions.

[0.1.0] - 2016-10-06

Added

  • First release on PyPI.

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-config-models-2.3.0.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_config_models-2.3.0-py2.py3-none-any.whl (29.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-config-models-2.3.0.tar.gz.

File metadata

  • Download URL: django-config-models-2.3.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for django-config-models-2.3.0.tar.gz
Algorithm Hash digest
SHA256 bc61013622c7e8822cb425d12c55b3eece8626f21c856ce6d71726e4432d8828
MD5 bdcbee68e5cc610fb2ea2d86a2bdb0ca
BLAKE2b-256 f8d4e3c497150e5d4b28a768c0d316026927319e313e4aa4b7283ebad236e6f2

See more details on using hashes here.

File details

Details for the file django_config_models-2.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_config_models-2.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for django_config_models-2.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7baa2fe8e6b33a89400904233769c50477f8586efc1c610ddd48acbafe840643
MD5 2e95beaf7b6fd1ca4c8c28ff519565cb
BLAKE2b-256 2f82440b5f4a2942484beefe20b968481e482dc71b2aa3be4eefe12df83bde39

See more details on using hashes here.

Supported by

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