Browse Source

fixed some parser issues

main
Holger Frey 2 months ago
parent
commit
d76ac0c72a
  1. BIN
      budgets/Budget-Vorlage-2024.xlsx
  2. 10
      superx_budget/budget.py
  3. 1
      superx_budget/pyramid/templates/overview.jinja2
  4. 4
      tests/test_budget_parser.py

BIN
budgets/Budget-Vorlage-2024.xlsx

Binary file not shown.

10
superx_budget/budget.py

@ -16,6 +16,8 @@ EXPECTED_TABLE_HEADERS = [
"Rest", "Rest",
] ]
EXCEL_LINES_TO_IGNORE = {"stand:", "stand"}
NUM_EXPECTED_HEADERS = len(EXPECTED_TABLE_HEADERS) NUM_EXPECTED_HEADERS = len(EXPECTED_TABLE_HEADERS)
ExcelRow = namedtuple("ExcelRow", ["row", "data"]) ExcelRow = namedtuple("ExcelRow", ["row", "data"])
@ -47,16 +49,20 @@ def _check_table_header(xl_row):
raise BudgetParserError(msg) raise BudgetParserError(msg)
def _skip_empty_lines(rows): def _skip_some_lines(rows):
for xl_row in rows: for xl_row in rows:
first_cell = xl_row.data[0] first_cell = xl_row.data[0]
if is_empty_excel_value(first_cell): if is_empty_excel_value(first_cell):
continue continue
if isinstance(first_cell, str):
value = first_cell.strip().lower()
if value in EXCEL_LINES_TO_IGNORE:
continue
yield xl_row yield xl_row
def _parse_data_table(rows): def _parse_data_table(rows):
for xl_row in _skip_empty_lines(rows): for xl_row in _skip_some_lines(rows):
data = [ data = [
strip_excel_value(value) strip_excel_value(value)
for value in xl_row.data[:NUM_EXPECTED_HEADERS] for value in xl_row.data[:NUM_EXPECTED_HEADERS]

1
superx_budget/pyramid/templates/overview.jinja2

@ -25,7 +25,6 @@
<tbody> <tbody>
{% for budget in overview %} {% for budget in overview %}
<tr scope="row" class="{% if budget.available<0 %}table-danger{% endif %}"> <tr scope="row" class="{% if budget.available<0 %}table-danger{% endif %}">
<td> <td>
{{budget.budget_data.project_name}} {{budget.budget_data.project_name}}

4
tests/test_budget_parser.py

@ -12,7 +12,7 @@ def test_check_table_header_raises_error():
def test_skip_empty_lines(): def test_skip_empty_lines():
from superx_budget.budget import ExcelRow, _skip_empty_lines from superx_budget.budget import ExcelRow, _skip_some_lines
rows = [ rows = [
ExcelRow(0, [""]), ExcelRow(0, [""]),
@ -23,7 +23,7 @@ def test_skip_empty_lines():
ExcelRow(5, [""]), ExcelRow(5, [""]),
] ]
result = _skip_empty_lines(rows) result = _skip_some_lines(rows)
assert list(result) == [(1, ["one"]), (4, ["two"])] assert list(result) == [(1, ["one"]), (4, ["two"])]

Loading…
Cancel
Save