From a763662cd6fc1477dc3fa867bdaecce0a5ef5b5f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 16 Jul 2018 13:33:00 +0200 Subject: [PATCH] Make sure the EnumField gets an Enum subclass as its parameter --- calsocial/forms.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/calsocial/forms.py b/calsocial/forms.py index 6d6e631..e7adf73 100644 --- a/calsocial/forms.py +++ b/calsocial/forms.py @@ -17,6 +17,8 @@ """Forms for Calendar.social """ +from enum import Enum + from flask_babelex import lazy_gettext as _ from flask_security.forms import LoginForm as BaseLoginForm from flask_wtf import FlaskForm @@ -173,6 +175,9 @@ class TimezoneField(SelectField): class EnumField(SelectField): def __init__(self, enum_type, translations, *args, **kwargs): + if not issubclass(enum_type, Enum): + raise TypeError('enum_type must be a subclass of Enum') + kwargs.update({'choices': [(value, None) for value in enum_type]}) self.data = None self.enum_type = enum_type