Code reformatting
This commit is contained in:
parent
c620342b42
commit
e8c00bf5c8
@ -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
|
||||
|
@ -5,10 +5,12 @@ from .models import Service, User
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
||||
|
||||
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)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = "core"
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-14 14:40
|
||||
|
||||
import core.models
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
import core.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -13,47 +14,146 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0011_update_proxy_permissions'),
|
||||
("auth", "0011_update_proxy_permissions"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
name="User",
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('username', models.TextField(default=core.models._default_uuid, unique=True)),
|
||||
('email', models.EmailField(max_length=254, unique=True)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("password", models.CharField(max_length=128, verbose_name="password")),
|
||||
(
|
||||
"last_login",
|
||||
models.DateTimeField(
|
||||
blank=True, null=True, verbose_name="last login"
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_superuser",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Designates that this user has all permissions without explicitly assigning them.",
|
||||
verbose_name="superuser status",
|
||||
),
|
||||
),
|
||||
(
|
||||
"first_name",
|
||||
models.CharField(
|
||||
blank=True, max_length=30, verbose_name="first name"
|
||||
),
|
||||
),
|
||||
(
|
||||
"last_name",
|
||||
models.CharField(
|
||||
blank=True, max_length=150, verbose_name="last name"
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_staff",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Designates whether the user can log into this admin site.",
|
||||
verbose_name="staff status",
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_active",
|
||||
models.BooleanField(
|
||||
default=True,
|
||||
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
|
||||
verbose_name="active",
|
||||
),
|
||||
),
|
||||
(
|
||||
"date_joined",
|
||||
models.DateTimeField(
|
||||
default=django.utils.timezone.now, verbose_name="date joined"
|
||||
),
|
||||
),
|
||||
(
|
||||
"username",
|
||||
models.TextField(default=core.models._default_uuid, unique=True),
|
||||
),
|
||||
("email", models.EmailField(max_length=254, unique=True)),
|
||||
(
|
||||
"groups",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
|
||||
related_name="user_set",
|
||||
related_query_name="user",
|
||||
to="auth.Group",
|
||||
verbose_name="groups",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user_permissions",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text="Specific permissions for this user.",
|
||||
related_name="user_set",
|
||||
related_query_name="user",
|
||||
to="auth.Permission",
|
||||
verbose_name="user permissions",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
"verbose_name": "user",
|
||||
"verbose_name_plural": "users",
|
||||
"abstract": False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
managers=[("objects", django.contrib.auth.models.UserManager()),],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Service',
|
||||
name="Service",
|
||||
fields=[
|
||||
('uuid', models.UUIDField(default=core.models._default_uuid, primary_key=True, serialize=False)),
|
||||
('name', models.TextField(max_length=64)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('link', models.URLField(blank=True)),
|
||||
('origins', models.TextField(default='*')),
|
||||
('status', models.CharField(choices=[('AC', 'Active'), ('AR', 'Archived')], db_index=True, default='AC', max_length=2)),
|
||||
('collaborators', models.ManyToManyField(blank=True, related_name='collaborating_services', to=settings.AUTH_USER_MODEL)),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owning_services', to=settings.AUTH_USER_MODEL)),
|
||||
(
|
||||
"uuid",
|
||||
models.UUIDField(
|
||||
default=core.models._default_uuid,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
("name", models.TextField(max_length=64)),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
("link", models.URLField(blank=True)),
|
||||
("origins", models.TextField(default="*")),
|
||||
(
|
||||
"status",
|
||||
models.CharField(
|
||||
choices=[("AC", "Active"), ("AR", "Archived")],
|
||||
db_index=True,
|
||||
default="AC",
|
||||
max_length=2,
|
||||
),
|
||||
),
|
||||
(
|
||||
"collaborators",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
related_name="collaborating_services",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="owning_services",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
@ -6,12 +6,11 @@ from django.db import migrations
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
("core", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='service',
|
||||
options={'ordering': ['name', 'uuid']},
|
||||
name="service", options={"ordering": ["name", "uuid"]},
|
||||
),
|
||||
]
|
||||
|
@ -6,8 +6,8 @@ from django.contrib.auth.models import AbstractUser
|
||||
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
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def _default_uuid():
|
||||
@ -179,7 +179,4 @@ class Service(models.Model):
|
||||
}
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
"dashboard:service",
|
||||
kwargs={"pk": self.pk},
|
||||
)
|
||||
return reverse("dashboard:service", kwargs={"pk": self.pk},)
|
||||
|
@ -5,5 +5,7 @@ from django.views.generic import RedirectView
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", RedirectView.as_view(url=reverse_lazy("dashboard:dashboard")), name="index"),
|
||||
path(
|
||||
"", RedirectView.as_view(url=reverse_lazy("dashboard:dashboard")), name="index"
|
||||
),
|
||||
]
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
class IndexView(TemplateView):
|
||||
template_name = "dashboard/pages/index.html"
|
||||
template_name = "dashboard/pages/index.html"
|
||||
|
@ -1,11 +1,13 @@
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class DashboardConfig(AppConfig):
|
||||
name = 'dashboard'
|
||||
name = "dashboard"
|
||||
|
||||
def ready(self):
|
||||
if not settings.ACCOUNT_SIGNUPS_ENABLED:
|
||||
# Normally you'd do this in settings.py, but this must be done _after_ apps are enabled
|
||||
from allauth.account.adapter import DefaultAccountAdapter
|
||||
|
||||
DefaultAccountAdapter.is_open_for_signup = lambda k, v: False
|
||||
|
@ -1,7 +1,8 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404, reverse
|
||||
from django.utils import timezone
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.views.generic import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
@ -11,13 +12,13 @@ from django.views.generic import (
|
||||
UpdateView,
|
||||
)
|
||||
from rules.contrib.views import PermissionRequiredMixin
|
||||
from django.db.models import Q
|
||||
|
||||
from analytics.models import Session
|
||||
from core.models import Service
|
||||
|
||||
from .forms import ServiceForm
|
||||
from .mixins import DateRangeMixin
|
||||
from core.models import Service
|
||||
|
||||
|
||||
class DashboardView(LoginRequiredMixin, DateRangeMixin, TemplateView):
|
||||
template_name = "dashboard/pages/dashboard.html"
|
||||
@ -77,7 +78,9 @@ class ServiceUpdateView(
|
||||
return reverse("dashboard:service", kwargs={"pk": self.object.uuid})
|
||||
|
||||
|
||||
class ServiceDeleteView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, DeleteView):
|
||||
class ServiceDeleteView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, DeleteView
|
||||
):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "dashboard/pages/service_delete.html"
|
||||
|
Loading…
Reference in New Issue
Block a user