Skip to content

Commit

Permalink
[_642,_643] build a complete list of column keys and names
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore committed Oct 22, 2024
1 parent f2394e0 commit bc80610
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 13 additions & 6 deletions irods/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@


class ModelBase(type):
columns = {}
column_items = []
column_dict = {}

@classmethod
def columns(cls):
if not cls.column_dict:
cls.column_dict = dict(cls.column_items)
return cls.column_dict

def __new__(cls, name, bases, attr):
columns = [y for (x, y) in six.iteritems(attr) if isinstance(y, Column)]
for col in columns:
ModelBase.columns[col.icat_id] = col
attr['_columns'] = columns
# attr['_icat_column_names'] = [y.icat_key for (x,y) in columns]
column_objects = [y for (x, y) in attr.items() if isinstance(y, Column)]
for col in column_objects:
ModelBase.column_items.append((col.icat_id, col))
attr['_columns'] = column_objects
# attr['_icat_column_names'] = [y.icat_key for (x,y) in column_objects]
return type.__new__(cls, name, bases, attr)


Expand Down
8 changes: 4 additions & 4 deletions irods/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def __str__(self):
table = PrettyTable()
for col in self.cols:
table.add_column(
ModelBase.columns[col.attriInx].icat_key, col.value)
ModelBase.columns()[col.attriInx].icat_key, col.value)
table.align = 'l'
return table.get_string()

def get_html_string(self, *args, **kwargs):
table = PrettyTable()
for col in self.cols:
table.add_column(
ModelBase.columns[col.attriInx].icat_key, col.value)
ModelBase.columns()[col.attriInx].icat_key, col.value)
table.align = 'l'
return table.get_html_string(*args, **kwargs)

@staticmethod
def _format_attribute(attribute_index, value):
col = ModelBase.columns[attribute_index]
col = ModelBase.columns()[attribute_index]
try:
return (col, col.column_type.to_python(value))
except (TypeError, ValueError):
Expand Down Expand Up @@ -94,7 +94,7 @@ def _format_row(self, index):
column = self._query_columns[i]
result_key = column
except TypeError:
column = ModelBase.columns[0] # SpecificQueryResult.value
column = ModelBase.columns()[0] # SpecificQueryResult.value
result_key = i

try:
Expand Down

0 comments on commit bc80610

Please sign in to comment.