Skip to content
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

[fec-] fix diving into row sheets #2434

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
57 changes: 17 additions & 40 deletions visidata/loaders/fec.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
from copy import copy
from visidata import (
vd,
VisiData,
Path,
Sheet,
TextSheet,
Column,
ColumnAttr,
ColumnItem,
ENTER,
asyncthread,
Progress,
addGlobals,
Expand Down Expand Up @@ -111,10 +110,10 @@ def reload(self):
vd.warning("Can't dive on lists with heterogenous item types.")
return False

def dive(self):
def openRow(self, row):
if self.is_keyvalue:
cell = self.cursorRow["value"]
name = vd.joinSheetnames(self.name, self.cursorRow["key"])
cell = row["value"]
name = vd.joinSheetnames(self.name, row["key"])

if isinstance(cell, (list, dict)):
vs = self.__class__(name, source = cell)
Expand All @@ -123,19 +122,13 @@ def dive(self):
return
else:
name = vd.joinSheetnames(self.name, "row")
vs = self.__class__(name, source = self.cursorRow)
vs = self.__class__(name, source = self.row)

success = vs.reload()
if success == False:
return

vd.push(vs)
vd.fail('could not reload new sheet')
return vs

DiveSheet.addCommand(
ENTER,
'dive-row',
'vd.sheet.dive()'
)

class FECItemizationSheet(Sheet):
"A sheet to display a list of FEC itemizations from a given form/schedule."
Expand All @@ -159,19 +152,9 @@ def set_columns_from_row(self, row):
self.columns.clear()
for i, name in enumerate(row.keys()):
self.addColumn(ColumnItem(name))
def dive(self):
vs = DiveSheet(
vd.joinSheetnames(self.name, "detail"),
source = self.cursorRow
)
vs.reload()
vd.push(vs)

FECItemizationSheet.addCommand(
ENTER,
'dive-row',
'vd.sheet.dive()'
)

def openRow(self, row):
return row

class FECScheduleSheet(Sheet):
"A sheet to display the list of itemized schedules in a filing."
Expand Down Expand Up @@ -199,11 +182,8 @@ def reload(self):
)
self.addRow(vs)

FECScheduleSheet.addCommand(
ENTER,
'dive-row',
'vd.push(cursorRow)'
)
def openRow(self, row):
return row

COMPONENT_SHEET_CLASSES = {
"header": DiveSheet,
Expand All @@ -230,7 +210,7 @@ class FECFiling(Sheet):
@asyncthread
def reload(self):
from fecfile import fecparser
self.rows = []
self.rows = [] # rowdef: Sheet, of a type from COMPONENT_SHEET_CLASSES.values()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general if the rowdef is a Sheet then the parent class is IndexSheet, which provides default columns and other functionality. I'm not sure if it applies here but it might be worth exploring.


row_dict = { }
itemization_subsheets = {}
Expand Down Expand Up @@ -310,16 +290,13 @@ def addSheetRow(component_name):
sheet_row.source[form_type].append(item.data)
sheet_row.size += 1

FECFiling.addCommand(
ENTER,
'dive-row',
'vd.push(cursorRow)'
)
def openRow(self, row):
return row

def open_fec(p):
@VisiData.api
def open_fec(vd, p):
return FECFiling(p.base_stem, source=p)

addGlobals({
"open_fec": open_fec,
"DiveSheet": DiveSheet
})
Loading