Fix attributes processing in ActionMetaclass

ActionMetaclass.__new__() creates a class object twice. At first,
it uses DeclarativeFieldsMetaclass.__new__() only to get a side effect
of gathering form fields to base_fields, and then it uses type.__new__()
to create the resulting class object. Dropping the first created class
object results in ignoring all that DeclarativeFieldsMetaclass.__new__()
does with it (currently, it adds a 'media' attribute).

This change uses the class object returned by
DeclarativeFieldsMetaclass.__new__() adding Meta options to it,
thereby fixing the issue.

Change-Id: Ia4ee0e7187846ea13c04505cbbe7b999c2044871
This commit is contained in:
Alexey Izbyshev 2013-01-18 20:03:27 +04:00
parent 83ac573a9e
commit 0e5179ac33

View File

@ -58,21 +58,20 @@ class WorkflowContext(dict):
class ActionMetaclass(forms.forms.DeclarativeFieldsMetaclass):
def __new__(mcs, name, bases, attrs):
super(ActionMetaclass, mcs).__new__(mcs, name, bases, attrs)
# Process options from Meta
# Pop Meta for later processing
opts = attrs.pop("Meta", None)
attrs['name'] = getattr(opts, "name", name)
attrs['slug'] = getattr(opts, "slug", slugify(name))
attrs['permissions'] = getattr(opts, "permissions", ())
attrs['progress_message'] = getattr(opts,
# Create our new class
cls = super(ActionMetaclass, mcs).__new__(mcs, name, bases, attrs)
# Process options from Meta
cls.name = getattr(opts, "name", name)
cls.slug = getattr(opts, "slug", slugify(name))
cls.permissions = getattr(opts, "permissions", ())
cls.progress_message = getattr(opts,
"progress_message",
_("Processing..."))
attrs['help_text'] = getattr(opts, "help_text", "")
attrs['help_text_template'] = getattr(opts, "help_text_template", None)
# Create our new class!
return type.__new__(mcs, name, bases, attrs)
cls.help_text = getattr(opts, "help_text", "")
cls.help_text_template = getattr(opts, "help_text_template", None)
return cls
class Action(forms.Form):