@ -26,6 +26,22 @@ bei Fragen bitte an Holgi wenden
"""
"""
def _map_from_form_data ( request , prefix ) :
if not prefix . endswith ( " - " ) :
prefix = f " { prefix } - "
result = { }
for key , value in request . POST . items ( ) :
if key . startswith ( prefix ) :
row_str = key . split ( " - " ) [ - 1 ]
row = int ( row_str )
try :
value = float ( value )
except ValueError :
value = 0
result [ row ] = value
return result
@view_config (
@view_config (
context = Root ,
context = Root ,
request_method = " GET " ,
request_method = " GET " ,
@ -112,22 +128,17 @@ def send_overview(context, request):
recipients = tmp_recipients . splitlines ( )
recipients = tmp_recipients . splitlines ( )
budget_template = request . POST . get ( " template " )
budget_template = request . POST . get ( " template " )
budget_file = request . budgets_dir / budget_template
budget_file = request . budgets_dir / budget_template
expenses = { }
for key , value in request . POST . items ( ) :
budgets = _map_from_form_data ( request , " budget- " )
if key . startswith ( " expense- " ) :
expenses = _map_from_form_data ( request , " expense- " )
row_str = key . split ( " - " ) [ - 1 ]
available = { k : ( v - expenses [ k ] ) for k , v in budgets . items ( ) }
row = int ( row_str )
try :
value = float ( value )
except ValueError :
value = 0
expenses [ row ] = value
# sanity check
# sanity check
if (
if (
not export_date
not export_date
or not recipients
or not recipients
or not expenses
or not expenses
or not available
or not budget_file . is_file ( )
or not budget_file . is_file ( )
) :
) :
request . session . flash (
request . session . flash (
@ -140,6 +151,9 @@ def send_overview(context, request):
for row , value in expenses . items ( ) :
for row , value in expenses . items ( ) :
cell = f " F { row } "
cell = f " F { row } "
sheet [ cell ] = value
sheet [ cell ] = value
for row , value in available . items ( ) :
cell = f " G { row } "
sheet [ cell ] = value
budget_year = budget_file . stem . split ( " - " ) [ - 1 ]
budget_year = budget_file . stem . split ( " - " ) [ - 1 ]
message = Message (
message = Message (