From a22e3dba47e3d10cf8a6b4652b81a83344df379b Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Mon, 1 Jun 2020 18:42:03 +0200 Subject: [PATCH] Bank: add sign to money log. --- drakul/bank/templates/bank/money_log.html | 2 +- drakul/bank/templatetags/bank_extras.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drakul/bank/templates/bank/money_log.html b/drakul/bank/templates/bank/money_log.html index f400c1a..270dcbf 100644 --- a/drakul/bank/templates/bank/money_log.html +++ b/drakul/bank/templates/bank/money_log.html @@ -22,7 +22,7 @@ {{ transaction.date }} - {% format_money transaction.amount %} + {% format_money transaction.amount force_sign=True %} {% format_money transaction.balance %} diff --git a/drakul/bank/templatetags/bank_extras.py b/drakul/bank/templatetags/bank_extras.py index 5b4a018..9d92cad 100644 --- a/drakul/bank/templatetags/bank_extras.py +++ b/drakul/bank/templatetags/bank_extras.py @@ -6,10 +6,9 @@ register = template.Library() @register.simple_tag() -def format_money(copper: int): - balance_str = str(abs(copper)).rjust(5, "0") # pad until 0 gold - if copper < 0: - balance_str = "-" + balance_str +def format_money(copper: int, force_sign=False): + sign = "+" if force_sign else "-" + balance_str = f"{copper:{sign}06}" # force sign if requested and zero-pad until 0 gold return format_html( """