Skip to content

Commit

Permalink
Ruff it
Browse files Browse the repository at this point in the history
  • Loading branch information
Almad committed Dec 29, 2024
1 parent ca7be43 commit a89d1d2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 15 deletions.
31 changes: 21 additions & 10 deletions ddcz/migrations/0003_plurals_20241229_1738.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@


class Migration(migrations.Migration):

dependencies = [
('ddcz', '0002_auto_20240818_1740'),
("ddcz", "0002_auto_20240818_1740"),
]

operations = [
migrations.AlterModelOptions(
name='rangerspell',
options={'verbose_name': 'Hraníčářské kouzlo', 'verbose_name_plural': 'Hraníčářská kouzla'},
name="rangerspell",
options={
"verbose_name": "Hraníčářské kouzlo",
"verbose_name_plural": "Hraníčářská kouzla",
},
),
migrations.AlterModelOptions(
name='scheduledemail',
options={'verbose_name': 'Plánovaný e-mail', 'verbose_name_plural': 'Plánované e-maily'},
name="scheduledemail",
options={
"verbose_name": "Plánovaný e-mail",
"verbose_name_plural": "Plánované e-maily",
},
),
migrations.AlterModelOptions(
name='schedulednotification',
options={'verbose_name': 'Plánovaná notifikace', 'verbose_name_plural': 'Plánované notifikace'},
name="schedulednotification",
options={
"verbose_name": "Plánovaná notifikace",
"verbose_name_plural": "Plánované notifikace",
},
),
migrations.AlterModelOptions(
name='userprofile',
options={'verbose_name': 'Uživatelský profil', 'verbose_name_plural': 'Uživatelské profily'},
name="userprofile",
options={
"verbose_name": "Uživatelský profil",
"verbose_name_plural": "Uživatelské profily",
},
),
]
9 changes: 4 additions & 5 deletions ddcz/migrations/0004_market_created.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@


class Migration(migrations.Migration):

dependencies = [
('ddcz', '0003_plurals_20241229_1738'),
("ddcz", "0003_plurals_20241229_1738"),
]

operations = [
migrations.AddField(
model_name='market',
name='created',
field=models.DateTimeField(blank=True, null=True, verbose_name='Přidáno'),
model_name="market",
name="created",
field=models.DateTimeField(blank=True, null=True, verbose_name="Přidáno"),
),
]
58 changes: 58 additions & 0 deletions ddcz/migrations/0005_market_dates_20241229_1747.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 3.1.14 on 2024-12-29 16:47

from django.db import migrations
from datetime import datetime

import sentry_sdk


def migrate_dates(apps, schema_editor):
Market = apps.get_model("ddcz", "Market")

for market in Market.objects.all():
if not market.published_varchar:
sentry_sdk.capture_message(
f"Market entry without date",

Check failure on line 15 in ddcz/migrations/0005_market_dates_20241229_1747.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F541)

ddcz/migrations/0005_market_dates_20241229_1747.py:15:17: F541 f-string without any placeholders
level="error",
extras={
"market_id": market.id,
"invalid_date": market.published_varchar,
},
)

try:
parsed_date = datetime.strptime(market.published_varchar, "%-d. %-m. %Y")
except ValueError:
# If both formats fail, report to Sentry
sentry_sdk.capture_message(
f"Failed to parse date in Market record",

Check failure on line 28 in ddcz/migrations/0005_market_dates_20241229_1747.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F541)

ddcz/migrations/0005_market_dates_20241229_1747.py:28:17: F541 f-string without any placeholders
level="error",
extras={
"market_id": market.id,
"invalid_date": market.published_varchar,
},
)
continue

market.created = parsed_date
market.save()


def reverse_migrate_dates(apps, schema_editor):
Market = apps.get_model("ddcz", "Market")

for market in Market.objects.all():
if not market.created:
continue

# Convert back to the original format with leading zeros
market.published_varchar = market.created.strftime("%d. %m. %Y")
market.save()


class Migration(migrations.Migration):
dependencies = [
("ddcz", "0004_market_created"),
]

operations = [migrations.RunPython(migrate_dates, reverse_migrate_dates)]

0 comments on commit a89d1d2

Please sign in to comment.