def export_taxon(txn, sprsh, is_root=False, recurse=True): # Start new spreadsheet if txn.is_page_root and not is_root: if recurse: export_spreadsheet(txn) return # Insert empty row for esthetics if txn.rank >= FAMILY: sprsh.add_row(export_tools.empty_row(), rank=SPECIES) taxon_row = export_tools.empty_row() # Taxon stuff try: taxon_row[0] = abbrev_of_rank(txn.rank) except KeyError: # Give numeric rank explicitly taxon_row[0] = str(txn.rank) taxon_row[1] = abbrev_of_age(txn.age) taxon_row[3] = txn.full_name() taxon_row[16] = txn.comments taxon_row[17] = txn.data # Find Name base_name = txn.base_name if base_name is None: taxon_row[5] = "n/a" add_nas(taxon_row) elif base_name.taxon.id != txn.id: taxon_row[5] = "see " + base_name.taxon.valid_name add_nas(taxon_row) else: fill_in_name(taxon_row, base_name) sprsh.add_row(taxon_row, rank=txn.rank) # Add synonyms for name in txn.sorted_names(exclude_valid=True): name_row = export_tools.empty_row() name_row[0] = abbrev_of_status(name.status) name_row[1] = abbrev_of_age(txn.age) name_row[3] = txn.full_name() fill_in_name(name_row, name) sprsh.add_row(name_row, status=name.status) # Add children for child in txn.sorted_children(): export_taxon(child, sprsh, recurse=recurse)
def export_spreadsheet(txn, **kwargs): # To get rid of the overly large cache gc.collect() with export_tools.spreadsheet(txn.valid_name) as sprsh: # add first line first_line = export_tools.empty_row() if txn.parent is not None: first_line[0] = txn.parent.valid_name first_line[3] = "=COUNTA(D2:D10000)" first_line[4] = "=COUNTA(E2:E10000)/D1*100" first_line[6] = "=COUNTA(G2:G10000)/D1*100" first_line[7] = "=COUNTA(H2:H10000)/D1*100" first_line[8] = "=COUNTA(I2:I10000)/D1*100" first_line[10] = "=COUNTA(K2:K10000)/D1*100" sprsh.add_row(first_line, status=STATUS_DUBIOUS) export_taxon(txn, sprsh, is_root=True, **kwargs)