From 47e265a02cf0c037761a42414b3b1f193ff10b97 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Tue, 13 Feb 2018 17:02:04 +0100 Subject: [PATCH] refactor code --- billard/templatetags/display_client.py | 45 ++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/billard/templatetags/display_client.py b/billard/templatetags/display_client.py index d15f81a..f4a0c91 100644 --- a/billard/templatetags/display_client.py +++ b/billard/templatetags/display_client.py @@ -17,28 +17,9 @@ def display_client(client, desk_no): loc = desk.client.location if not desk.enabled: return '' - alert = 'alert-success' acc = desk.accounting_set.all()[:3][::-1] - if acc is not None and len(acc) > 0: - a = acc[-1] - if a.time_to is None: - alert = 'alert-info' - prize, u1, u2 = utils.get_prize_for( - start=a.time_from, - end=datetime.now(), - pph=desk.prize, - hh_start=loc.happy_hour_start, - hh_end=loc.happy_hour_end, - pphh=desk.prize_hh, - ) - prize = '{0:.2f}'.format(prize) - if prize != a.prize: - a.prize = prize - before5min = datetime.now() - timedelta(minutes=5) - if client.last_seen is not None and client.last_seen < before5min: - alert = 'alert-danger' html = '
\n' - html += '
\n'.format(alert) + html += '
\n'.format(_get_alert_name(desk)) html += '

({}) {}

\n'.format(desk_no, desk.name) if loc.happy_hour_start is not None and desk.prize_hh is not None: html += '
Preis: {:.2f} € / Stunde | {} - {}: {:.2f} / € Stunde
\n' \ @@ -67,3 +48,27 @@ def display_client(client, desk_no): html += '
\n' html = format_html(html) return html + + +def _get_alert_name(desk): + alert = 'alert-success' + acc = desk.accounting_set.all()[:3][::-1] + if acc is not None and len(acc) > 0: + a = acc[-1] + if a.time_to is None: + alert = 'alert-info' + prize, u1, u2 = utils.get_prize_for( + start=a.time_from, + end=datetime.now(), + pph=desk.prize, + hh_start=desk.client.location.happy_hour_start, + hh_end=desk.client.location.happy_hour_end, + pphh=desk.prize_hh, + ) + prize = '{0:.2f}'.format(prize) + if prize != a.prize: + a.prize = prize + before5min = datetime.now() - timedelta(minutes=5) + if desk.client.last_seen is not None and desk.client.last_seen < before5min: + alert = 'alert-danger' + return alert