Skip to content

Commit

Permalink
Add migration to convert to datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher authored and quantum5 committed May 8, 2021
1 parent e4f1a3d commit d0fa9a5
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions judge/migrations/0118_convert_to_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 2.2.17 on 2021-04-27 14:46

from django.db import migrations, models
from django.db.models import F
from django.utils import timezone


def convert_to_datetime(apps, schema_editor):
Contest = apps.get_model('judge', 'Contest')
Submission = apps.get_model('judge', 'Submission')

Submission.objects.filter(was_rejudged=True).update(rejudged_date=F('judged_date'))
Submission.objects.filter(is_locked=True).update(locked_after=timezone.now())
Contest.objects.filter(is_locked=True).update(locked_after=F('end_time'))


def convert_to_boolean(apps, schema_editor):
Contest = apps.get_model('judge', 'Contest')
Submission = apps.get_model('judge', 'Submission')

now = timezone.now()

Submission.objects.filter(rejudged_date__isnull=False).update(was_rejudged=True)
Submission.objects.filter(locked_after__lt=now).update(is_locked=True)
Contest.objects.filter(locked_after__lt=now).update(is_locked=True)


class Migration(migrations.Migration):

dependencies = [
('judge', '0117_remove_private_messages'),
]

operations = [
migrations.AddField(
model_name='contest',
name='locked_after',
field=models.DateTimeField(blank=True, help_text='Prevent submissions from this contest from being rejudged after this date.', null=True, verbose_name='contest lock'),
),
migrations.AddField(
model_name='submission',
name='locked_after',
field=models.DateTimeField(blank=True, null=True, verbose_name='submission lock'),
),
migrations.AddField(
model_name='submission',
name='rejudged_date',
field=models.DateTimeField(blank=True, null=True, verbose_name='last rejudge date by admin'),
),
migrations.RunPython(convert_to_datetime, convert_to_boolean, atomic=True),
migrations.RemoveField(
model_name='contest',
name='is_locked',
),
migrations.RemoveField(
model_name='submission',
name='is_locked',
),
migrations.RemoveField(
model_name='submission',
name='was_rejudged',
),
]

0 comments on commit d0fa9a5

Please sign in to comment.