Use django-djconfig for kfet app.

Old configuration(/settings), based on Settings model, system is
deleted: SettingsForm, Settings.
New system use `django-djconfig` module.

- `kfet.config` module provides `kfet_config` to access configuration concerning
kfet app.
- Views, forms, models, etc now use this object to retrieve conf values.
- Views no longer add config values to context, instead templates use
  `kfet_config` provided by a new context_processor.
- Enhance list and update views of settings.
- Fix: settings can directly be used without having to visit a specific
  page...

Misc
- Delete some py2/3 imports
- Delete unused imports in kfet.models and kfet.views
- Some PEP8 compliance
This commit is contained in:
Aurélien Delobelle 2017-04-03 20:32:16 +02:00
parent a4a854bc50
commit 85caa6b058
16 changed files with 247 additions and 227 deletions

25
kfet/config.py Normal file
View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from djconfig import config
class KFetConfig(object):
"""kfet app configuration.
Enhance dependency with backend used to store config.
Usable after DjConfig middleware was called.
"""
prefix = 'kfet_'
def __getattr__(self, key):
dj_key = '{}{}'.format(self.prefix, key)
return getattr(config, dj_key)
def list(self):
from kfet.forms import KFetConfigForm
return [(field.label, getattr(config, name), )
for name, field in KFetConfigForm.base_fields.items()]
kfet_config = KFetConfig()