Skip to content

Commit

Permalink
Clean up and remove unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Jun 1, 2016
1 parent b71f534 commit 8fe9826
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions django_tables2/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@


class TableData(object):
"""
'''
Exposes a consistent API for :term:`table data`.
Arguments:
data (`~django.db.query.QuerySet` or `list` of `dict`): iterable
containing data for each row
table (`~.Table`)
"""
'''
def __init__(self, data, table):
self.table = table
# data may be a QuerySet-like objects with count() and order_by()
Expand Down Expand Up @@ -61,7 +61,7 @@ def data(self):

@property
def ordering(self):
"""
'''
Returns the list of order by aliases that are enforcing ordering on the
data.
Expand All @@ -70,7 +70,7 @@ def ordering(self):
This works by inspecting the actual underlying data. As such it's only
supported for querysets.
"""
'''
if hasattr(self, 'queryset'):
aliases = {}
for bound_column in self.table.columns:
Expand All @@ -81,15 +81,15 @@ def ordering(self):
pass

def order_by(self, aliases):
"""
'''
Order the data based on order by aliases (prefixed column names) in the
table.
Arguments:
aliases (`~.utils.OrderByTuple`): optionally prefixed names of
columns ('-' indicates descending order) in order of
significance with regard to data ordering.
"""
'''
bound_column = None
accessors = []
for alias in aliases:
Expand All @@ -101,6 +101,7 @@ def order_by(self, aliases):
accessors += bound_column.order_by.opposite
else:
accessors += bound_column.order_by

if hasattr(self, 'queryset'):
# Custom ordering
if bound_column:
Expand All @@ -114,43 +115,37 @@ def order_by(self, aliases):
else:
self.list.sort(key=OrderByTuple(accessors).key)

def __iter__(self):
"""
for ... in ... default to using this. There's a bug in Django 1.3
with indexing into querysets, so this side-steps that problem (as well
as just being a better way to iterate).
"""
return iter(self.data)

def __getitem__(self, key):
"""
'''
Slicing returns a new `.TableData` instance, indexing returns a
single record.
"""
'''
return self.data[key]

@cached_property
def verbose_name(self):
"""
'''
The full (singular) name for the data.
Queryset data has its model's `~django.db.Model.Meta.verbose_name`
honored. List data is checked for a ``verbose_name`` attribute, and
falls back to using ``"item"``.
"""
honored. List data is checked for a `verbose_name` attribute, and
falls back to using `'item'`.
'''
if hasattr(self, 'queryset'):
return self.queryset.model._meta.verbose_name

return getattr(self.list, 'verbose_name', 'item')

@cached_property
def verbose_name_plural(self):
"""
'''
The full (plural) name of the data.
This uses the same approach as `TableData.verbose_name`.
"""
'''
if hasattr(self, 'queryset'):
return self.queryset.model._meta.verbose_name_plural

return getattr(self.list, 'verbose_name_plural', 'items')


Expand Down

0 comments on commit 8fe9826

Please sign in to comment.