From 6fa049e1b1b01a62598e73f91855237cc2383cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 15 Jan 2023 23:39:52 +0100 Subject: [PATCH] Sort and clean up imports --- poetry.lock | 20 ++++++++++++++++++- pyproject.toml | 1 + src/web/common/util/plots.py | 16 +++++++-------- src/web/common/util/time.py | 7 ++++--- src/web/tracker/admin.py | 3 ++- src/web/tracker/forms.py | 3 ++- src/web/tracker/migrations/0001_initial.py | 2 +- .../0002_alter_session_duration_manual.py | 1 + .../0004_alter_session_duration_manual.py | 1 + .../migrations/0005_auto_20230109_1843.py | 3 ++- .../migrations/0006_auto_20230109_1904.py | 3 ++- src/web/tracker/models.py | 12 +++++------ src/web/tracker/templatetags/version.py | 5 +++-- src/web/tracker/views.py | 17 ++++++++-------- src/web/web/settings.py | 3 +-- src/web/web/urls.py | 3 +-- tests/test_time.py | 3 ++- 17 files changed, 63 insertions(+), 40 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8e155b3..fbab599 100644 --- a/poetry.lock +++ b/poetry.lock @@ -417,6 +417,24 @@ files = [ {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] +[[package]] +name = "isort" +version = "5.11.4" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.7.0" +files = [ + {file = "isort-5.11.4-py3-none-any.whl", hash = "sha256:c033fd0edb91000a7f09527fe5c75321878f98322a77ddcc81adbd83724afb7b"}, + {file = "isort-5.11.4.tar.gz", hash = "sha256:6db30c5ded9815d813932c04c2f85a360bcdd35fed496f4d8f35495ef0a261b6"}, +] + +[package.extras] +colors = ["colorama (>=0.4.3,<0.5.0)"] +pipfile-deprecated-finder = ["pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] + [[package]] name = "jsbeautifier" version = "1.14.7" @@ -1279,4 +1297,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "01d5c9b89b638c993f8540298dedfa79321b3aac1b2af70da58ef77706d0a113" +content-hash = "bf02e951b8c14fbe6f2709b6df7f9664f99ad5fbf7195d8e7b18c8574d00e683" diff --git a/pyproject.toml b/pyproject.toml index 4f44a19..710fd28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ django-extensions = "^3.2.1" werkzeug = "^2.2.2" djhtml = "^1.5.2" djlint = "^1.19.11" +isort = "^5.11.4" [build-system] requires = ["poetry-core"] diff --git a/src/web/common/util/plots.py b/src/web/common/util/plots.py index 95b2170..ff39ce5 100644 --- a/src/web/common/util/plots.py +++ b/src/web/common/util/plots.py @@ -1,14 +1,12 @@ -import pandas as pd -import matplotlib.pyplot as plt -from matplotlib.dates import date2num import base64 -from io import BytesIO -from tracker.models import Session -from django.db.models import Sum, IntegerField, F -from django.db.models.functions import TruncDay -import logging from datetime import datetime -from django.db.models import QuerySet +from io import BytesIO + +import matplotlib.pyplot as plt +import pandas as pd +from django.db.models import F, IntegerField, QuerySet, Sum +from django.db.models.functions import TruncDay +from tracker.models import Session def key_value_to_value_value(data): diff --git a/src/web/common/util/time.py b/src/web/common/util/time.py index d73df88..0e5b45e 100644 --- a/src/web/common/util/time.py +++ b/src/web/common/util/time.py @@ -1,7 +1,8 @@ -from datetime import datetime, timedelta -from django.conf import settings -from zoneinfo import ZoneInfo import re +from datetime import datetime, timedelta +from zoneinfo import ZoneInfo + +from django.conf import settings def now() -> datetime: diff --git a/src/web/tracker/admin.py b/src/web/tracker/admin.py index 0bdd83d..36af422 100644 --- a/src/web/tracker/admin.py +++ b/src/web/tracker/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Game, Purchase, Platform, Session + +from .models import Game, Platform, Purchase, Session # Register your models here. admin.site.register(Game) diff --git a/src/web/tracker/forms.py b/src/web/tracker/forms.py index 13f0165..7cfda40 100644 --- a/src/web/tracker/forms.py +++ b/src/web/tracker/forms.py @@ -1,5 +1,6 @@ from django import forms -from .models import Session, Purchase, Game, Platform + +from .models import Game, Platform, Purchase, Session class SessionForm(forms.ModelForm): diff --git a/src/web/tracker/migrations/0001_initial.py b/src/web/tracker/migrations/0001_initial.py index b7107cc..36e18b8 100644 --- a/src/web/tracker/migrations/0001_initial.py +++ b/src/web/tracker/migrations/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 4.1.4 on 2023-01-02 18:27 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/web/tracker/migrations/0002_alter_session_duration_manual.py b/src/web/tracker/migrations/0002_alter_session_duration_manual.py index 1411fd4..09f15d2 100644 --- a/src/web/tracker/migrations/0002_alter_session_duration_manual.py +++ b/src/web/tracker/migrations/0002_alter_session_duration_manual.py @@ -1,6 +1,7 @@ # Generated by Django 4.1.4 on 2023-01-02 18:55 import datetime + from django.db import migrations, models diff --git a/src/web/tracker/migrations/0004_alter_session_duration_manual.py b/src/web/tracker/migrations/0004_alter_session_duration_manual.py index d6e1cad..90e1039 100644 --- a/src/web/tracker/migrations/0004_alter_session_duration_manual.py +++ b/src/web/tracker/migrations/0004_alter_session_duration_manual.py @@ -1,6 +1,7 @@ # Generated by Django 4.1.5 on 2023-01-09 14:49 import datetime + from django.db import migrations, models diff --git a/src/web/tracker/migrations/0005_auto_20230109_1843.py b/src/web/tracker/migrations/0005_auto_20230109_1843.py index ab1988f..c529636 100644 --- a/src/web/tracker/migrations/0005_auto_20230109_1843.py +++ b/src/web/tracker/migrations/0005_auto_20230109_1843.py @@ -1,8 +1,9 @@ # Generated by Django 4.1.5 on 2023-01-09 17:43 -from django.db import migrations from datetime import timedelta +from django.db import migrations + def set_duration_calculated_none_to_zero(apps, schema_editor): Session = apps.get_model("tracker", "Session") diff --git a/src/web/tracker/migrations/0006_auto_20230109_1904.py b/src/web/tracker/migrations/0006_auto_20230109_1904.py index dfdb52c..d0a9e04 100644 --- a/src/web/tracker/migrations/0006_auto_20230109_1904.py +++ b/src/web/tracker/migrations/0006_auto_20230109_1904.py @@ -1,8 +1,9 @@ # Generated by Django 4.1.5 on 2023-01-09 18:04 -from django.db import migrations from datetime import timedelta +from django.db import migrations + def set_duration_manual_none_to_zero(apps, schema_editor): Session = apps.get_model("tracker", "Session") diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index 01321e5..d1810bf 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -1,11 +1,11 @@ -from django.db import models from datetime import datetime, timedelta -from django.conf import settings -from zoneinfo import ZoneInfo -from common.util.time import format_duration -from django.db.models import Sum, F -from django.db.models import Manager from typing import Any +from zoneinfo import ZoneInfo + +from common.util.time import format_duration +from django.conf import settings +from django.db import models +from django.db.models import F, Manager, Sum class Game(models.Model): diff --git a/src/web/tracker/templatetags/version.py b/src/web/tracker/templatetags/version.py index be57455..46e4f55 100644 --- a/src/web/tracker/templatetags/version.py +++ b/src/web/tracker/templatetags/version.py @@ -1,7 +1,8 @@ +import os +import time + from django import template from django.conf import settings -import time -import os register = template.Library() diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index 4ce6550..0675dc9 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -1,14 +1,13 @@ -from django.shortcuts import render, redirect - -from .models import Game, Platform, Purchase, Session -from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm -from datetime import datetime, timedelta +from datetime import datetime from zoneinfo import ZoneInfo -from django.conf import settings -from common.util.time import now as now_with_tz, format_duration -from django.db.models import Sum -import logging + from common.util.plots import playtime_over_time_chart +from common.util.time import now as now_with_tz +from django.conf import settings +from django.shortcuts import redirect, render + +from .forms import GameForm, PlatformForm, PurchaseForm, SessionForm +from .models import Game, Platform, Purchase, Session def model_counts(request): diff --git a/src/web/web/settings.py b/src/web/web/settings.py index a0ca0ac..c0a9f66 100644 --- a/src/web/web/settings.py +++ b/src/web/web/settings.py @@ -10,9 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.1/ref/settings/ """ -from pathlib import Path -import logging import os +from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent diff --git a/src/web/web/urls.py b/src/web/web/urls.py index 8e43fbf..029f9a7 100644 --- a/src/web/web/urls.py +++ b/src/web/web/urls.py @@ -13,11 +13,10 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings from django.contrib import admin from django.urls import include, path from django.views.generic import RedirectView -from django.conf import settings - urlpatterns = [ path("", RedirectView.as_view(url="/tracker/list-sessions")), diff --git a/tests/test_time.py b/tests/test_time.py index e2ae81a..2630401 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -1,7 +1,8 @@ import unittest -from web.common.util.time import format_duration from datetime import timedelta +from web.common.util.time import format_duration + class FormatDurationTest(unittest.TestCase): def setUp(self) -> None: