mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
[py3] Used six.with_metaclass wherever necessary.
This commit is contained in:
@@ -14,6 +14,7 @@ from django.utils.datastructures import SortedDict
|
||||
from django.utils.html import conditional_escape, format_html
|
||||
from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils import six
|
||||
|
||||
|
||||
__all__ = ('BaseForm', 'Form')
|
||||
@@ -380,14 +381,13 @@ class BaseForm(StrAndUnicode):
|
||||
"""
|
||||
return [field for field in self if not field.is_hidden]
|
||||
|
||||
class Form(BaseForm):
|
||||
class Form(six.with_metaclass(DeclarativeFieldsMetaclass, BaseForm)):
|
||||
"A collection of Fields, plus their associated data."
|
||||
# This is a separate class from BaseForm in order to abstract the way
|
||||
# self.fields is specified. This class (Form) is the one that does the
|
||||
# fancy metaclass stuff purely for the semantic sugar -- it allows one
|
||||
# to define a form using declarative syntax.
|
||||
# BaseForm itself has no way of designating self.fields.
|
||||
__metaclass__ = DeclarativeFieldsMetaclass
|
||||
|
||||
class BoundField(StrAndUnicode):
|
||||
"A Field plus data"
|
||||
|
||||
@@ -15,6 +15,7 @@ from django.forms.widgets import (SelectMultiple, HiddenInput,
|
||||
MultipleHiddenInput, media_property)
|
||||
from django.utils.encoding import smart_unicode, force_unicode
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils import six
|
||||
from django.utils.text import get_text_list, capfirst
|
||||
from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
@@ -365,8 +366,8 @@ class BaseModelForm(BaseForm):
|
||||
|
||||
save.alters_data = True
|
||||
|
||||
class ModelForm(BaseModelForm):
|
||||
__metaclass__ = ModelFormMetaclass
|
||||
class ModelForm(six.with_metaclass(ModelFormMetaclass, BaseModelForm)):
|
||||
pass
|
||||
|
||||
def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
||||
formfield_callback=None, widgets=None):
|
||||
@@ -401,6 +402,7 @@ def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
||||
|
||||
form_metaclass = ModelFormMetaclass
|
||||
|
||||
# TODO: this doesn't work under Python 3.
|
||||
if issubclass(form, BaseModelForm) and hasattr(form, '__metaclass__'):
|
||||
form_metaclass = form.__metaclass__
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from django.utils.translation import ugettext, ugettext_lazy
|
||||
from django.utils.encoding import StrAndUnicode, force_unicode
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils import datetime_safe, formats
|
||||
from django.utils import six
|
||||
|
||||
__all__ = (
|
||||
'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'PasswordInput',
|
||||
@@ -153,8 +154,7 @@ class SubWidget(StrAndUnicode):
|
||||
args.append(self.choices)
|
||||
return self.parent_widget.render(*args)
|
||||
|
||||
class Widget(object):
|
||||
__metaclass__ = MediaDefiningClass
|
||||
class Widget(six.with_metaclass(MediaDefiningClass)):
|
||||
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
||||
needs_multipart_form = False # Determines does this widget need multipart form
|
||||
is_localized = False
|
||||
|
||||
Reference in New Issue
Block a user