Skip to content

Commit

Permalink
Try again with simpler strp directive (refs #195)
Browse files Browse the repository at this point in the history
  • Loading branch information
Almad committed Dec 29, 2024
1 parent 25c8c4f commit b942984
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ddcz/migrations/0006_dates_vol2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.1.14 on 2024-12-29 19:13

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(
"Market entry without date",
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:
sentry_sdk.capture_message(
"Failed to parse date in Market record",
level="error",
extras={
"market_id": market.id,
"invalid_date": market.published_varchar,
},
)
continue

market.created = parsed_date
market.save()


class Migration(migrations.Migration):
dependencies = [
("ddcz", "0005_market_dates_20241229_1747"),
]

operations = [migrations.RunPython(migrate_dates)]
3 changes: 3 additions & 0 deletions ddcz/models/used/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Market(models.Model):

created = models.DateTimeField(blank=True, null=True, verbose_name="Přidáno")

def __str__(self):
return f"{self.name} ({self.group}) z {self.published}"

@property
def published(self):
# Windows workaround as `%-d` is platform-specific
Expand Down

0 comments on commit b942984

Please sign in to comment.