Consolidate display logic and always show full value on hover

This commit is contained in:
RunasSudo 2020-03-30 20:02:09 +11:00
parent bc52ccc349
commit 2eff00b5db
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
6 changed files with 34 additions and 22 deletions

View File

@ -213,25 +213,38 @@ def transaction():
# Template filters
@app.template_filter('a')
def filter_amount(amt):
def filter_amount(amt, link=None):
if amt.near_zero:
return flask.Markup('0.00 ')
elif amt > 0:
return flask.Markup('{:,.2f} '.format(amt.amount).replace(',', ' ')) # Narrow no-break space
amt_str = '0.00'
is_pos = True
elif amt >= 0:
amt_str = '{:,.2f}'.format(amt.amount).replace(',', ' ') # Narrow no-break space
is_pos = True
else:
return flask.Markup('({:,.2f})'.format(-amt.amount).replace(',', ' '))
amt_str = '{:,.2f}'.format(-amt.amount).replace(',', ' ')
is_pos = False
if link:
if is_pos:
return flask.Markup('<a href="{}"><span title="{}">{}</span></a>&nbsp;'.format(link, amt.tostr(False), amt_str))
else:
return flask.Markup('<a href="{}"><span title="{}">({})</span></a>'.format(link, amt.tostr(False), amt_str))
else:
if is_pos:
return flask.Markup('<span title="{}">&nbsp;'.format(amt.tostr(False), amt_str))
else:
return flask.Markup('<span title="{}">({})</span>'.format(amt.tostr(False), amt_str))
@app.template_filter('b')
def filter_amount_positive(amt):
return flask.Markup('{:,.2f}'.format(amt.amount).replace(',', '&#8239;'))
#return flask.Markup('{:,.2f} {}'.format(amt.amount, amt.currency.name).replace(',', '&#8239;'))
return flask.Markup('<span title="{}">{:,.2f}</span>'.format(amt.tostr(False), amt.amount).replace(',', '&#8239;'))
@app.template_filter('bc')
def filter_currency_positive(amt):
if amt.currency.is_prefix:
return flask.Markup('{}{:,.2f}'.format(amt.currency.name, amt.amount).replace(',', '&#8239;'))
return flask.Markup('<span title="{}">{}{:,.2f}</span>'.format(amt.tostr(False), amt.currency.name, amt.amount).replace(',', '&#8239;'))
else:
return flask.Markup('{:,.2f} {}'.format(amt.amount, amt.currency.name).replace(',', '&#8239;'))
return flask.Markup('<span title="{}">{:,.2f} {}</span>'.format(amt.tostr(False), amt.amount, amt.currency.name).replace(',', '&#8239;'))
@app.template_filter('bt')
def filter_currency_table_positive(amt, show_price, link=None):

View File

@ -38,12 +38,11 @@
<td>
{% if not amount.near_zero %}
{% if account.name == config['current_year_earnings'] %}
<a href="/pandl?{{ {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0', 'cash': 'on' if cash else ''}|urlencode }}">
{{ amount|a('/pandl?' + {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0', 'cash': 'on' if cash else ''}|urlencode) }}
{% else %}
<a href="/transactions?{{ {'date': balance_sheet.date.strftime('%Y-%m-%d'), 'pstart': balance_sheet.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">
{{ amount|a('/transactions?' + {'date': balance_sheet.date.strftime('%Y-%m-%d'), 'pstart': balance_sheet.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode) }}
{% endif %}
{{ amount|a }}
</a>
{% endif %}
</td>
{% endfor %}

View File

@ -41,8 +41,8 @@
<td>{% if loop.first %}{{ transaction.date.strftime('%Y-%m-%d') }}{% endif %}</td>
<td>{% if loop.first %}{{ transaction.description }}{% endif %}</td>
<td>{{ (posting.account.name|e).__str__().replace(':', ':<wbr>')|safe }}</td>
<td style="text-align: right;">{% if amount > 0 %}<span title="{{ posting.amount.tostr(False) }}">{{ amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}<span title="{{ (-posting.amount).tostr(False) }}">{{ -amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount > 0 %}{{ amount|b }}{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}{{ -amount|b }}{% endif %}</td>
</tr>
{% endfor %}
{% endfor %}

View File

@ -29,7 +29,7 @@
</td>
{% for pandl in pandls %}
{% set amount = (-pandl.get_balance(account) if invert else pandl.get_balance(account)).exchange(report_currency, True) %}
<td>{% if not amount.near_zero %}<a href="/transactions?{{ {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ amount|a }}</a>{% endif %}</td>
<td>{% if not amount.near_zero %}{{ amount|a('/transactions?' + {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode) }}{% endif %}</td>
{% endfor %}
</tr>

View File

@ -56,8 +56,8 @@
<tr>
<td>{{ posting.comment }}</td>
<td>{{ (posting.account.name|e).__str__().replace(':', ':<wbr>')|safe }}</td>
<td style="text-align: right;">{% if amount > 0 %}<span title="{{ posting.amount.tostr(False) }}">{{ amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}<span title="{{ (-posting.amount).tostr(False) }}">{{ -amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount > 0 %}{{ amount|b }}{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}{{ -amount|b }}{% endif %}</td>
</tr>
{% endfor %}

View File

@ -77,8 +77,8 @@
{% if account %}
{# Reverse Dr/Cr so it's from the "perspective" of this account #}
{% set ns.balance = ns.balance - amount %}
<td style="text-align: right;">{% if amount < 0 %}<span title="{{ (-posting.amount).tostr(False) }}">{{ -amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount > 0 %}<span title="{{ posting.amount.tostr(False) }}">{{ amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}{{ -amount|b }}{% endif %}</td>
<td style="text-align: right;">{% if amount > 0 %}{{ amount|b }}{% endif %}</td>
<td style="text-align: right;">
{% if loop.last %}
{% if ns.balance >= 0 %}
@ -89,8 +89,8 @@
{% endif %}
</td>
{% else %}
<td style="text-align: right;">{% if amount > 0 %}<span title="{{ posting.amount.tostr(False) }}">{{ amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}<span title="{{ (-posting.amount).tostr(False) }}">{{ -amount|b }}</span>{% endif %}</td>
<td style="text-align: right;">{% if amount > 0 %}{{ amount|b }}{% endif %}</td>
<td style="text-align: right;">{% if amount < 0 %}{{ -amount|b }}{% endif %}</td>
{% endif %}
</tr>
{% endfor %}