@@ -34,20 +34,20 @@ def __init__(self, data, table):
34
34
if (hasattr (data , 'count' ) and callable (data .count ) and
35
35
hasattr (data , 'order_by' ) and callable (data .order_by )):
36
36
self .queryset = data
37
- # otherwise it must be convertable to a list
38
- else :
39
- # do some light validation
40
- if hasattr (data , '__iter__' ) or (hasattr (data , '__len__' ) and hasattr (data , '__getitem__' )):
41
- self .list = list (data )
42
- else :
43
- raise ValueError (
44
- 'data must be QuerySet-like (have count and '
45
- ' order_by) or support list(data) -- %s has '
46
- ' neither' % type (data ).__name__
47
- )
37
+ return
38
+
39
+ # do some light validation
40
+ if hasattr (data , '__iter__' ) or (hasattr (data , '__len__' ) and hasattr (data , '__getitem__' )):
41
+ self .list = list (data )
42
+ return
43
+
44
+ raise ValueError (
45
+ 'data must be QuerySet-like (have count() and order_by()) or support'
46
+ ' list(data) -- {} has neither'. format ( type (data ).__name__ )
47
+ )
48
48
49
49
def __len__ (self ):
50
- if not hasattr (self , " _length" ):
50
+ if not hasattr (self , ' _length' ):
51
51
# Use the queryset count() method to get the length, instead of
52
52
# loading all results into memory. This allows, for example,
53
53
# smart paginators that use len() to perform better.
@@ -72,7 +72,7 @@ def ordering(self):
72
72
This works by inspecting the actual underlying data. As such it's only
73
73
supported for querysets.
74
74
"""
75
- if hasattr (self , " queryset" ):
75
+ if hasattr (self , ' queryset' ):
76
76
aliases = {}
77
77
for bound_column in self .table .columns :
78
78
aliases [bound_column .order_by_alias ] = bound_column .order_by
@@ -101,7 +101,7 @@ def order_by(self, aliases):
101
101
accessors += bound_column .order_by .opposite
102
102
else :
103
103
accessors += bound_column .order_by
104
- if hasattr (self , " queryset" ):
104
+ if hasattr (self , ' queryset' ):
105
105
translate = lambda accessor : accessor .replace (Accessor .SEPARATOR , QUERYSET_ACCESSOR_SEPARATOR )
106
106
if accessors :
107
107
self .queryset = self .queryset .order_by (* (translate (a ) for a in accessors ))
@@ -132,9 +132,9 @@ def verbose_name(self):
132
132
honored. List data is checked for a ``verbose_name`` attribute, and
133
133
falls back to using ``"item"``.
134
134
"""
135
- if hasattr (self , " queryset" ):
135
+ if hasattr (self , ' queryset' ):
136
136
return self .queryset .model ._meta .verbose_name
137
- return getattr (self .list , " verbose_name" , " item" )
137
+ return getattr (self .list , ' verbose_name' , ' item' )
138
138
139
139
@cached_property
140
140
def verbose_name_plural (self ):
@@ -143,9 +143,9 @@ def verbose_name_plural(self):
143
143
144
144
This uses the same approach as `TableData.verbose_name`.
145
145
"""
146
- if hasattr (self , " queryset" ):
146
+ if hasattr (self , ' queryset' ):
147
147
return self .queryset .model ._meta .verbose_name_plural
148
- return getattr (self .list , " verbose_name_plural" , " items" )
148
+ return getattr (self .list , ' verbose_name_plural' , ' items' )
149
149
150
150
151
151
class DeclarativeColumnsMetaclass (type ):
0 commit comments