2015-05-04 19:52:53 +00:00
|
|
|
from django.apps import AppConfig
|
|
|
|
from django.core.checks import register, Error
|
|
|
|
from django.core.exceptions import ValidationError
|
2015-05-19 13:27:04 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2015-05-07 14:09:37 +00:00
|
|
|
|
|
|
|
from orchestra.core import administration
|
2015-05-04 19:52:53 +00:00
|
|
|
|
|
|
|
from . import Setting
|
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
|
2015-05-04 19:52:53 +00:00
|
|
|
class SettingsConfig(AppConfig):
|
|
|
|
name = 'orchestra.contrib.settings'
|
|
|
|
verbose_name = 'Settings'
|
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
def ready(self):
|
2015-05-07 14:18:09 +00:00
|
|
|
administration.register_view('settings_setting_change', verbose_name=_("Setting"),
|
|
|
|
verbose_name_plural=_("Settings"),
|
2015-05-07 14:09:37 +00:00
|
|
|
icon='Multimedia-volume-control.png')
|
|
|
|
|
2015-05-04 19:52:53 +00:00
|
|
|
@register()
|
|
|
|
def check_settings(app_configs, **kwargs):
|
|
|
|
""" perfroms all the validation """
|
|
|
|
messages = []
|
|
|
|
for name, setting in Setting.settings.items():
|
|
|
|
try:
|
2015-10-03 14:35:34 +00:00
|
|
|
setting.validate()
|
2015-05-04 19:52:53 +00:00
|
|
|
except ValidationError as exc:
|
2015-10-03 14:35:34 +00:00
|
|
|
msg = "Error validating setting with value %s: %s" % (setting.value, exc)
|
2015-05-04 19:52:53 +00:00
|
|
|
messages.append(Error(msg, obj=name, id='settings.E001'))
|
|
|
|
return messages
|