show alert-danger if client last_seen older then 5 minutes
This commit is contained in:
parent
1a0c0ff63a
commit
bab9196c38
@ -31,8 +31,8 @@ class LocationAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(Client)
|
@admin.register(Client)
|
||||||
class ClientAdmin(admin.ModelAdmin):
|
class ClientAdmin(admin.ModelAdmin):
|
||||||
list_display = ('uuid', 'location', 'report_user')
|
list_display = ('uuid', 'location', 'report_user', 'last_seen')
|
||||||
fields = ['location', 'uuid', 'report_user']
|
fields = ['location', 'uuid', 'report_user', 'last_seen']
|
||||||
|
|
||||||
|
|
||||||
@admin.register(LocationData)
|
@admin.register(LocationData)
|
||||||
|
17
billard/migrations/0026_client_last_seen.py
Normal file
17
billard/migrations/0026_client_last_seen.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 2.0.2 on 2018-02-11 11:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('billard', '0025_auto_20180211_1059'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='client',
|
||||||
|
name='last_seen',
|
||||||
|
field=models.DateTimeField(blank=True, null=True, verbose_name='Letzter Update'),
|
||||||
|
),
|
||||||
|
]
|
@ -52,6 +52,7 @@ class Client(models.Model):
|
|||||||
location = models.ForeignKey(Location, related_name="clients", verbose_name="Standort", on_delete=models.CASCADE)
|
location = models.ForeignKey(Location, related_name="clients", verbose_name="Standort", on_delete=models.CASCADE)
|
||||||
report_user = models.ForeignKey(User, blank=True, null=True, verbose_name="Reporting Benutzer",
|
report_user = models.ForeignKey(User, blank=True, null=True, verbose_name="Reporting Benutzer",
|
||||||
related_name='reporting_clients', on_delete=models.DO_NOTHING)
|
related_name='reporting_clients', on_delete=models.DO_NOTHING)
|
||||||
|
last_seen = models.DateTimeField(blank=True, null=True, verbose_name="Letzter Update")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}, {}'.format(self.location.name, self.uuid)
|
return '{}, {}'.format(self.location.name, self.uuid)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
@ -34,6 +34,9 @@ def display_client(client, desk_no):
|
|||||||
prize = '{0:.2f}'.format(prize)
|
prize = '{0:.2f}'.format(prize)
|
||||||
if prize != a.prize:
|
if prize != a.prize:
|
||||||
a.prize = 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(alert)
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user