Skip to content

Commit

Permalink
Address QC suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Falešník committed Apr 28, 2017
1 parent e3a2738 commit c20deb1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/widgetastic/widget.py
Expand Up @@ -1037,12 +1037,16 @@ def table(self):
return self.row.table

def read(self):
"""Reads the content of the cell. If widget is present and visible, it is read, otherwise
the text of the cell is returned.
"""
if self.widget is not None and self.widget.is_displayed:
return self.widget.read()
else:
return self.text

def fill(self, value):
"""Fills the cell with the value if the widget is present. If not, raises a TypeError."""
if self.widget is not None:
return self.widget.fill(value)
else:
Expand Down Expand Up @@ -1103,6 +1107,7 @@ def __iter__(self):
yield header, self[i]

def read(self):
"""Read the row - the result is a dictionary"""
result = {}
for i, (header, cell) in enumerate(self):
if header is None:
Expand All @@ -1111,14 +1116,17 @@ def read(self):
return result

def fill(self, value):
"""Row filling.
Accepts either a dictionary or an iterable that can be zipped with headers to create a dict.
"""
if isinstance(value, (list, tuple)):
# make it a dict
value = dict(zip(self.table.headers, value))
changed = False
for key, value in value.items():
if value is not None:
if self[key].fill(value):
changed = True
if value is not None and self[key].fill(value):
changed = True
return changed


Expand Down Expand Up @@ -1427,12 +1435,14 @@ def _filtered_rows(self, *extra_filters, **filters):
yield row

def read(self):
"""Reads the table. Returns a list, every item in the list is contents read from the row."""
result = []
for row in self:
result.append(row.read())
return result

def fill(self, value):
"""Fills the table, accepts list which is dispatched to respective rows."""
if not isinstance(value, (list, tuple)):
value = [value]
changed = False
Expand Down

0 comments on commit c20deb1

Please sign in to comment.