Merge branch 'feature/last_seen' into develop
This commit is contained in:
commit
334e3be46b
@ -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,9 +1,15 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from billard.models import LocationData
|
from billard.models import LocationData, Client
|
||||||
|
|
||||||
|
|
||||||
class LocationDataSerializer(serializers.HyperlinkedModelSerializer):
|
class LocationDataSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LocationData
|
model = LocationData
|
||||||
fields = ('client_id', 'desk_no', 'tst', 'on_off',)
|
fields = ('client_id', 'desk_no', 'tst', 'on_off',)
|
||||||
|
|
||||||
|
|
||||||
|
class ClientUpdateLastSeenSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Client
|
||||||
|
fields = ('uuid', 'last_seen')
|
||||||
|
@ -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)
|
||||||
|
@ -7,6 +7,7 @@ from billard import views
|
|||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'locationdata', views.LocationDataViewSet)
|
router.register(r'locationdata', views.LocationDataViewSet)
|
||||||
|
router.register(r'last_seen', views.ClientUpdateLastSeenViewSet)
|
||||||
|
|
||||||
app_name = 'billard'
|
app_name = 'billard'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -11,7 +11,7 @@ from django.views import generic
|
|||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from billard.models import LocationData, Location, Client, Accounting
|
from billard.models import LocationData, Location, Client, Accounting
|
||||||
from billard.serializers import LocationDataSerializer
|
from billard.serializers import LocationDataSerializer, ClientUpdateLastSeenSerializer
|
||||||
from billard.tasks import process_location_data
|
from billard.tasks import process_location_data
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -108,6 +108,11 @@ class LocationDataViewSet(viewsets.ModelViewSet):
|
|||||||
serializer_class = LocationDataSerializer
|
serializer_class = LocationDataSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ClientUpdateLastSeenViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = LocationData.objects.all()
|
||||||
|
serializer_class = ClientUpdateLastSeenSerializer
|
||||||
|
|
||||||
|
|
||||||
def process_location_data(request):
|
def process_location_data(request):
|
||||||
process_location_data()
|
process_location_data()
|
||||||
return HttpResponse('DONE')
|
return HttpResponse('DONE')
|
||||||
|
Loading…
Reference in New Issue
Block a user