From fe8e7666700468445f53cf7efaff5fc7e17b70b4 Mon Sep 17 00:00:00 2001 From: "R. Miles McCain" Date: Mon, 29 Mar 2021 14:37:59 +0000 Subject: [PATCH] Format --- shynet/a17t/templatetags/pagination.py | 6 +--- shynet/analytics/migrations/0001_initial.py | 8 +++-- .../migrations/0004_auto_20210328_1514.py | 36 +++++++++++-------- .../migrations/0005_auto_20210328_1518.py | 14 ++++---- .../analytics/migrations/0006_hit_service.py | 36 ++++++++++--------- .../migrations/0007_auto_20210328_1634.py | 8 +++-- .../migrations/0008_session_is_bounce.py | 12 ++++--- shynet/analytics/tasks.py | 2 +- shynet/analytics/views/ingress.py | 4 ++- shynet/core/management/commands/demo.py | 9 +++-- shynet/core/management/commands/hostname.py | 3 +- .../core/management/commands/registeradmin.py | 3 +- shynet/core/management/commands/whitelabel.py | 3 +- shynet/core/migrations/0001_initial.py | 4 ++- .../migrations/0002_auto_20200415_1742.py | 3 +- shynet/core/models.py | 5 ++- shynet/dashboard/templatetags/helpers.py | 7 +++- shynet/dashboard/views.py | 8 ++--- shynet/shynet/settings.py | 16 ++++++--- shynet/shynet/urls.py | 2 +- 20 files changed, 116 insertions(+), 73 deletions(-) diff --git a/shynet/a17t/templatetags/pagination.py b/shynet/a17t/templatetags/pagination.py index 7871c36..6f9aa51 100644 --- a/shynet/a17t/templatetags/pagination.py +++ b/shynet/a17t/templatetags/pagination.py @@ -16,11 +16,7 @@ def pagination( after_current_pages=4, ): url_parameters = urlencode( - [ - (key, value) - for key, value in request.GET.items() - if key != "page" - ] + [(key, value) for key, value in request.GET.items() if key != "page"] ) before = max(page.number - before_current_pages - 1, 0) diff --git a/shynet/analytics/migrations/0001_initial.py b/shynet/analytics/migrations/0001_initial.py index b88ee8b..5f58667 100644 --- a/shynet/analytics/migrations/0001_initial.py +++ b/shynet/analytics/migrations/0001_initial.py @@ -60,7 +60,9 @@ class Migration(migrations.Migration): ), ), ], - options={"ordering": ["-start_time"],}, + options={ + "ordering": ["-start_time"], + }, ), migrations.CreateModel( name="Hit", @@ -90,7 +92,9 @@ class Migration(migrations.Migration): ), ), ], - options={"ordering": ["-start_time"],}, + options={ + "ordering": ["-start_time"], + }, ), migrations.AddIndex( model_name="session", diff --git a/shynet/analytics/migrations/0004_auto_20210328_1514.py b/shynet/analytics/migrations/0004_auto_20210328_1514.py index 45afe74..af8be87 100644 --- a/shynet/analytics/migrations/0004_auto_20210328_1514.py +++ b/shynet/analytics/migrations/0004_auto_20210328_1514.py @@ -7,32 +7,40 @@ import django.utils.timezone class Migration(migrations.Migration): dependencies = [ - ('analytics', '0003_auto_20200502_1227'), + ("analytics", "0003_auto_20200502_1227"), ] operations = [ migrations.AlterField( - model_name='hit', - name='last_seen', + model_name="hit", + name="last_seen", field=models.DateTimeField(default=django.utils.timezone.now), ), migrations.AlterField( - model_name='hit', - name='start_time', - field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + model_name="hit", + name="start_time", + field=models.DateTimeField( + db_index=True, default=django.utils.timezone.now + ), ), migrations.AlterField( - model_name='session', - name='last_seen', - field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + model_name="session", + name="last_seen", + field=models.DateTimeField( + db_index=True, default=django.utils.timezone.now + ), ), migrations.AlterField( - model_name='session', - name='start_time', - field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + model_name="session", + name="start_time", + field=models.DateTimeField( + db_index=True, default=django.utils.timezone.now + ), ), migrations.AddIndex( - model_name='session', - index=models.Index(fields=['service', '-last_seen'], name='analytics_s_service_10bb96_idx'), + model_name="session", + index=models.Index( + fields=["service", "-last_seen"], name="analytics_s_service_10bb96_idx" + ), ), ] diff --git a/shynet/analytics/migrations/0005_auto_20210328_1518.py b/shynet/analytics/migrations/0005_auto_20210328_1518.py index 2280ec3..6ed752c 100644 --- a/shynet/analytics/migrations/0005_auto_20210328_1518.py +++ b/shynet/analytics/migrations/0005_auto_20210328_1518.py @@ -7,18 +7,20 @@ import django.utils.timezone class Migration(migrations.Migration): dependencies = [ - ('analytics', '0004_auto_20210328_1514'), + ("analytics", "0004_auto_20210328_1514"), ] operations = [ migrations.AlterField( - model_name='hit', - name='last_seen', - field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + model_name="hit", + name="last_seen", + field=models.DateTimeField( + db_index=True, default=django.utils.timezone.now + ), ), migrations.AlterField( - model_name='hit', - name='load_time', + model_name="hit", + name="load_time", field=models.FloatField(db_index=True, null=True), ), ] diff --git a/shynet/analytics/migrations/0006_hit_service.py b/shynet/analytics/migrations/0006_hit_service.py index bf8d593..8889a43 100644 --- a/shynet/analytics/migrations/0006_hit_service.py +++ b/shynet/analytics/migrations/0006_hit_service.py @@ -5,34 +5,36 @@ from django.db import migrations, models import django.db.models.deletion from django.db.models import Subquery, OuterRef -def add_service_to_hits(_a, _b): - service = Session.objects.filter( - pk=OuterRef('session') - ).values_list( - 'service' - )[:1] - Hit.objects.update( - service=Subquery(service) - ) +def add_service_to_hits(_a, _b): + service = Session.objects.filter(pk=OuterRef("session")).values_list("service")[:1] + + Hit.objects.update(service=Subquery(service)) + class Migration(migrations.Migration): dependencies = [ - ('core', '0008_auto_20200628_1403'), - ('analytics', '0005_auto_20210328_1518'), + ("core", "0008_auto_20200628_1403"), + ("analytics", "0005_auto_20210328_1518"), ] operations = [ migrations.AddField( - model_name='hit', - name='service', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.service'), + model_name="hit", + name="service", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="core.service", + ), ), migrations.RunPython(add_service_to_hits, lambda: ()), migrations.AlterField( - model_name='hit', - name='service', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.service'), + model_name="hit", + name="service", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="core.service" + ), ), ] diff --git a/shynet/analytics/migrations/0007_auto_20210328_1634.py b/shynet/analytics/migrations/0007_auto_20210328_1634.py index 7efceff..e90597a 100644 --- a/shynet/analytics/migrations/0007_auto_20210328_1634.py +++ b/shynet/analytics/migrations/0007_auto_20210328_1634.py @@ -6,12 +6,14 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('analytics', '0006_hit_service'), + ("analytics", "0006_hit_service"), ] operations = [ migrations.AddIndex( - model_name='hit', - index=models.Index(fields=['service', '-start_time'], name='analytics_h_service_f4f41e_idx'), + model_name="hit", + index=models.Index( + fields=["service", "-start_time"], name="analytics_h_service_f4f41e_idx" + ), ), ] diff --git a/shynet/analytics/migrations/0008_session_is_bounce.py b/shynet/analytics/migrations/0008_session_is_bounce.py index cbc7d34..0e69eea 100644 --- a/shynet/analytics/migrations/0008_session_is_bounce.py +++ b/shynet/analytics/migrations/0008_session_is_bounce.py @@ -5,19 +5,23 @@ from ..models import Session, Hit from django.db import migrations, models from django.db.models import Subquery, OuterRef + def update_bounce_stats(_a, _b): - Session.objects.all().annotate(hit_count=models.Count("hit")).filter(hit_count__gt=1).update(is_bounce=False) + Session.objects.all().annotate(hit_count=models.Count("hit")).filter( + hit_count__gt=1 + ).update(is_bounce=False) + class Migration(migrations.Migration): dependencies = [ - ('analytics', '0007_auto_20210328_1634'), + ("analytics", "0007_auto_20210328_1634"), ] operations = [ migrations.AddField( - model_name='session', - name='is_bounce', + model_name="session", + name="is_bounce", field=models.BooleanField(db_index=True, default=True), ), migrations.RunPython(update_bounce_stats, lambda: ()), diff --git a/shynet/analytics/tasks.py b/shynet/analytics/tasks.py index d68ac58..c28727c 100644 --- a/shynet/analytics/tasks.py +++ b/shynet/analytics/tasks.py @@ -184,7 +184,7 @@ def ingress_request( load_time=payload.get("loadTime"), start_time=time, last_seen=time, - service=service + service=service, ) # Recalculate whether the session is a bounce diff --git a/shynet/analytics/views/ingress.py b/shynet/analytics/views/ingress.py index 0c1ded2..9a5107b 100644 --- a/shynet/analytics/views/ingress.py +++ b/shynet/analytics/views/ingress.py @@ -112,7 +112,9 @@ class ScriptView(ValidateServiceOriginsMixin, View): endpoint = ( reverse( "ingress:endpoint_script", - kwargs={"service_uuid": self.kwargs.get("service_uuid"),}, + kwargs={ + "service_uuid": self.kwargs.get("service_uuid"), + }, ) if self.kwargs.get("identifier") == None else reverse( diff --git a/shynet/core/management/commands/demo.py b/shynet/core/management/commands/demo.py index f66a2f3..b93d265 100644 --- a/shynet/core/management/commands/demo.py +++ b/shynet/core/management/commands/demo.py @@ -54,15 +54,18 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "name", type=str, + "name", + type=str, ) parser.add_argument("owner_email", type=str) parser.add_argument( - "avg", type=int, + "avg", + type=int, ) parser.add_argument("deviation", type=float, default=0.4) parser.add_argument( - "days", type=int, + "days", + type=int, ) parser.add_argument("load_time", type=float, default=1000) diff --git a/shynet/core/management/commands/hostname.py b/shynet/core/management/commands/hostname.py index dcb7059..73bbe03 100644 --- a/shynet/core/management/commands/hostname.py +++ b/shynet/core/management/commands/hostname.py @@ -14,7 +14,8 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "hostname", type=str, + "hostname", + type=str, ) def handle(self, *args, **options): diff --git a/shynet/core/management/commands/registeradmin.py b/shynet/core/management/commands/registeradmin.py index dd62388..e2a55ec 100644 --- a/shynet/core/management/commands/registeradmin.py +++ b/shynet/core/management/commands/registeradmin.py @@ -14,7 +14,8 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "email", type=str, + "email", + type=str, ) def handle(self, *args, **options): diff --git a/shynet/core/management/commands/whitelabel.py b/shynet/core/management/commands/whitelabel.py index fe3fb95..69b6961 100644 --- a/shynet/core/management/commands/whitelabel.py +++ b/shynet/core/management/commands/whitelabel.py @@ -14,7 +14,8 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "name", type=str, + "name", + type=str, ) def handle(self, *args, **options): diff --git a/shynet/core/migrations/0001_initial.py b/shynet/core/migrations/0001_initial.py index b146950..9da701e 100644 --- a/shynet/core/migrations/0001_initial.py +++ b/shynet/core/migrations/0001_initial.py @@ -112,7 +112,9 @@ class Migration(migrations.Migration): "verbose_name_plural": "users", "abstract": False, }, - managers=[("objects", django.contrib.auth.models.UserManager()),], + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], ), migrations.CreateModel( name="Service", diff --git a/shynet/core/migrations/0002_auto_20200415_1742.py b/shynet/core/migrations/0002_auto_20200415_1742.py index b41752f..dff2743 100644 --- a/shynet/core/migrations/0002_auto_20200415_1742.py +++ b/shynet/core/migrations/0002_auto_20200415_1742.py @@ -11,6 +11,7 @@ class Migration(migrations.Migration): operations = [ migrations.AlterModelOptions( - name="service", options={"ordering": ["name", "uuid"]}, + name="service", + options={"ordering": ["name", "uuid"]}, ), ] diff --git a/shynet/core/models.py b/shynet/core/models.py index 60bdb76..e67f614 100644 --- a/shynet/core/models.py +++ b/shynet/core/models.py @@ -244,4 +244,7 @@ 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}, + ) diff --git a/shynet/dashboard/templatetags/helpers.py b/shynet/dashboard/templatetags/helpers.py index d553435..a494c2c 100644 --- a/shynet/dashboard/templatetags/helpers.py +++ b/shynet/dashboard/templatetags/helpers.py @@ -44,7 +44,12 @@ def country_name(isocode): @register.simple_tag def relative_stat_tone( - start, end, good="UP", good_classes=None, bad_classes=None, neutral_classes=None, + start, + end, + good="UP", + good_classes=None, + bad_classes=None, + neutral_classes=None, ): good_classes = good_classes or "~positive" bad_classes = bad_classes or "~critical" diff --git a/shynet/dashboard/views.py b/shynet/dashboard/views.py index 0190e4a..c071143 100644 --- a/shynet/dashboard/views.py +++ b/shynet/dashboard/views.py @@ -22,9 +22,7 @@ from .forms import ServiceForm from .mixins import DateRangeMixin -class DashboardView( - LoginRequiredMixin, DateRangeMixin, ListView -): +class DashboardView(LoginRequiredMixin, DateRangeMixin, ListView): model = Service template_name = "dashboard/pages/dashboard.html" paginate_by = 5 @@ -38,7 +36,9 @@ class DashboardView( data = super().get_context_data(**kwargs) for service in data["object_list"]: - service.stats = service.get_core_stats(self.get_start_date(), self.get_end_date()) + service.stats = service.get_core_stats( + self.get_start_date(), self.get_end_date() + ) return data diff --git a/shynet/shynet/settings.py b/shynet/shynet/settings.py index afab570..c7086bc 100644 --- a/shynet/shynet/settings.py +++ b/shynet/shynet/settings.py @@ -58,7 +58,7 @@ INSTALLED_APPS = [ "allauth", "allauth.account", "allauth.socialaccount", - "debug_toolbar" + "debug_toolbar", ] MIDDLEWARE = [ @@ -147,9 +147,15 @@ AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, - {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, - {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, ] # Logging @@ -250,7 +256,7 @@ LOGIN_REDIRECT_URL = "/" SITE_ID = 1 INTERNAL_IPS = [ - '127.0.0.1', + "127.0.0.1", ] # Celery diff --git a/shynet/shynet/urls.py b/shynet/shynet/urls.py index 0df3737..7264261 100644 --- a/shynet/shynet/urls.py +++ b/shynet/shynet/urls.py @@ -18,7 +18,7 @@ from django.urls import include, path import debug_toolbar urlpatterns = [ - path('__debug__/', include(debug_toolbar.urls)), + path("__debug__/", include(debug_toolbar.urls)), path("admin/", admin.site.urls), path("accounts/", include("allauth.urls")), path("ingress/", include(("analytics.ingress_urls", "ingress")), name="ingress"),