From 73f18704319c3ee36b9f5fb15548487ca0613eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Thu, 1 May 2025 02:47:09 +0200 Subject: [PATCH] Remove django-auto-prefetch --- .vscode/settings.json | 2 ++ core/migrations/0001_initial.py | 50 ++++----------------------------- core/models.py | 35 +++++++++++------------ pyproject.toml | 50 +++------------------------------ 4 files changed, 29 insertions(+), 108 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ac6d774..e4712b4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,7 @@ "createcachetable", "createsuperuser", "djade", + "djlint", "docstrings", "dotenv", "dropcampaign", @@ -43,6 +44,7 @@ "psycopg", "PUID", "pydocstyle", + "pytest", "pyupgrade", "requirepass", "rewardcampaign", diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py index 7907944..9bfac35 100644 --- a/core/migrations/0001_initial.py +++ b/core/migrations/0001_initial.py @@ -1,11 +1,9 @@ -# Generated by Django 5.2 on 2025-05-01 00:02 +# Generated by Django 5.2 on 2025-05-01 00:45 from __future__ import annotations -import auto_prefetch import django.contrib.auth.models import django.contrib.auth.validators import django.db.models.deletion -import django.db.models.manager import django.utils.timezone from django.db import migrations, models @@ -39,13 +37,7 @@ class Migration(migrations.Migration): ], options={ "ordering": ["display_name"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), migrations.CreateModel( name="Organization", @@ -65,13 +57,7 @@ class Migration(migrations.Migration): ], options={ "ordering": ["name"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), migrations.CreateModel( name="ScrapedJson", @@ -84,13 +70,7 @@ class Migration(migrations.Migration): ], options={ "ordering": ["-created_at"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), migrations.CreateModel( name="User", @@ -203,7 +183,7 @@ class Migration(migrations.Migration): ), ( "game", - auto_prefetch.ForeignKey( + models.ForeignKey( help_text="The game associated with this campaign", null=True, on_delete=django.db.models.deletion.SET_NULL, @@ -213,7 +193,7 @@ class Migration(migrations.Migration): ), ( "owner", - auto_prefetch.ForeignKey( + models.ForeignKey( help_text="The organization running this campaign", null=True, on_delete=django.db.models.deletion.SET_NULL, @@ -224,13 +204,7 @@ class Migration(migrations.Migration): ], options={ "ordering": ["end_at"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), migrations.CreateModel( name="Benefit", @@ -263,7 +237,7 @@ class Migration(migrations.Migration): ("modified_at", models.DateTimeField(auto_now=True)), ( "game", - auto_prefetch.ForeignKey( + models.ForeignKey( null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="benefits", @@ -272,7 +246,7 @@ class Migration(migrations.Migration): ), ( "owner_organization", - auto_prefetch.ForeignKey( + models.ForeignKey( null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="benefits", @@ -282,13 +256,7 @@ class Migration(migrations.Migration): ], options={ "ordering": ["-twitch_created_at"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), migrations.CreateModel( name="TimeBasedDrop", @@ -329,7 +297,7 @@ class Migration(migrations.Migration): ), ( "campaign", - auto_prefetch.ForeignKey( + models.ForeignKey( help_text="The campaign this drop belongs to", on_delete=django.db.models.deletion.CASCADE, related_name="time_based_drops", @@ -339,12 +307,6 @@ class Migration(migrations.Migration): ], options={ "ordering": ["required_minutes_watched"], - "abstract": False, - "base_manager_name": "prefetch_manager", }, - managers=[ - ("objects", django.db.models.manager.Manager()), - ("prefetch_manager", django.db.models.manager.Manager()), - ], ), ] diff --git a/core/models.py b/core/models.py index 57eee26..ef96a33 100644 --- a/core/models.py +++ b/core/models.py @@ -3,7 +3,6 @@ from __future__ import annotations import logging from typing import ClassVar -import auto_prefetch from django.contrib.auth.models import AbstractUser from django.db import models @@ -21,7 +20,7 @@ class User(AbstractUser): return self.username -class ScrapedJson(auto_prefetch.Model): +class ScrapedJson(models.Model): """The JSON data from the Twitch API. This data is from https://github.com/TheLovinator1/TwitchDropsMiner. @@ -32,7 +31,7 @@ class ScrapedJson(auto_prefetch.Model): modified_at = models.DateTimeField(auto_now=True) imported_at = models.DateTimeField(null=True) - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["-created_at"] def __str__(self) -> str: @@ -40,7 +39,7 @@ class ScrapedJson(auto_prefetch.Model): return f"{'' if self.imported_at else 'Not imported - '}{self.created_at}" -class Organization(auto_prefetch.Model): +class Organization(models.Model): """Represents the owner/organization of a Drop Campaign.""" org_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the owner.") @@ -49,7 +48,7 @@ class Organization(auto_prefetch.Model): created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["name"] def __str__(self) -> str: @@ -57,7 +56,7 @@ class Organization(auto_prefetch.Model): return f"{self.name or self.org_id} - {self.created_at}" -class Game(auto_prefetch.Model): +class Game(models.Model): """The game the drop campaign is for. Note that some reward campaigns are not tied to a game.""" game_id = models.TextField(primary_key=True, help_text="The Twitch ID of the game.") @@ -69,7 +68,7 @@ class Game(auto_prefetch.Model): created_at = models.DateTimeField(auto_now_add=True, help_text="When the game was first added to the database.") modified_at = models.DateTimeField(auto_now=True, help_text="When the game was last modified.") - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["display_name"] def __str__(self) -> str: @@ -77,7 +76,7 @@ class Game(auto_prefetch.Model): return f"{self.display_name or self.game_id} - {self.created_at}" -class DropCampaign(auto_prefetch.Model): +class DropCampaign(models.Model): """This is the drop campaign we will see on the front end.""" campaign_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop campaign.") @@ -89,14 +88,14 @@ class DropCampaign(auto_prefetch.Model): image_url = models.URLField(blank=True, help_text="The URL to the image for the drop campaign.") name = models.TextField(blank=True, help_text="The name of the drop campaign.") status = models.TextField(blank=True, help_text="The status of the drop campaign.") - game = auto_prefetch.ForeignKey( + game = models.ForeignKey( to=Game, help_text="The game associated with this campaign", null=True, on_delete=models.SET_NULL, related_name="drop_campaigns", ) - owner = auto_prefetch.ForeignKey( + owner = models.ForeignKey( Organization, help_text="The organization running this campaign", null=True, @@ -110,7 +109,7 @@ class DropCampaign(auto_prefetch.Model): ) modified_at = models.DateTimeField(auto_now=True, help_text="When the drop campaign was last modified.") - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["end_at"] def __str__(self) -> str: @@ -118,7 +117,7 @@ class DropCampaign(auto_prefetch.Model): return f"{self.name or self.campaign_id} - {self.created_at}" -class Benefit(auto_prefetch.Model): +class Benefit(models.Model): """Represents a specific reward/benefit within a Drop.""" benefit_id = models.TextField(primary_key=True, unique=True, help_text="Twitch's unique ID for the benefit") @@ -130,8 +129,8 @@ class Benefit(auto_prefetch.Model): image_asset_url = models.URLField(blank=True, help_text="The URL to the image for the benefit.") is_ios_available = models.BooleanField(null=True, help_text="If the benefit is farmable on iOS.") name = models.TextField(blank=True, help_text="Name of the benefit/reward") - game = auto_prefetch.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True) - owner_organization = auto_prefetch.ForeignKey( + game = models.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True) + owner_organization = models.ForeignKey( Organization, on_delete=models.SET_NULL, related_name="benefits", @@ -142,7 +141,7 @@ class Benefit(auto_prefetch.Model): created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["-twitch_created_at"] def __str__(self) -> str: @@ -150,7 +149,7 @@ class Benefit(auto_prefetch.Model): return f"{self.name or self.benefit_id} - {self.twitch_created_at}" -class TimeBasedDrop(auto_prefetch.Model): +class TimeBasedDrop(models.Model): """Represents a time-based drop within a Campaign.""" drop_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop.") @@ -164,7 +163,7 @@ class TimeBasedDrop(auto_prefetch.Model): start_at = models.DateTimeField(help_text="Drop start time") end_at = models.DateTimeField(help_text="Drop end time") - campaign = auto_prefetch.ForeignKey( + campaign = models.ForeignKey( DropCampaign, help_text="The campaign this drop belongs to", on_delete=models.CASCADE, @@ -179,7 +178,7 @@ class TimeBasedDrop(auto_prefetch.Model): created_at = models.DateTimeField(auto_now_add=True, help_text="When the drop was first added to the database.") modified_at = models.DateTimeField(auto_now=True, help_text="When the drop was last modified.") - class Meta(auto_prefetch.Model.Meta): + class Meta: ordering: ClassVar[list[str]] = ["required_minutes_watched"] def __str__(self) -> str: diff --git a/pyproject.toml b/pyproject.toml index 083d727..1f9e105 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,27 +10,17 @@ dependencies = [ "django", "platformdirs", "python-dotenv", - "django-auto-prefetch", ] -# You can install development dependencies with `uv install --dev`. -# Or you can install them with `uv install --dev -r requirements-dev.txt`. -# uv can be replaced with `pip`if you don't have uv installed. [dependency-groups] -dev = ["pre-commit", "pytest", "pytest-django", "ruff"] +dev = ["pytest", "pytest-django"] -# https://docs.astral.sh/ruff/settings/ [tool.ruff] -# Enable all rules lint.select = ["ALL"] - -# https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html lint.pydocstyle.convention = "google" - -# Add "from __future__ import annotations" to all files lint.isort.required-imports = ["from __future__ import annotations"] +line-length = 120 -# Ignore some rules lint.ignore = [ "CPY001", # Checks for the absence of copyright notices within Python files. "D100", # Checks for undocumented public module definitions. @@ -57,9 +47,6 @@ lint.ignore = [ "W191", # Checks for indentation that uses tabs. ] -# Default is 88 characters -line-length = 120 - [tool.ruff.lint.per-file-ignores] "**/tests/**" = [ "ARG", # Unused function args -> fixtures nevertheless are functionally relevant... @@ -72,51 +59,22 @@ line-length = 120 "RUF012", # Checks for mutable default values in class attributes. ] -# https://www.djlint.com/ + [tool.djlint] -# Set a profile for the template language. The profile will enable linter rules that apply to your template language, and may also change reformatting. profile = "django" - -# Formatter will attempt to format template syntax inside of tag attributes. format_attribute_template_tags = true - -# Format contents of style tags using css-beautify format_css = true - -# Format contents of script tags using js-beautify. format_js = true +ignore = "H006" -# Ignore some rules -ignore = "H006" # Img tag should have height and width attributes. - -# https://pytest-django.readthedocs.io/en/latest/ [tool.pytest.ini_options] -# Where our Django settings are located. DJANGO_SETTINGS_MODULE = "core.settings" - -# Only run tests in files that match this pattern. python_files = ["*_test.py"] - -# Enable logging in the console. log_cli = true log_cli_level = "INFO" log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)" log_cli_date_format = "%Y-%m-%d %H:%M:%S" - -# Only check /tests/ directory for tests. -# This will speed up the test run significantly. (5.16s -> 0.25s) testpaths = ["tests"] -[tool.mypy] -plugins = ["mypy_django_plugin.main"] - [tool.django-stubs] django_settings_module = "core.settings" - -[tool.black] -line-length = 120 -preview = true -unstable = true - -[tool.isort] -profile = "black"