Add and use pre-commit hooks

This commit is contained in:
Joakim Hellsén 2025-11-28 04:44:07 +01:00
commit b2eef830d8
No known key found for this signature in database
10 changed files with 66 additions and 18 deletions

View file

@ -132,7 +132,7 @@ class Command(BaseCommand):
f"{len(self._organization_cache)} orgs, "
f"{len(self._drop_campaign_cache)} campaigns, "
f"{len(self._channel_cache)} channels, "
f"{len(self._benefit_cache)} benefits."
f"{len(self._benefit_cache)} benefits.",
)
except (FileNotFoundError, OSError, RuntimeError):
# If preload fails for any reason, continue without it

View file

@ -82,7 +82,10 @@ class Migration(migrations.Migration):
(
"id",
models.TextField(
help_text="The unique Twitch identifier for the organization.", primary_key=True, serialize=False, verbose_name="Organization ID"
help_text="The unique Twitch identifier for the organization.",
primary_key=True,
serialize=False,
verbose_name="Organization ID",
),
),
("name", models.TextField(help_text="Display name of the organization.", unique=True, verbose_name="Name")),
@ -179,7 +182,10 @@ class Migration(migrations.Migration):
(
"benefits",
models.ManyToManyField(
help_text="Benefits unlocked by this drop.", related_name="drops", through="twitch.DropBenefitEdge", to="twitch.dropbenefit"
help_text="Benefits unlocked by this drop.",
related_name="drops",
through="twitch.DropBenefitEdge",
to="twitch.dropbenefit",
),
),
(
@ -200,7 +206,9 @@ class Migration(migrations.Migration):
model_name="dropbenefitedge",
name="drop",
field=models.ForeignKey(
help_text="The time-based drop in this relationship.", on_delete=django.db.models.deletion.CASCADE, to="twitch.timebaseddrop"
help_text="The time-based drop in this relationship.",
on_delete=django.db.models.deletion.CASCADE,
to="twitch.timebaseddrop",
),
),
migrations.CreateModel(

View file

@ -434,8 +434,9 @@ class GameDetailView(DetailView):
.select_related("game__owner")
.prefetch_related(
Prefetch(
"time_based_drops", queryset=TimeBasedDrop.objects.prefetch_related(Prefetch("benefits", queryset=DropBenefit.objects.order_by("name")))
)
"time_based_drops",
queryset=TimeBasedDrop.objects.prefetch_related(Prefetch("benefits", queryset=DropBenefit.objects.order_by("name"))),
),
)
.order_by("-end_at")
)
@ -580,12 +581,12 @@ def debug_view(request: HttpRequest) -> HttpResponse:
# Campaigns with missing or obviously broken images (empty or not starting with http)
broken_image_campaigns: QuerySet[DropCampaign] = DropCampaign.objects.filter(
Q(image_url__isnull=True) | Q(image_url__exact="") | ~Q(image_url__startswith="http")
Q(image_url__isnull=True) | Q(image_url__exact="") | ~Q(image_url__startswith="http"),
).select_related("game")
# Benefits with missing images
broken_benefit_images: QuerySet[DropBenefit] = DropBenefit.objects.annotate(trimmed_url=Trim("image_asset_url")).filter(
Q(image_asset_url__isnull=True) | Q(trimmed_url__exact="") | ~Q(image_asset_url__startswith="http")
Q(image_asset_url__isnull=True) | Q(trimmed_url__exact="") | ~Q(image_asset_url__startswith="http"),
)
# Time-based drops without any benefits
@ -593,7 +594,7 @@ def debug_view(request: HttpRequest) -> HttpResponse:
# Campaigns with invalid dates (start after end or missing either)
invalid_date_campaigns: QuerySet[DropCampaign] = DropCampaign.objects.filter(
Q(start_at__gt=F("end_at")) | Q(start_at__isnull=True) | Q(end_at__isnull=True)
Q(start_at__gt=F("end_at")) | Q(start_at__isnull=True) | Q(end_at__isnull=True),
).select_related("game")
# Duplicate campaign names per game. We retrieve the game's name for user-friendly display.
@ -729,7 +730,7 @@ class ChannelDetailView(DetailView):
queryset=TimeBasedDrop.objects.prefetch_related(
Prefetch("benefits", queryset=DropBenefit.objects.order_by("name")),
),
)
),
)
.order_by("-start_at")
)