NDOJ/judge/management/commands/copy_language.py

34 lines
1.2 KiB
Python
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
from django.core.management.base import BaseCommand, CommandError
from judge.models import Language, LanguageLimit
class Command(BaseCommand):
2022-05-14 17:57:27 +00:00
help = "allows the problems that allow <source> to be submitted in <target>"
2020-01-21 06:35:58 +00:00
def add_arguments(self, parser):
2022-05-14 17:57:27 +00:00
parser.add_argument("source", help="language to copy from")
parser.add_argument("target", help="language to copy to")
2020-01-21 06:35:58 +00:00
def handle(self, *args, **options):
try:
2022-05-14 17:57:27 +00:00
source = Language.objects.get(key=options["source"])
2020-01-21 06:35:58 +00:00
except Language.DoesNotExist:
2022-05-14 17:57:27 +00:00
raise CommandError("Invalid source language: %s" % options["source"])
2020-01-21 06:35:58 +00:00
try:
2022-05-14 17:57:27 +00:00
target = Language.objects.get(key=options["target"])
2020-01-21 06:35:58 +00:00
except Language.DoesNotExist:
2022-05-14 17:57:27 +00:00
raise CommandError("Invalid target language: %s" % options["target"])
2020-01-21 06:35:58 +00:00
target.problem_set.set(source.problem_set.all())
2022-05-14 17:57:27 +00:00
LanguageLimit.objects.bulk_create(
LanguageLimit(
problem=ll.problem,
language=target,
time_limit=ll.time_limit,
memory_limit=ll.memory_limit,
)
for ll in LanguageLimit.objects.filter(language=source)
)