Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 'create_problem' command work and add options #2256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion judge/management/commands/create_problem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand

from judge.models import Problem, ProblemGroup, ProblemType
from judge.models.runtime import Language
DapperX marked this conversation as resolved.
Show resolved Hide resolved
DapperX marked this conversation as resolved.
Show resolved Hide resolved


class Command(BaseCommand):
Expand All @@ -12,12 +13,28 @@ def add_arguments(self, parser):
parser.add_argument('body', help='problem description')
parser.add_argument('type', help='problem type')
parser.add_argument('group', help='problem group')
parser.add_argument('time_limit', help='time limit in (fractional) seconds')
parser.add_argument('memory_limit', help='memory limit in kilobytes')
parser.add_argument('points', help='problem points')
parser.add_argument('--partial-points', help='allow partial points',
action='store_true', default=False, dest='pr_pts')
DapperX marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--all-languages', help='allow all languages',
action='store_true', default=False, dest='all_lang')
DapperX marked this conversation as resolved.
Show resolved Hide resolved

def handle(self, *args, **options):
problem = Problem()
problem.code = options['code']
problem.name = options['name']
problem.description = options['body']
problem.group = ProblemGroup.objects.get(name=options['group'])
problem.types = [ProblemType.objects.get(name=options['type'])]
problem.time_limit = options["time_limit"]
DapperX marked this conversation as resolved.
Show resolved Hide resolved
problem.memory_limit = options["memory_limit"]
problem.points = options["points"]
DapperX marked this conversation as resolved.
Show resolved Hide resolved
if options['pr_pts']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this if necessary? It seems we can just do

problem.partial = options['pr_pts']

Copy link
Author

@DapperX DapperX May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this for not assuming the default value of this field, i.e., if Allows partial points is enabled by default at some points, the code should still work, though I don't have strong opinions about this.

problem.partial = 1
problem.save()

problem.types.set([ProblemType.objects.get(name=options['type'])])
if options['all_lang']:
problem.allowed_languages.set([l for l in Language.objects.all()])
DapperX marked this conversation as resolved.
Show resolved Hide resolved
problem.save()