Code reformatting
This commit is contained in:
@@ -2,25 +2,52 @@ from django.contrib import admin
|
||||
|
||||
from .models import Hit, Session
|
||||
|
||||
|
||||
class HitInline(admin.TabularInline):
|
||||
model = Hit
|
||||
fk_name = "session"
|
||||
extra = 0
|
||||
|
||||
|
||||
class SessionAdmin(admin.ModelAdmin):
|
||||
list_display = ("uuid", "service", "start_time", "identifier", "ip", "asn", "country")
|
||||
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")
|
||||
search_fields = (
|
||||
"ip",
|
||||
"user_agent",
|
||||
"device",
|
||||
"device_type",
|
||||
"identifier",
|
||||
"asn",
|
||||
"time_zone",
|
||||
)
|
||||
list_filter = ("device_type",)
|
||||
inlines = [HitInline]
|
||||
|
||||
|
||||
admin.site.register(Session, SessionAdmin)
|
||||
|
||||
|
||||
class HitAdmin(admin.ModelAdmin):
|
||||
list_display = ("session", "initial", "start_time", "heartbeats", "tracker", "load_time")
|
||||
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)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-14 14:40
|
||||
|
||||
import analytics.models
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
import analytics.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -10,70 +11,115 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
("core", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Session',
|
||||
name="Session",
|
||||
fields=[
|
||||
('uuid', models.UUIDField(default=analytics.models._default_uuid, primary_key=True, serialize=False)),
|
||||
('identifier', models.TextField(blank=True, db_index=True)),
|
||||
('start_time', models.DateTimeField(auto_now_add=True, db_index=True)),
|
||||
('last_seen', models.DateTimeField(auto_now_add=True)),
|
||||
('user_agent', models.TextField()),
|
||||
('browser', models.TextField()),
|
||||
('device', models.TextField()),
|
||||
('device_type', models.CharField(choices=[('PHONE', 'Phone'), ('TABLET', 'Tablet'), ('DESKTOP', 'Desktop'), ('ROBOT', 'Robot'), ('OTHER', 'Other')], default='OTHER', max_length=7)),
|
||||
('os', models.TextField()),
|
||||
('ip', models.GenericIPAddressField(db_index=True)),
|
||||
('asn', models.TextField(blank=True)),
|
||||
('country', models.TextField(blank=True)),
|
||||
('longitude', models.FloatField(null=True)),
|
||||
('latitude', models.FloatField(null=True)),
|
||||
('time_zone', models.TextField(blank=True)),
|
||||
('service', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Service')),
|
||||
(
|
||||
"uuid",
|
||||
models.UUIDField(
|
||||
default=analytics.models._default_uuid,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
("identifier", models.TextField(blank=True, db_index=True)),
|
||||
("start_time", models.DateTimeField(auto_now_add=True, db_index=True)),
|
||||
("last_seen", models.DateTimeField(auto_now_add=True)),
|
||||
("user_agent", models.TextField()),
|
||||
("browser", models.TextField()),
|
||||
("device", models.TextField()),
|
||||
(
|
||||
"device_type",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("PHONE", "Phone"),
|
||||
("TABLET", "Tablet"),
|
||||
("DESKTOP", "Desktop"),
|
||||
("ROBOT", "Robot"),
|
||||
("OTHER", "Other"),
|
||||
],
|
||||
default="OTHER",
|
||||
max_length=7,
|
||||
),
|
||||
),
|
||||
("os", models.TextField()),
|
||||
("ip", models.GenericIPAddressField(db_index=True)),
|
||||
("asn", models.TextField(blank=True)),
|
||||
("country", models.TextField(blank=True)),
|
||||
("longitude", models.FloatField(null=True)),
|
||||
("latitude", models.FloatField(null=True)),
|
||||
("time_zone", models.TextField(blank=True)),
|
||||
(
|
||||
"service",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="core.Service"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-start_time'],
|
||||
},
|
||||
options={"ordering": ["-start_time"],},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Hit',
|
||||
name="Hit",
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('initial', models.BooleanField(db_index=True, default=True)),
|
||||
('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()),
|
||||
('location', models.TextField(blank=True, db_index=True)),
|
||||
('referrer', models.TextField(blank=True, db_index=True)),
|
||||
('load_time', models.FloatField(null=True)),
|
||||
('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='analytics.Session')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("initial", models.BooleanField(db_index=True, default=True)),
|
||||
("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()),
|
||||
("location", models.TextField(blank=True, db_index=True)),
|
||||
("referrer", models.TextField(blank=True, db_index=True)),
|
||||
("load_time", models.FloatField(null=True)),
|
||||
(
|
||||
"session",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="analytics.Session",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-start_time'],
|
||||
},
|
||||
options={"ordering": ["-start_time"],},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='session',
|
||||
index=models.Index(fields=['service', '-start_time'], name='analytics_s_service_4b1137_idx'),
|
||||
model_name="session",
|
||||
index=models.Index(
|
||||
fields=["service", "-start_time"], name="analytics_s_service_4b1137_idx"
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='session',
|
||||
index=models.Index(fields=['service', 'identifier'], name='analytics_s_service_82ab21_idx'),
|
||||
model_name="session",
|
||||
index=models.Index(
|
||||
fields=["service", "identifier"], name="analytics_s_service_82ab21_idx"
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='hit',
|
||||
index=models.Index(fields=['session', '-start_time'], name='analytics_h_session_b2667f_idx'),
|
||||
model_name="hit",
|
||||
index=models.Index(
|
||||
fields=["session", "-start_time"], name="analytics_h_session_b2667f_idx"
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='hit',
|
||||
index=models.Index(fields=['session', 'location'], name='analytics_h_session_775f5a_idx'),
|
||||
model_name="hit",
|
||||
index=models.Index(
|
||||
fields=["session", "location"], name="analytics_h_session_775f5a_idx"
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='hit',
|
||||
index=models.Index(fields=['session', 'referrer'], name='analytics_h_session_98b8bf_idx'),
|
||||
model_name="hit",
|
||||
index=models.Index(
|
||||
fields=["session", "referrer"], name="analytics_h_session_98b8bf_idx"
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -6,13 +6,15 @@ from django.db import migrations, models
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('analytics', '0001_initial'),
|
||||
("analytics", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='hit',
|
||||
name='tracker',
|
||||
field=models.TextField(choices=[('JS', 'JavaScript'), ('PIXEL', 'Pixel (noscript)')]),
|
||||
model_name="hit",
|
||||
name="tracker",
|
||||
field=models.TextField(
|
||||
choices=[("JS", "JavaScript"), ("PIXEL", "Pixel (noscript)")]
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -2,10 +2,10 @@ import json
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.shortcuts import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from core.models import Service
|
||||
from django.shortcuts import reverse
|
||||
|
||||
|
||||
def _default_uuid():
|
||||
|
||||
@@ -6,8 +6,9 @@ import user_agents
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.utils import timezone
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from core.models import Service
|
||||
|
||||
from .models import Hit, Session
|
||||
|
||||
Reference in New Issue
Block a user