Update logic for update_seen of clients
This commit is contained in:
parent
45dea64599
commit
e3deead94b
@ -35,6 +35,12 @@ class ClientAdmin(admin.ModelAdmin):
|
||||
fields = ['location', 'uuid', 'report_user', 'last_seen']
|
||||
|
||||
|
||||
@admin.register(ClientData)
|
||||
class ClientDataAdmin(admin.ModelAdmin):
|
||||
list_display = ('uuid', 'last_seen')
|
||||
fields = ['location', 'last_seen']
|
||||
|
||||
|
||||
@admin.register(LocationData)
|
||||
class LocationDataAdmin(admin.ModelAdmin):
|
||||
def get_urls(self):
|
||||
|
24
billard/migrations/0027_clientdata.py
Normal file
24
billard/migrations/0027_clientdata.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 2.0.2 on 2018-02-19 10:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('billard', '0026_client_last_seen'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ClientData',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.UUIDField(verbose_name='Identifier')),
|
||||
('last_seen', models.DateTimeField(verbose_name='Letzter Update')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Client Data logs',
|
||||
'verbose_name_plural': 'Client Data logs',
|
||||
},
|
||||
),
|
||||
]
|
@ -102,7 +102,25 @@ class Accounting(models.Model):
|
||||
verbose_name_plural = "Buchhaltungseinträge"
|
||||
|
||||
|
||||
class ClientData(models.Model):
|
||||
uuid = models.UUIDField(verbose_name="Identifier")
|
||||
last_seen = models.DateTimeField(verbose_name="Letzter Update")
|
||||
|
||||
def __str__(self):
|
||||
return '{}, {}'.format(self.uuid, self.last_seen)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Client Data logs"
|
||||
verbose_name_plural = "Client Data logs"
|
||||
|
||||
|
||||
@receiver(post_save, sender=LocationData)
|
||||
def test(sender, **kwargs):
|
||||
from .tasks import process_location_data
|
||||
process_location_data()
|
||||
|
||||
|
||||
@receiver(post_save, sender=ClientData)
|
||||
def test(sender, **kwargs):
|
||||
from .tasks import process_client_data
|
||||
process_client_data()
|
||||
|
@ -1,6 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from billard.models import LocationData, Client
|
||||
from billard.models import LocationData, ClientData
|
||||
|
||||
|
||||
class LocationDataSerializer(serializers.HyperlinkedModelSerializer):
|
||||
@ -11,5 +11,5 @@ class LocationDataSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class ClientUpdateLastSeenSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Client
|
||||
model = ClientData
|
||||
fields = ('uuid', 'last_seen')
|
||||
|
@ -3,11 +3,20 @@ from __future__ import absolute_import, unicode_literals
|
||||
import logging
|
||||
|
||||
import billard.utils as utils
|
||||
from billard.models import LocationData, Client, Accounting
|
||||
from billard.models import LocationData, Client, Accounting, ClientData
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def process_client_data():
|
||||
data = ClientData.objects.all()
|
||||
for cd in data:
|
||||
client = Client.objects.get(uuid=cd.uuid)
|
||||
client.last_seen = cd.last_seen
|
||||
client.save()
|
||||
cd.delete()
|
||||
|
||||
|
||||
def process_location_data():
|
||||
data = LocationData.objects.filter(processed=False).order_by('tst')
|
||||
for ld in data:
|
||||
|
Loading…
Reference in New Issue
Block a user