add custom checker
This commit is contained in:
parent
184fa549e0
commit
25ebc87db8
8 changed files with 601 additions and 2 deletions
155
judge/migrations/0098_auto_20200123_2136.py
Normal file
155
judge/migrations/0098_auto_20200123_2136.py
Normal file
File diff suppressed because one or more lines are too long
30
judge/migrations/0099_auto_20200123_2228.py
Normal file
30
judge/migrations/0099_auto_20200123_2228.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 2.2.9 on 2020-01-23 22:28
|
||||
|
||||
from django.db import migrations, models
|
||||
import judge.models.problem_data
|
||||
import judge.utils.problem_data
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('judge', '0098_auto_20200123_2136'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='problemdata',
|
||||
name='custom_checker',
|
||||
field=models.FileField(blank=True, null=True, storage=judge.utils.problem_data.ProblemDataStorage(), upload_to=judge.models.problem_data.problem_directory_file, verbose_name='custom checker file'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='problemdata',
|
||||
name='checker',
|
||||
field=models.CharField(blank=True, choices=[('standard', 'Standard'), ('floats', 'Floats'), ('floatsabs', 'Floats (absolute)'), ('floatsrel', 'Floats (relative)'), ('rstripped', 'Non-trailing spaces'), ('sorted', 'Unordered'), ('identical', 'Byte identical'), ('linecount', 'Line-by-line'), ('custom', 'Custom checker')], max_length=10, verbose_name='checker'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='problemtestcase',
|
||||
name='checker',
|
||||
field=models.CharField(blank=True, choices=[('standard', 'Standard'), ('floats', 'Floats'), ('floatsabs', 'Floats (absolute)'), ('floatsrel', 'Floats (relative)'), ('rstripped', 'Non-trailing spaces'), ('sorted', 'Unordered'), ('identical', 'Byte identical'), ('linecount', 'Line-by-line'), ('custom', 'Custom checker')], max_length=10, verbose_name='checker'),
|
||||
),
|
||||
]
|
|
@ -1,6 +1,7 @@
|
|||
import errno
|
||||
import os
|
||||
|
||||
from django.core.validators import FileExtensionValidator
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -28,6 +29,7 @@ CHECKERS = (
|
|||
('sorted', _('Unordered')),
|
||||
('identical', _('Byte identical')),
|
||||
('linecount', _('Line-by-line')),
|
||||
('custom', _('Custom checker')),
|
||||
)
|
||||
|
||||
|
||||
|
@ -44,7 +46,9 @@ class ProblemData(models.Model):
|
|||
checker = models.CharField(max_length=10, verbose_name=_('checker'), choices=CHECKERS, blank=True)
|
||||
checker_args = models.TextField(verbose_name=_('checker arguments'), blank=True,
|
||||
help_text=_('checker arguments as a JSON object'))
|
||||
|
||||
custom_checker = models.FileField(verbose_name=_('custom checker file'), storage=problem_data_storage, null=True, blank=True,
|
||||
upload_to=problem_directory_file,
|
||||
validators=[FileExtensionValidator(allowed_extensions=['py'])])
|
||||
__original_zipfile = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -69,6 +73,8 @@ class ProblemData(models.Model):
|
|||
self.zipfile.name = _problem_directory_file(new, self.zipfile.name)
|
||||
if self.generator:
|
||||
self.generator.name = _problem_directory_file(new, self.generator.name)
|
||||
if self.custom_checker:
|
||||
self.custom_checker.name = _problem_directory_file(new, self.custom_checker.name)
|
||||
self.save()
|
||||
_update_code.alters_data = True
|
||||
|
||||
|
|
|
@ -64,6 +64,11 @@ class ProblemDataCompiler(object):
|
|||
cases.append(batch)
|
||||
|
||||
def make_checker(case):
|
||||
if (case.checker == 'custom'):
|
||||
custom_checker_path = split_path_first(case.custom_checker.name)
|
||||
if len(custom_checker_path) != 2:
|
||||
raise ProblemDataError(_('How did you corrupt the custom checker path?'))
|
||||
return(custom_checker_path[1])
|
||||
if case.checker_args:
|
||||
return {
|
||||
'name': case.checker,
|
||||
|
|
|
@ -50,7 +50,7 @@ class ProblemDataForm(ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = ProblemData
|
||||
fields = ['zipfile', 'generator', 'output_limit', 'output_prefix', 'checker', 'checker_args']
|
||||
fields = ['zipfile', 'generator', 'output_limit', 'output_prefix', 'checker', 'checker_args', 'custom_checker']
|
||||
widgets = {
|
||||
'checker_args': HiddenInput,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue