Changeset - 17c5468a7d47
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-12 20:42:54
brettcsmith@brettcsmith.org
reports: ODS links default to using URL as link text.
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -919,25 +919,25 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
 
        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,
 
                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))
 
        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,
tests/test_reports_spreadsheet.py
Show inline comments
...
 
@@ -505,37 +505,37 @@ def test_ods_writer_multiline_cell(ods_writer):
 
    XML_NAMES,
 
))
 
def test_ods_writer_multilink_singleton(ods_writer, cell_source, style_name):
 
    cell = ods_writer.multilink_cell([cell_source], stylename=style_name)
 
    assert cell.getAttribute('valuetype') == 'string'
 
    assert cell.getAttribute('stylename') == style_name
 
    try:
 
        href, text = cell_source
 
    except ValueError:
 
        href = cell_source
 
        text = None
 
    anchor = get_child(cell, odf.text.A, type='simple', href=href)
 
    assert get_text(anchor) == (text or '')
 
    assert get_text(anchor) == (text or href)
 

	
 
def test_ods_writer_multilink_cell(ods_writer):
 
    cell = ods_writer.multilink_cell(iter(LINK_CELL_DATA))
 
    assert cell.getAttribute('valuetype') == 'string'
 
    children = get_children(cell, odf.text.A)
 
    for source, child in itertools.zip_longest(LINK_CELL_DATA, children):
 
        try:
 
            href, text = source
 
        except ValueError:
 
            href = source
 
            text = None
 
        assert child.getAttribute('type') == 'simple'
 
        assert child.getAttribute('href') == href
 
        assert get_text(child) == (text or '')
 
        assert get_text(child) == (text or href)
 

	
 
@pytest.mark.parametrize('cell_source,style_name', testutil.combine_values(
 
    STRING_CELL_DATA,
 
    XML_NAMES,
 
))
 
def test_ods_writer_string_cell(ods_writer, cell_source, style_name):
 
    cell = ods_writer.string_cell(cell_source, stylename=style_name)
 
    assert cell.getAttribute('valuetype') == 'string'
 
    assert cell.getAttribute('stylename') == style_name
 
    assert get_text(cell) == str(cell_source)
0 comments (0 inline, 0 general)