Start implement user status logging
This commit is contained in:
parent
3af6677da0
commit
7476c08529
4 changed files with 61 additions and 2 deletions
29
manager/migrations/0040_auto_20190131_1951.py
Normal file
29
manager/migrations/0040_auto_20190131_1951.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# Generated by Django 2.1.5 on 2019-01-31 19:51
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('manager', '0039_auto_20190124_1023'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserStatus',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('last_action', models.DateTimeField(blank=True, null=True)),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='device',
|
||||||
|
name='wifi',
|
||||||
|
field=models.ManyToManyField(blank=True, to='manager.Wifi'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,6 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import uuid
|
|
||||||
|
|
||||||
def getRandom():
|
def getRandom():
|
||||||
return str(uuid.uuid4().hex)
|
return str(uuid.uuid4().hex)
|
||||||
|
@ -162,3 +161,8 @@ class Notification(models.Model):
|
||||||
text = models.CharField("Notification Text", max_length=1024)
|
text = models.CharField("Notification Text", max_length=1024)
|
||||||
expiry = models.DateTimeField("Notification Expiry", null=True, blank=True)
|
expiry = models.DateTimeField("Notification Expiry", null=True, blank=True)
|
||||||
on_login = models.BooleanField("Display Notification on Login Screen", default=False)
|
on_login = models.BooleanField("Display Notification on Login Screen", default=False)
|
||||||
|
|
||||||
|
class UserStatus(models.Model):
|
||||||
|
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||||
|
last_action = models.DateTimeField(null=True, blank=True)
|
||||||
|
|
||||||
|
|
13
manager/templatetags/userstatus.py
Normal file
13
manager/templatetags/userstatus.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from django import template
|
||||||
|
from django.conf import settings
|
||||||
|
from manager.models import UserStatus
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def updateUserStatus(user):
|
||||||
|
try:
|
||||||
|
UserStatus.objects.filter(user=user)[0].last_action = timezone.now()
|
||||||
|
except:
|
||||||
|
pass
|
|
@ -8,8 +8,11 @@ from django.core.files import File
|
||||||
from django.db.models.fields.files import FieldFile
|
from django.db.models.fields.files import FieldFile
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from .models import Device, Organization, Network, Model, Wifi
|
from .models import Device, Organization, Network, Model, Wifi, UserStatus
|
||||||
from .signals import *
|
from .signals import *
|
||||||
|
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
|
@ -587,3 +590,13 @@ def makedevice(request):
|
||||||
)
|
)
|
||||||
|
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
||||||
|
def createUserStatus(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
UserStatus.objects.create(user=instance)
|
||||||
|
|
||||||
|
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
||||||
|
def saveUserStatus(sender, instance, **kwargs):
|
||||||
|
instance.profile.save()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue