From 0128df94a2f12e07f60e15b166dd9a71614b4fb9 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Tue, 14 Aug 2018 10:18:41 +0200
Subject: [PATCH] Added mips and haskell options in SubmissionType Prog. lang

---
 core/models.py   |  4 ++++
 util/importer.py | 28 ++++++++++++++++++++--------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/core/models.py b/core/models.py
index f5e6e2bf..bc33deec 100644
--- a/core/models.py
+++ b/core/models.py
@@ -109,10 +109,14 @@ class SubmissionType(models.Model):
 
     C = 'c'
     JAVA = 'java'
+    MIPS = 'mipsasm'
+    HASKELL = 'haskell'
 
     LANGUAGE_CHOICES = (
         (C, 'C syntax highlighting'),
         (JAVA, 'Java syntax highlighting'),
+        (MIPS, 'Mips syntax highlighting'),
+        (HASKELL, 'Haskell syntax highlighting'),
     )
 
     submission_type_id = models.UUIDField(primary_key=True,
diff --git a/util/importer.py b/util/importer.py
index 736591c6..bbd4c706 100644
--- a/util/importer.py
+++ b/util/importer.py
@@ -163,13 +163,24 @@ def call_loader(func: Callable) -> None:
     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():
 
     print(
         '''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
+       Supported suffixes: .c , .java , .hs , .s (for mips)
     2) A path to a directory where I can find sample solutions named
         <id>-lsg.c
     3) A path to a directory where I can find HTML files with an accurate
@@ -204,17 +215,18 @@ def do_load_submission_types():
             csv_rows = [row for row in csv.reader(tfile)]
 
         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:
-                lang = '.c'
+            if not suffix:
+                suffix = '.c'
             else:
-                lang = lang[0]
+                suffix = suffix[0]
 
-            lang = lang.lower().strip('.')
+            suffix = suffix.lower().strip('.')
+            lang_name = file_suffix_to_lang_name(suffix)
 
             with \
-                open(os.path.join(lsg_dir, tid + '.' + lang),
+                open(os.path.join(lsg_dir, tid + '.' + suffix),
                      encoding='utf-8') as lsg, \
                 open(os.path.join(desc_dir, tid + '.html'),
                      encoding='utf-8') as desc:
@@ -223,7 +235,7 @@ def do_load_submission_types():
                     'description': desc.read(),
                     'solution': lsg.read(),
                     'full_score': int(score),
-                    'programming_language': lang
+                    'programming_language': lang_name
                 }
             _, created = SubmissionType.objects.update_or_create(
                 name=name,
-- 
GitLab