* test: fix timestamp construction in several doc tests * refactor: rename date2datetime to datetime_from_date and clarify code * chore: helper to get tzinfo for PRODUCTION_TIMEZONE * fix: fix timezone handling in make_last_call() * test: fix datetime generation in doc.tests_charter * refactor: remove PRODUCTION_TIMEZONE setting Replaces the PRODUCTION_TIMEZONE setting with a constant, DEADLINE_TZINFO, in ietf.utils.timezone. * test: be more careful about timezone in tests_charter.py * test: be more careful about timezone in doc/tests.py * fix: fix timezone handling affecting doc.tests_draft * fix: fix timezone handling affecting tests_irsg_ballot.py * fix: fix timezone handling affecting tests_review.py * fix: fix timezone handling affecting last ietf.doc tests * fix: fix timezone handling affecting last ietf.group tests * fix: fix timezone handling affecting ietf.iesg tests * fix: handle timezones in get_8989_eligibility_querysets * fix: handle timezones affecting ietfauth tests * fix: return tz-aware datetime from utc_from_string * fix: specify timezone for constants in ipr_rfc_number() * fix: specify tz for ipr deadlines * fix: handle timezones affecting liaisons tests * fix: treat leap day in get_8989_eligibility_querysets() Manual cherry-pick of 248d6474 * test: treat leap day properly in nomcom tests * fix: fix timezone handling affecting nomcom tests * test: fix timezone handling in review tests * fix: fix timezone handling affecting secr.meetings tests * fix: handle both pytz and zoneinfo timezones in ietf.utils.timezone * fix: fix timezone handling affecting secr.proceedings tests * refactor: use make_aware() helper in secr.meetings tests * test: fix timezone handling in secr.telechat tests * fix: fix timezone handling affecting stats tests * fix: eliminate tz-naive helpers affecting sync email parsing * fix: include timezone data when serializing DeletedEvent data * fix: fix timezone handling affecting sync tests * style: remove unused import
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
# Generated by Django 2.2.28 on 2022-08-31 20:26
|
|
|
|
import datetime
|
|
import json
|
|
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
TZ_BEFORE = ZoneInfo('PST8PDT')
|
|
|
|
|
|
def forward(apps, schema_editor):
|
|
DeletedEvent = apps.get_model('doc', 'DeletedEvent')
|
|
for deleted_event in DeletedEvent.objects.all():
|
|
fields = json.loads(deleted_event.json)
|
|
replacements = {}
|
|
for k, v in fields.items():
|
|
if isinstance(v, str):
|
|
try:
|
|
dt = datetime.datetime.strptime(v, '%Y-%m-%d %H:%M:%S')
|
|
except:
|
|
pass
|
|
else:
|
|
replacements[k] = dt.replace(tzinfo=TZ_BEFORE).astimezone(datetime.timezone.utc).isoformat()
|
|
if len(replacements) > 0:
|
|
fields.update(replacements)
|
|
deleted_event.json = json.dumps(fields)
|
|
deleted_event.save()
|
|
|
|
|
|
def reverse(apps, schema_editor):
|
|
DeletedEvent = apps.get_model('doc', 'DeletedEvent')
|
|
for deleted_event in DeletedEvent.objects.all():
|
|
fields = json.loads(deleted_event.json)
|
|
replacements = {}
|
|
for k, v in fields.items():
|
|
if isinstance(v, str) and 'T' in v:
|
|
try:
|
|
dt = datetime.datetime.fromisoformat(v)
|
|
except:
|
|
pass
|
|
else:
|
|
replacements[k] = dt.astimezone(TZ_BEFORE).replace(tzinfo=None).strftime('%Y-%m-%d %H:%M:%S')
|
|
if len(replacements) > 0:
|
|
fields.update(replacements)
|
|
deleted_event.json = json.dumps(fields)
|
|
deleted_event.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('doc', '0045_use_timezone_now_for_doc_models'),
|
|
('utils', '0003_pause_to_change_use_tz'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(forward, reverse),
|
|
]
|