Skip to content

set/dict lookups over list/tuple lookups #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django_tables2/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,9 @@ def iteritems(self):
consideration all of the ordering and filtering modifiers that a table
supports (e.g. `~Table.Meta.exclude` and `~Table.Meta.sequence`).
"""
to_exclude = set(self._table.exclude)
for name in self._table.sequence:
if name not in self._table.exclude:
if name not in to_exclude:
yield (name, self.columns[name])

def items(self):
Expand Down
16 changes: 9 additions & 7 deletions django_tables2/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __new__(mcs, name, bases, attrs):
for key, column in extra.items():
# skip current column because the parent was explicitly defined,
# and the current column is not.
if key in base_columns and base_columns[key]._explicit is True:
base_column = base_columns.get(key)
if base_column is not None and base_column._explicit is True:
continue
base_columns[key] = column

Expand All @@ -80,13 +81,11 @@ def __new__(mcs, name, bases, attrs):

# Apply any explicit exclude setting
for exclusion in opts.exclude:
if exclusion in base_columns:
base_columns.pop(exclusion)
base_columns.pop(exclusion, None)

# Remove any columns from our remainder, else columns from our parent class will remain
for attr_name in remainder:
if attr_name in base_columns:
base_columns.pop(attr_name)
base_columns.pop(attr_name, None)

# Set localize on columns
for column_name in base_columns.keys():
Expand Down Expand Up @@ -479,7 +478,9 @@ def value_name(self, value):
"""
if exclude_columns is None:
exclude_columns = ()

else:
# boost efficiency by using a set over list/tuple
exclude_columns = set(exclude_columns)
columns = [
column
for column in self.columns.iterall()
Expand Down Expand Up @@ -526,7 +527,8 @@ def order_by(self, value):
# everything's been converted to a iterable, accept iterable!
for alias in order_by:
name = OrderBy(alias).bare
if name in self.columns and self.columns[name].orderable:
column = self.columns.get(name)
if column is not None and self.column.orderable:
valid.append(alias)
self._order_by = OrderByTuple(valid)
self.data.order_by(self._order_by)
Expand Down
2 changes: 1 addition & 1 deletion django_tables2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def call_with_appropriate(fn, kwargs):
args, kwargs_name = signature(fn)
# no catch-all defined, we need to exactly pass the arguments specified.
if not kwargs_name:
kwargs = {key: kwargs[key] for key in kwargs if key in args}
kwargs = {key: val for key, val in kwargs.items() if key in args}

# if any argument of fn is not in kwargs, just return None
if any(arg not in kwargs for arg in args):
Expand Down
Loading