Changeset - 8d3a0dbe4c97
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-29 13:20:59
brettcsmith@brettcsmith.org
reports: Add BaseODS.lock_first_column() method.
2 files changed with 25 insertions and 5 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -920,6 +920,22 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
 

	
 
    ### Sheets
 

	
 
    def lock_first_column(self, sheet: Optional[odf.table.Table]=None) -> None:
 
        """Lock the first column of cells under the given sheet
 

	
 
        This method sets all the appropriate settings to "lock" the first column
 
        of cells in a sheet, so it stays in view even as the viewer scrolls
 
        across the sheet. If a sheet is not given, works on ``self.sheet``.
 
        """
 
        if sheet is None:
 
            sheet = self.sheet
 
        config_map = self.ensure_config_map_entry(
 
            self.view, 'Tables', sheet.getAttribute('name'),
 
        )
 
        self.set_config(config_map, 'PositionRight', 1, 'int')
 
        self.set_config(config_map, 'HorizontalSplitMode', 2, 'short')
 
        self.set_config(config_map, 'HorizontalSplitPosition', 1, 'short')
 

	
 
    def lock_first_row(self, sheet: Optional[odf.table.Table]=None) -> None:
 
        """Lock the first row of cells under the given sheet
 

	
tests/test_reports_spreadsheet.py
Show inline comments
...
 
@@ -454,8 +454,12 @@ def test_ods_writer_date_style(ods_writer):
 
    assert day.qname[1] == 'day'
 
    assert day.getAttribute('style') == 'long'
 

	
 
def test_ods_lock_first_row(ods_writer):
 
    ods_writer.lock_first_row()
 
@pytest.mark.parametrize('method_name,split_name,side_name', [
 
    ('lock_first_row', 'Vertical', 'Bottom'),
 
    ('lock_first_column', 'Horizontal', 'Right'),
 
])
 
def test_ods_lock_first_cells(ods_writer, method_name, split_name, side_name):
 
    getattr(ods_writer, method_name)()
 
    view_settings = get_child(
 
        ods_writer.document.settings,
 
        odf.config.ConfigItemSet,
...
 
@@ -467,9 +471,9 @@ def test_ods_lock_first_row(ods_writer):
 
    sheet_name = ods_writer.sheet.getAttribute('name')
 
    config_entry = get_child(config_map, odf.config.ConfigItemMapEntry, name=sheet_name)
 
    for name, ctype, value in [
 
            ('PositionBottom', 'int', '1'),
 
            ('VerticalSplitMode', 'short', '2'),
 
            ('VerticalSplitPosition', 'short', '1'),
 
            (f'Position{side_name}', 'int', '1'),
 
            (f'{split_name}SplitMode', 'short', '2'),
 
            (f'{split_name}SplitPosition', 'short', '1'),
 
    ]:
 
        child = get_child(config_entry, odf.config.ConfigItem, name=name)
 
        assert child.getAttribute('type') == ctype
0 comments (0 inline, 0 general)