Improve admin panel & display

This commit is contained in:
R. Miles McCain 2020-04-15 10:00:20 -04:00
parent ea78f88377
commit 0b574227fb
No known key found for this signature in database
GPG Key ID: 91CB47BDDF2671A5
6 changed files with 61 additions and 7 deletions

View File

@ -2,8 +2,25 @@ from django.contrib import admin
from .models import Hit, Session
admin.site.register(Session)
class HitInline(admin.TabularInline):
model = Hit
fk_name = "session"
extra = 0
admin.site.register(Hit)
class SessionAdmin(admin.ModelAdmin):
list_display = ("uuid", "service", "start_time", "identifier", "ip", "asn", "country")
list_display_links = ("uuid",)
search_fields = ("ip", "user_agent", "device", "device_type", "identifier", "asn", "time_zone")
list_filter = ("device_type",)
inlines = [HitInline]
# Register your models here.
admin.site.register(Session, SessionAdmin)
class HitAdmin(admin.ModelAdmin):
list_display = ("session", "initial", "start_time", "heartbeats", "tracker", "load_time")
list_display_links = ("session",)
search_fields = ("initial", "tracker", "location", "referrer")
list_filter = ("initial", "tracker")
admin.site.register(Hit, HitAdmin)

View File

@ -5,6 +5,7 @@ from django.db import models
from django.utils import timezone
from core.models import Service
from django.shortcuts import reverse
def _default_uuid():
@ -62,6 +63,15 @@ class Session(models.Model):
def duration(self):
return self.last_seen - self.start_time
def __str__(self):
return f"{self.identifier if self.identifier != '' else 'Anonymous'} @ {self.service.name} [{str(self.uuid)[:6]}]"
def get_absolute_url(self):
return reverse(
"dashboard:service_session",
kwargs={"pk": self.service.pk, "session_pk": self.uuid},
)
class Hit(models.Model):
session = models.ForeignKey(Session, on_delete=models.CASCADE, db_index=True)
@ -71,7 +81,9 @@ class Hit(models.Model):
start_time = models.DateTimeField(auto_now_add=True, db_index=True)
last_seen = models.DateTimeField(auto_now_add=True)
heartbeats = models.IntegerField(default=0)
tracker = models.TextField() # Tracking pixel or JS
tracker = models.TextField(
choices=[("JS", "JavaScript"), ("PIXEL", "Pixel (noscript)")]
) # Tracking pixel or JS
# Advanced page information
location = models.TextField(blank=True, db_index=True)
@ -89,3 +101,9 @@ class Hit(models.Model):
@property
def duration(self):
return self.last_seen - self.start_time
def get_absolute_url(self):
return reverse(
"dashboard:service_session",
kwargs={"pk": self.session.service.pk, "session_pk": self.session.pk},
)

View File

@ -4,4 +4,11 @@ from django.contrib.auth.admin import UserAdmin
from .models import Service, User
admin.site.register(User, UserAdmin)
admin.site.register(Service)
class ServiceAdmin(admin.ModelAdmin):
list_display = ("name", "link", "owner", "status")
list_display_links = ("name",)
list_filter = ("status",)
search_fields = ("name", "link", "owner")
admin.site.register(Service, ServiceAdmin)

View File

@ -7,6 +7,7 @@ from django.db import models
from django.db.models.functions import TruncDate
from django.db.utils import NotSupportedError
from django.utils import timezone
from django.shortcuts import reverse
def _default_uuid():
@ -173,3 +174,9 @@ class Service(models.Model):
),
"online": True,
}
def get_absolute_url(self):
return reverse(
"dashboard:service",
kwargs={"pk": self.pk},
)

View File

@ -68,6 +68,11 @@
{% if user.is_authenticated %}
{% if user.is_superuser %}
{% url 'admin:index' as url %}
{% include 'dashboard/includes/sidebar_portal.html' with label="Admin" url=url %}
{% endif %}
{% url 'account_email' as url %}
{% include 'dashboard/includes/sidebar_portal.html' with label="Emails" url=url %}

View File

@ -98,7 +98,7 @@
<tbody>
{% for referrer in stats.referrers %}
<tr>
<td>{{referrer.referrer|default:"Direct"|urldisplay}}</td>
<td>{{referrer.referrer|default:"Direct"|urlize}}</td>
<td class="rf">{{referrer.count|intcomma}}</td>
</tr>
{% endfor %}
@ -178,7 +178,7 @@
</table>
</div>
</div>
<div class="card ~neutral !low">
<div class="card ~neutral !low limited-height py-2">
{% include 'dashboard/includes/session_list.html' %}
<hr class="sep h-8">
<a href="{% url 'dashboard:service_session_list' service.uuid %}" class="button ~neutral w-auto">View more sessions