Skip to content

Commit

Permalink
Fix populate_aip_stored_dates command
Browse files Browse the repository at this point in the history
This updates the command to get the timezone using Django's utility
instead of pytz.
  • Loading branch information
replaceafill committed Mar 22, 2024
1 parent 3309322 commit 44a9dc2
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
import os
from datetime import datetime

import pytz
from common.management.commands import StorageServiceCommand
from django.conf import settings
from django.core.management.base import CommandError
from django.utils.timezone import get_current_timezone
from locations.models.package import Package
from locations.models.package import Space

# Suppress the logging from models/package.py.
logging.config.dictConfig({"version": 1, "disable_existing_loggers": True})

TIMEZONE = pytz.timezone(settings.TIME_ZONE)


class Command(StorageServiceCommand):
help = __doc__
Expand Down Expand Up @@ -55,6 +52,8 @@ def handle(self, *args, **options):
success_count = 0
skipped_count = 0

tz = get_current_timezone()

for aip in aips:
# Skip AIPs that already have datestamps.
if aip.stored_date is not None:
Expand All @@ -71,7 +70,7 @@ def handle(self, *args, **options):
)
continue

aip.stored_date = datetime.fromtimestamp(int(modified_unix), tz=TIMEZONE)
aip.stored_date = datetime.fromtimestamp(int(modified_unix), tz=tz)
aip.save()
success_count += 1

Expand Down

0 comments on commit 44a9dc2

Please sign in to comment.