From bfe310f6364b32f00bca5c0ccd3b8cb1d12d988e Mon Sep 17 00:00:00 2001 From: Etzelia Date: Fri, 21 Sep 2018 23:35:51 -0500 Subject: [PATCH] IP last used date & IP info Added last_used to IP model Created page to view an IP and last dates for any associated players --- api/views.py | 6 +++-- migrations/0009_ip_last_seen.py | 18 +++++++++++++++ migrations/0010_auto_20180921_2306.py | 18 +++++++++++++++ models.py | 1 + .../css/bootswatch-darkly.css | 3 ++- .../css/bootswatch-flatly.css | 3 ++- .../css/bootswatch-slate.css | 3 ++- .../css/bootswatch-solar.css | 3 ++- templates/minecraft_manager/ip.html | 23 +++++++++++++++++++ templates/minecraft_manager/player_info.html | 6 ++--- urls.py | 2 ++ views.py | 11 +++++++++ 12 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 migrations/0009_ip_last_seen.py create mode 100644 migrations/0010_auto_20180921_2306.py create mode 100644 templates/minecraft_manager/ip.html diff --git a/api/views.py b/api/views.py index 387f32d..a2fe855 100644 --- a/api/views.py +++ b/api/views.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -import logging, random, string, discord +import logging, random, string, datetime from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth import update_session_auth_hash from django.apps import apps @@ -261,11 +261,13 @@ class PluginAPI(View): player.application = test_app player.save() test_ip = IP.objects.filter(ip=post['ip'], player=player).exists() + last_used = datetime.date.today() if not test_ip: ip = IP(ip=post['ip'], player=player) - ip.save() else: ip = IP.objects.get(ip=post['ip'], player=player) + ip.last_used = last_used + ip.save() player = Player.objects.get(uuid=post['uuid']) player.last_seen = timezone.now().strftime("%Y-%m-%d") player.save() diff --git a/migrations/0009_ip_last_seen.py b/migrations/0009_ip_last_seen.py new file mode 100644 index 0000000..2cdb0dc --- /dev/null +++ b/migrations/0009_ip_last_seen.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2018-09-22 03:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('minecraft_manager', '0008_auto_20180820_1406'), + ] + + operations = [ + migrations.AddField( + model_name='ip', + name='last_seen', + field=models.DateField(blank=True, null=True), + ), + ] diff --git a/migrations/0010_auto_20180921_2306.py b/migrations/0010_auto_20180921_2306.py new file mode 100644 index 0000000..3ce4e35 --- /dev/null +++ b/migrations/0010_auto_20180921_2306.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2018-09-22 04:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('minecraft_manager', '0009_ip_last_seen'), + ] + + operations = [ + migrations.RenameField( + model_name='ip', + old_name='last_seen', + new_name='last_used', + ), + ] diff --git a/models.py b/models.py index 6d0a43f..dacd021 100644 --- a/models.py +++ b/models.py @@ -369,6 +369,7 @@ class Warning(models.Model): class IP(models.Model): player = models.ForeignKey(Player, on_delete=models.CASCADE) ip = models.CharField(max_length=30) + last_used = models.DateField(null=True, blank=True) class Meta: verbose_name = "IP" diff --git a/static/minecraft_manager/css/bootswatch-darkly.css b/static/minecraft_manager/css/bootswatch-darkly.css index b68012a..9a5e710 100644 --- a/static/minecraft_manager/css/bootswatch-darkly.css +++ b/static/minecraft_manager/css/bootswatch-darkly.css @@ -3994,7 +3994,8 @@ select[multiple].input-group-sm > .input-group-btn > .btn { padding: 10px 15px; } .nav > li > a:hover, -.nav > li > a:focus { +.nav > li > a:focus, +.nav > li.active > a { text-decoration: none; background-color: #303030; } diff --git a/static/minecraft_manager/css/bootswatch-flatly.css b/static/minecraft_manager/css/bootswatch-flatly.css index 162b767..ba7e9e9 100644 --- a/static/minecraft_manager/css/bootswatch-flatly.css +++ b/static/minecraft_manager/css/bootswatch-flatly.css @@ -3990,7 +3990,8 @@ select[multiple].input-group-sm > .input-group-btn > .btn { padding: 10px 15px; } .nav > li > a:hover, -.nav > li > a:focus { +.nav > li > a:focus, +.nav > li.active > a { text-decoration: none; background-color: #ecf0f1; } diff --git a/static/minecraft_manager/css/bootswatch-slate.css b/static/minecraft_manager/css/bootswatch-slate.css index 0f09828..eb90344 100644 --- a/static/minecraft_manager/css/bootswatch-slate.css +++ b/static/minecraft_manager/css/bootswatch-slate.css @@ -3993,7 +3993,8 @@ select[multiple].input-group-sm > .input-group-btn > .btn { padding: 10px 15px; } .nav > li > a:hover, -.nav > li > a:focus { +.nav > li > a:focus, +.nav > li.active > a { text-decoration: none; background-color: #3e444c; } diff --git a/static/minecraft_manager/css/bootswatch-solar.css b/static/minecraft_manager/css/bootswatch-solar.css index 653ff06..3beb663 100644 --- a/static/minecraft_manager/css/bootswatch-solar.css +++ b/static/minecraft_manager/css/bootswatch-solar.css @@ -3990,7 +3990,8 @@ select[multiple].input-group-sm > .input-group-btn > .btn { padding: 10px 15px; } .nav > li > a:hover, -.nav > li > a:focus { +.nav > li > a:focus, +.nav > li.active > a { text-decoration: none; background-color: #222222; } diff --git a/templates/minecraft_manager/ip.html b/templates/minecraft_manager/ip.html new file mode 100644 index 0000000..ec1023e --- /dev/null +++ b/templates/minecraft_manager/ip.html @@ -0,0 +1,23 @@ +{% extends "minecraft_manager/dashboard.html" %} +{% load static %} +{% block after_h1 %}{{ ip.ip }}{% endblock %} +{% block section %} +
+ + + + + + + + + {% for i in ips %} + + + + + {% endfor %} + +
PlayerLast Used
{{ i.player.username }}{{ i.last_used }}
+
+{% endblock section %} \ No newline at end of file diff --git a/templates/minecraft_manager/player_info.html b/templates/minecraft_manager/player_info.html index 7602fd9..ed33468 100644 --- a/templates/minecraft_manager/player_info.html +++ b/templates/minecraft_manager/player_info.html @@ -52,14 +52,14 @@
- +

IPs

{% if form.ips %} {% for ip in form.ips %} - + - + {% if ip.associated %}