Make sure the EnumField gets an Enum subclass as its parameter

This commit is contained in:
Gergely Polonkai 2018-07-16 13:33:00 +02:00
parent 41b4b9d7ea
commit a763662cd6

View File

@ -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