Skip to content
Snippets Groups Projects
Commit 0128df94 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Added mips and haskell options in SubmissionType Prog. lang

parent b95340f9
No related branches found
No related tags found
1 merge request!118Explore swagger
...@@ -109,10 +109,14 @@ class SubmissionType(models.Model): ...@@ -109,10 +109,14 @@ class SubmissionType(models.Model):
C = 'c' C = 'c'
JAVA = 'java' JAVA = 'java'
MIPS = 'mipsasm'
HASKELL = 'haskell'
LANGUAGE_CHOICES = ( LANGUAGE_CHOICES = (
(C, 'C syntax highlighting'), (C, 'C syntax highlighting'),
(JAVA, 'Java syntax highlighting'), (JAVA, 'Java syntax highlighting'),
(MIPS, 'Mips syntax highlighting'),
(HASKELL, 'Haskell syntax highlighting'),
) )
submission_type_id = models.UUIDField(primary_key=True, submission_type_id = models.UUIDField(primary_key=True,
......
...@@ -163,13 +163,24 @@ def call_loader(func: Callable) -> None: ...@@ -163,13 +163,24 @@ def call_loader(func: Callable) -> None:
info(f'{func.__name__} is done.') info(f'{func.__name__} is done.')
def file_suffix_to_lang_name(suffix: str) -> str:
suffix2name = {
'hs': 'haskell',
's': 'mipsasm'
}
if suffix not in suffix2name:
return suffix
return suffix2name[suffix]
def do_load_submission_types(): def do_load_submission_types():
print( print(
'''For the following import you need three files: '''For the following import you need three files:
1) A .csv file where the columns are: id, name, score, (suffix). No 1) A .csv file where the columns are: id, name, score, (file suffix). No
suffix defaults to .c suffix defaults to .c
Supported suffixes: .c , .java , .hs , .s (for mips)
2) A path to a directory where I can find sample solutions named 2) A path to a directory where I can find sample solutions named
<id>-lsg.c <id>-lsg.c
3) A path to a directory where I can find HTML files with an accurate 3) A path to a directory where I can find HTML files with an accurate
...@@ -204,17 +215,18 @@ def do_load_submission_types(): ...@@ -204,17 +215,18 @@ def do_load_submission_types():
csv_rows = [row for row in csv.reader(tfile)] csv_rows = [row for row in csv.reader(tfile)]
for row in csv_rows: for row in csv_rows:
tid, name, score, *lang = (col.strip() for col in row) tid, name, score, *suffix = (col.strip() for col in row)
if not lang: if not suffix:
lang = '.c' suffix = '.c'
else: else:
lang = lang[0] suffix = suffix[0]
lang = lang.lower().strip('.') suffix = suffix.lower().strip('.')
lang_name = file_suffix_to_lang_name(suffix)
with \ with \
open(os.path.join(lsg_dir, tid + '.' + lang), open(os.path.join(lsg_dir, tid + '.' + suffix),
encoding='utf-8') as lsg, \ encoding='utf-8') as lsg, \
open(os.path.join(desc_dir, tid + '.html'), open(os.path.join(desc_dir, tid + '.html'),
encoding='utf-8') as desc: encoding='utf-8') as desc:
...@@ -223,7 +235,7 @@ def do_load_submission_types(): ...@@ -223,7 +235,7 @@ def do_load_submission_types():
'description': desc.read(), 'description': desc.read(),
'solution': lsg.read(), 'solution': lsg.read(),
'full_score': int(score), 'full_score': int(score),
'programming_language': lang 'programming_language': lang_name
} }
_, created = SubmissionType.objects.update_or_create( _, created = SubmissionType.objects.update_or_create(
name=name, name=name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment