Kaydet (Commit) 37520d28 authored tarafından Tim Graham's avatar Tim Graham

Removed useless hasattr() checks in ModelAdmin checks.

These attributes are defined on BaseModelAdmin and thus should always
be there.
üst 0841a31b
...@@ -251,8 +251,7 @@ class BaseModelAdminChecks: ...@@ -251,8 +251,7 @@ class BaseModelAdminChecks:
def _check_form(self, obj): def _check_form(self, obj):
""" Check that form subclasses BaseModelForm. """ """ Check that form subclasses BaseModelForm. """
if not issubclass(obj.form, BaseModelForm):
if hasattr(obj, 'form') and not issubclass(obj.form, BaseModelForm):
return must_inherit_from(parent='BaseModelForm', option='form', return must_inherit_from(parent='BaseModelForm', option='form',
obj=obj, id='admin.E016') obj=obj, id='admin.E016')
else: else:
...@@ -260,10 +259,7 @@ class BaseModelAdminChecks: ...@@ -260,10 +259,7 @@ class BaseModelAdminChecks:
def _check_filter_vertical(self, obj): def _check_filter_vertical(self, obj):
""" Check that filter_vertical is a sequence of field names. """ """ Check that filter_vertical is a sequence of field names. """
if not isinstance(obj.filter_vertical, (list, tuple)):
if not hasattr(obj, 'filter_vertical'):
return []
elif not isinstance(obj.filter_vertical, (list, tuple)):
return must_be('a list or tuple', option='filter_vertical', obj=obj, id='admin.E017') return must_be('a list or tuple', option='filter_vertical', obj=obj, id='admin.E017')
else: else:
return list(chain.from_iterable( return list(chain.from_iterable(
...@@ -273,10 +269,7 @@ class BaseModelAdminChecks: ...@@ -273,10 +269,7 @@ class BaseModelAdminChecks:
def _check_filter_horizontal(self, obj): def _check_filter_horizontal(self, obj):
""" Check that filter_horizontal is a sequence of field names. """ """ Check that filter_horizontal is a sequence of field names. """
if not isinstance(obj.filter_horizontal, (list, tuple)):
if not hasattr(obj, 'filter_horizontal'):
return []
elif not isinstance(obj.filter_horizontal, (list, tuple)):
return must_be('a list or tuple', option='filter_horizontal', obj=obj, id='admin.E018') return must_be('a list or tuple', option='filter_horizontal', obj=obj, id='admin.E018')
else: else:
return list(chain.from_iterable( return list(chain.from_iterable(
...@@ -301,10 +294,7 @@ class BaseModelAdminChecks: ...@@ -301,10 +294,7 @@ class BaseModelAdminChecks:
def _check_radio_fields(self, obj): def _check_radio_fields(self, obj):
""" Check that `radio_fields` is a dictionary. """ """ Check that `radio_fields` is a dictionary. """
if not isinstance(obj.radio_fields, dict):
if not hasattr(obj, 'radio_fields'):
return []
elif not isinstance(obj.radio_fields, dict):
return must_be('a dictionary', option='radio_fields', obj=obj, id='admin.E021') return must_be('a dictionary', option='radio_fields', obj=obj, id='admin.E021')
else: else:
return list(chain.from_iterable( return list(chain.from_iterable(
...@@ -354,27 +344,21 @@ class BaseModelAdminChecks: ...@@ -354,27 +344,21 @@ class BaseModelAdminChecks:
return [] return []
def _check_view_on_site_url(self, obj): def _check_view_on_site_url(self, obj):
if hasattr(obj, 'view_on_site'): if not callable(obj.view_on_site) and not isinstance(obj.view_on_site, bool):
if not callable(obj.view_on_site) and not isinstance(obj.view_on_site, bool): return [
return [ checks.Error(
checks.Error( "The value of 'view_on_site' must be a callable or a boolean value.",
"The value of 'view_on_site' must be a callable or a boolean value.", obj=obj.__class__,
obj=obj.__class__, id='admin.E025',
id='admin.E025', )
) ]
]
else:
return []
else: else:
return [] return []
def _check_prepopulated_fields(self, obj): def _check_prepopulated_fields(self, obj):
""" Check that `prepopulated_fields` is a dictionary containing allowed """ Check that `prepopulated_fields` is a dictionary containing allowed
field types. """ field types. """
if not isinstance(obj.prepopulated_fields, dict):
if not hasattr(obj, 'prepopulated_fields'):
return []
elif not isinstance(obj.prepopulated_fields, dict):
return must_be('a dictionary', option='prepopulated_fields', obj=obj, id='admin.E026') return must_be('a dictionary', option='prepopulated_fields', obj=obj, id='admin.E026')
else: else:
return list(chain.from_iterable( return list(chain.from_iterable(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment