def __new__(cls, name, bases, attrs):
super_new = super(AccountActionMetaclass, cls).__new__
parents = [base for base in bases if isinstance(base, AccountActionMetaclass)]
if not parents:
# We stop here if we are considering AccountActionBase and not
# one of its subclasses
return super_new(cls, name, bases, attrs)
new_action = super_new(cls, name, bases, attrs)
# Performs some checks
action_name = getattr(new_action, 'name', None)
if action_name is None or not isinstance(action_name, six.string_types):
raise ImproperlyConfigured('The "name" attribute must be a string')
execute_method = getattr(new_action, 'execute', None)
if execute_method is None or \
not (inspect.ismethod(execute_method) or inspect.isfunction(execute_method)):
raise ImproperlyConfigured('The "execute" method must be configured')
return new_action
评论列表
文章目录