From ee0980a99fe599756b5ab833327cafc6047fd3a9 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 21 Nov 2014 20:29:11 +0100 Subject: [PATCH] Raise an exception if an unsupported config type is used. This is in response to #54 and #66. --- constance/admin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/constance/admin.py b/constance/admin.py index d1e5eaa..3b564e7 100644 --- a/constance/admin.py +++ b/constance/admin.py @@ -7,7 +7,7 @@ from django import forms from django.contrib import admin, messages from django.contrib.admin import widgets from django.contrib.admin.options import csrf_protect_m -from django.core.exceptions import PermissionDenied +from django.core.exceptions import PermissionDenied, ImproperlyConfigured from django.forms import fields from django.http import HttpResponseRedirect from django.shortcuts import render_to_response @@ -57,7 +57,13 @@ class ConstanceForm(forms.Form): def __init__(self, *args, **kwargs): super(ConstanceForm, self).__init__(*args, **kwargs) for name, (default, help_text) in settings.CONFIG.items(): - field_class, kwargs = FIELDS[type(default)] + config_type = type(default) + if config_type not in FIELDS: + raise ImproperlyConfigured("Constance doesn't support " + "config values of the type %s. " + "Please fix the value of '%s'." + % (config_type, name)) + field_class, kwargs = FIELDS[config_type] self.fields[name] = field_class(label=name, **kwargs) def save(self):