-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow choosing python versions for graders.
Custom migrations were written to safely transfer data, and handle deprecated languages.
- Loading branch information
1 parent
6a43c84
commit e55d1e6
Showing
17 changed files
with
374 additions
and
38 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
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
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,117 @@ | ||
# Generated by Django 4.2.16 on 2024-11-11 01:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def replace_language_with_default_language(apps, schema_editor): | ||
"""Creates a default :class:`.Language` model for each assignment. | ||
This converts the old language field to a foreign key to the new language model. | ||
""" | ||
|
||
Language = apps.get_model("assignments", "Language") | ||
db_alias = schema_editor.connection.alias | ||
python_310, py_created = Language.objects.using(db_alias).get_or_create( | ||
name="Python 3.10", | ||
executable="/usr/bin/python3.10", | ||
language="P", | ||
version=310, | ||
) | ||
|
||
# Keep backwards compatibility with Java assignments by making them | ||
# use python. | ||
java, java_created = Language.objects.using(db_alias).get_or_create( | ||
name="Python 3.10 (Deprecated)", | ||
executable="/usr/bin/python3.10", | ||
language="P", | ||
version=310, | ||
is_deprecated=True, | ||
use_java_folder=True, | ||
) | ||
|
||
Assignment = apps.get_model("assignments", "Assignment") | ||
for assignment in Assignment.objects.using(db_alias).all(): | ||
if assignment.language == "P": | ||
assignment.language_details = python_310 | ||
assignment.save() | ||
elif assignment.language == "J": | ||
assignment.language_details = java | ||
assignment.save() | ||
|
||
# avoid creating empty models | ||
if py_created and not python_310.assignment_set.exists(): | ||
python_310.delete() | ||
if java_created and not java.assignment_set.exists(): | ||
java.delete() | ||
|
||
|
||
def revert_default_language(apps, schema_editor): | ||
Assignment = apps.get_model("assignments", "Assignment") | ||
Language = apps.get_model("assignments", "Language") | ||
db_alias = schema_editor.connection.alias | ||
java = ( | ||
Language.objects.using(db_alias) | ||
.filter( | ||
language="P", | ||
is_deprecated=True, | ||
use_java_folder=True, | ||
name="Python 3.10 (Deprecated)", | ||
) | ||
.first() | ||
) | ||
for assignment in Assignment.objects.using(db_alias).all(): | ||
if java and assignment.language_details == java: | ||
assignment.language = "J" | ||
else: | ||
assignment.language = "P" | ||
assignment.save() | ||
|
||
|
||
# fmt: off | ||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('assignments', '0032_assignment_quiz_description_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Language', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('is_deprecated', models.BooleanField(default=False)), | ||
('language', models.CharField(choices=[('P', 'Python 3'), ('J', 'Java')], max_length=1)), | ||
('name', models.CharField(help_text='The name of the language', max_length=50)), | ||
('executable', models.CharField(help_text='The path to the language executable', max_length=100)), | ||
('use_java_folder', models.BooleanField(default=False, help_text="Store the assignment grader in the Java folder, regardless of language")), | ||
('version', models.PositiveSmallIntegerField(help_text="The version of the executable. 0 if executable is /dev/null.")), | ||
], | ||
options={'ordering': ['-language', '-version']}, | ||
), | ||
migrations.AddField( | ||
model_name="assignment", | ||
name="language_details", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=models.deletion.CASCADE, | ||
related_name="assignment_set", | ||
to="assignments.language", | ||
), | ||
), | ||
migrations.RunPython(replace_language_with_default_language, revert_default_language), | ||
migrations.AlterField( | ||
model_name="assignment", | ||
name="language_details", | ||
field=models.ForeignKey( | ||
null=False, | ||
on_delete=models.deletion.CASCADE, | ||
related_name="assignment_set", | ||
to="assignments.language", | ||
), | ||
), | ||
migrations.RemoveField( | ||
model_name='assignment', | ||
name='language', | ||
), | ||
|
||
] |
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
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
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
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
Oops, something went wrong.