Changeset - 6703d1af87ad
[Not reviewed]
0 2 0
Brett Smith - 3 years ago 2021-03-15 17:19:03
brettcsmith@brettcsmith.org
reports: BaseODS puts each line of strings in a P tag.

This seems to be the most straightforward way to get Calc to automatically
determine a nice row height for multi-line string cells. This has become a
lot more noticeable now that query-report supports putting postal addresses
in cells.
2 files changed with 13 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -1427,46 +1427,53 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
 
                rt_path = urlparse.urlparse(rt_href).path
 
                if rt_path.endswith('/Ticket/Display.html'):
 
                    text = rtutil.RT.unparse(*rt_ids)
 
                else:
 
                    text = urlparse.unquote(Path(rt_path).name)
 
                href = rt_href
 
            yield (href, text)
 

	
 
    def meta_links_cell(self, links: Iterable[Optional[str]], **attrs: Any) -> odf.table.TableCell:
 
        return self.multilink_cell(self._meta_link_pairs(links), **attrs)
 

	
 
    def multiline_cell(self, lines: Iterable[Any], **attrs: Any) -> odf.table.TableCell:
 
        item_lines = [str(item).splitlines() for item in lines if item is not None]
 
        if any(len(seq) > 1 for seq in item_lines):
 
            for seq in item_lines:
 
                seq.append('')
 
            seq.pop()
 
        cell = odf.table.TableCell(valuetype='string', **attrs)
 
        for line in lines:
 
            cell.addElement(odf.text.P(text=str(line)))
 
        for seq in item_lines:
 
            for line in seq:
 
                cell.addElement(odf.text.P(text=line))
 
        return cell
 

	
 
    def multilink_cell(self, links: Iterable[LinkType], **attrs: Any) -> odf.table.TableCell:
 
        cell = odf.table.TableCell(valuetype='string', **attrs)
 
        for link in links:
 
            if isinstance(link, tuple):
 
                href, text = link
 
            else:
 
                href = link
 
                text = None
 
            cell.addElement(odf.text.P())
 
            cell.lastChild.addElement(odf.text.A(
 
                type='simple', href=href, text=text or href,
 
            ))
 
        return cell
 

	
 
    def string_cell(self, text: str, **attrs: Any) -> odf.table.TableCell:
 
        cell = odf.table.TableCell(valuetype='string', **attrs)
 
        cell.addElement(odf.text.P(text=text))
 
        for line in text.splitlines():
 
            cell.addElement(odf.text.P(text=line))
 
        return cell
 

	
 
    def write_row(self, row: RT) -> None:
 
        """Write a single row of input data to the spreadsheet
 

	
 
        This default implementation adds a single row to the spreadsheet,
 
        with one cell per element of the row. The type of each element
 
        determines what kind of cell is created.
 

	
 
        This implementation will help get you started, but you'll probably
 
        want to override it to specify styles.
 
        """
tests/test_reports_fund.py
Show inline comments
...
 
@@ -184,25 +184,27 @@ def check_ods_sheet(sheet, account_balances, *, full):
 
        }
 
    totals = {key: Decimal() for key in total_keys}
 
    for fund, balances in account_bals.items():
 
        for key in totals:
 
            totals[key] += balances[key]
 
    account_bals[''] = totals
 
    if full:
 
        account_bals['Unrestricted'] = unrestricted
 
    for row in itertools.islice(sheet.getElementsByType(odf.table.TableRow), 4, None):
 
        cells = iter(testutil.ODSCell.from_row(row))
 
        try:
 
            fund = next(cells).firstChild.text
 
        except (AttributeError, StopIteration):
 
        except AttributeError:
 
            fund = ''
 
        except StopIteration:
 
            continue
 
        try:
 
            balances = account_bals.pop(fund)
 
        except KeyError:
 
            pytest.fail(f"report included unexpected fund {fund}")
 
        check_cell_balance(next(cells), balances['opening'])
 
        check_cell_balance(next(cells), balances['Income'])
 
        if full:
 
            check_cell_balance(next(cells), -balances['Expenses'])
 
            check_cell_balance(next(cells), balances['Equity'])
 
        else:
 
            check_cell_balance(
0 comments (0 inline, 0 general)