-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to convert to datetimes
- Loading branch information
1 parent
e4f1a3d
commit d0fa9a5
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
] |