refactor code
This commit is contained in:
		@@ -17,28 +17,9 @@ def display_client(client, desk_no):
 | 
				
			|||||||
    loc = desk.client.location
 | 
					    loc = desk.client.location
 | 
				
			||||||
    if not desk.enabled:
 | 
					    if not desk.enabled:
 | 
				
			||||||
        return ''
 | 
					        return ''
 | 
				
			||||||
    alert = 'alert-success'
 | 
					 | 
				
			||||||
    acc = desk.accounting_set.all()[:3][::-1]
 | 
					    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 = '<div class="col col-12 col-lg-6">\n'
 | 
					    html = '<div class="col col-12 col-lg-6">\n'
 | 
				
			||||||
    html += '    <div class="table-info alert {}">\n'.format(alert)
 | 
					    html += '    <div class="table-info alert {}">\n'.format(_get_alert_name(desk))
 | 
				
			||||||
    html += '        <h4 style="text-align: center">({}) {}</h4>\n'.format(desk_no, desk.name)
 | 
					    html += '        <h4 style="text-align: center">({}) {}</h4>\n'.format(desk_no, desk.name)
 | 
				
			||||||
    if loc.happy_hour_start is not None and desk.prize_hh is not None:
 | 
					    if loc.happy_hour_start is not None and desk.prize_hh is not None:
 | 
				
			||||||
        html += '        <h6 style="text-align: center">Preis: {:.2f} € / Stunde | {} - {}: {:.2f} / € Stunde</h6>\n' \
 | 
					        html += '        <h6 style="text-align: center">Preis: {:.2f} € / Stunde | {} - {}: {:.2f} / € Stunde</h6>\n' \
 | 
				
			||||||
@@ -67,3 +48,27 @@ def display_client(client, desk_no):
 | 
				
			|||||||
    html += '</div>\n'
 | 
					    html += '</div>\n'
 | 
				
			||||||
    html = format_html(html)
 | 
					    html = format_html(html)
 | 
				
			||||||
    return 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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user