From 8b1745ea6ac2747342914a36e7acf95a896ced8c Mon Sep 17 00:00:00 2001
From: janmax <mail-github@jmx.io>
Date: Thu, 30 Mar 2017 19:34:46 +0200
Subject: [PATCH] correctly display compiler error, feedback got an origin

---
 core/forms.py                              |  6 +---
 core/migrations/0003_auto_20170330_1709.py | 25 +++++++++++++++
 core/models.py                             | 18 +++++++++++
 core/static/lib/css/custom.css             | 11 +++++--
 core/templates/core/feedback_form.html     | 36 ++++++++++++++++------
 populatedb.py                              |  1 +
 6 files changed, 81 insertions(+), 16 deletions(-)
 create mode 100644 core/migrations/0003_auto_20170330_1709.py

diff --git a/core/forms.py b/core/forms.py
index 3528f937..f7d46831 100644
--- a/core/forms.py
+++ b/core/forms.py
@@ -42,8 +42,4 @@ class FeedbackForm(ModelForm):
     class Meta:
         model = Feedback
         auto_id = False
-        fields = ('text', 'score', 'of_submission', 'of_tutor')
-        widgets = {
-            'of_submission': HiddenInput,
-            'of_tutor': HiddenInput,
-        }
+        fields = ('text', 'score')
diff --git a/core/migrations/0003_auto_20170330_1709.py b/core/migrations/0003_auto_20170330_1709.py
new file mode 100644
index 00000000..2f6ed701
--- /dev/null
+++ b/core/migrations/0003_auto_20170330_1709.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.6 on 2017-03-30 17:09
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0002_auto_20170323_0026'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='feedback',
+            name='origin',
+            field=models.CharField(choices=[('E', 'was empty'), ('UT', 'passed unittests'), ('CF', 'did not compile'), ('M', 'created by a human. yak!')], default='M', max_length=2),
+        ),
+        migrations.AlterField(
+            model_name='submission',
+            name='text',
+            field=models.TextField(blank=True),
+        ),
+    ]
diff --git a/core/models.py b/core/models.py
index 41673e02..276399c3 100644
--- a/core/models.py
+++ b/core/models.py
@@ -113,6 +113,7 @@ class Submission(models.Model):
 
         submission = ready[0]
         feedback = Feedback()
+        feedback.origin = Feedback.MANUAL
         feedback.of_tutor = tutor
         feedback.of_submission = submission
         feedback.save()
@@ -141,6 +142,23 @@ class Feedback(models.Model):
         blank=True, null=True
     )
 
+    # adding an origin
+    WAS_EMPTY = 'E'
+    PASSED_UNIT_TESTS = 'UT'
+    DID_NOT_COMPILE = 'CF'
+    MANUAL = 'M'
+    ORIGIN = (
+        (WAS_EMPTY, 'was empty'),
+        (PASSED_UNIT_TESTS, 'passed unittests'),
+        (DID_NOT_COMPILE, 'did not compile'),
+        (MANUAL, 'created by a human. yak!'),
+    )
+    origin = models.CharField(
+        max_length=2,
+        choices=ORIGIN,
+        default=MANUAL,
+    )
+
     class Meta:
         verbose_name = "Feedback"
         verbose_name_plural = "Feedback Set"
diff --git a/core/static/lib/css/custom.css b/core/static/lib/css/custom.css
index 5ef326e0..76c2162c 100644
--- a/core/static/lib/css/custom.css
+++ b/core/static/lib/css/custom.css
@@ -12,16 +12,23 @@ pre {
   padding: 0;
 }
 
-.editor-code {
+.editor {
     position: relative;
     top: 0;
     right: 0;
     bottom: 0;
     left: 0;
-    height: 500px;
     width: auto;
 }
 
+.editor-code {
+    height: 500px;
+}
+
+.editor-pre {
+    height: 200px;
+}
+
 .nopadding-right {
    padding-right: 0 !important;
 }
diff --git a/core/templates/core/feedback_form.html b/core/templates/core/feedback_form.html
index e11ec442..628fe5e8 100644
--- a/core/templates/core/feedback_form.html
+++ b/core/templates/core/feedback_form.html
@@ -13,11 +13,22 @@
     <div class="card mb-2">
       <h4 class="card-header">{{feedback.of_submission.type.name}}</h4>
       <div class="card-block">
-        <div id="student_text" class="editor-code">{{feedback.of_submission.text}}</div>
+        <div id="student_text" class="editor editor-code">{{feedback.of_submission.text}}</div>
+      </div>
+    </div>
+
+    {# Custom feedback seems too complicated #}
+    <div class="card my-1">
+      <a data-toggle="collapse" href="#collapse4">
+        <h5 class="card-header">Custom Feedback</h5>
+      </a>
+      <div id="collapse4" class="collapse show" role="tabpanel">
+        <div class="card-block m-2">
+          <div id="pre_corrections" class="editor editor-pre">{{feedback.of_submission.pre_corrections}}</div>
+        </div>
       </div>
     </div>
 
-    {% include "core/feedback_card.html" with unique="4" header="Custom Feedback" content=feedback.of_submission.pre_corrections expanded="show" %}
     {% include "core/feedback_card.html" with unique="1" header="Description" content=feedback.of_submission.type.task_description expanded="hide" %}
     {% include "core/feedback_card.html" with unique="2" header="Solution" content=feedback.of_submission.type.possible_solution expanded="hide" %}
     {% include "core/feedback_card.html" with unique="3" header="Correction Guideline" content=feedback.of_submission.type.correction_guideline expanded="hide" %}
@@ -32,7 +43,7 @@
     <div class="card">
       <h4 class="card-header">Please provide your feedback</h4>
       <div class="card-block">
-        <div class="editor-code" id="tutor_text" autofocus>{{feedback.text}}</div>
+        <div class="editor editor-code" id="tutor_text" autofocus>{{feedback.text}}</div>
       </div>
     </div>
     <form action="{% url 'FeedbackEdit' feedback.slug %}" method="post" id="form1">
@@ -66,12 +77,12 @@
         {% endfor %}
       </div>
     </form>
-      {# This is where all the messages pop up #}
-      {% include "core/message_box.html" %}
+    {# This is where all the messages pop up #}
+    {% include "core/message_box.html" %}
   </div>
 </div>
 
-  </div>
+</div>
 </div>
 
 {% endblock %}
@@ -93,8 +104,18 @@
     })
   });
 
+  // we need this one for the student readonly
+  var editor_pre = ace.edit("pre_corrections");
+  editor_pre.setOptions({
+    readOnly: true,
+    showGutter: false,
+  })
+
   // we need this one for the student readonly
   var editor_student = ace.edit("student_text");
+  editor_student.setOptions({
+    readOnly: true,
+  })
 
   // we need this one for the tutor
   var editor_tutor = ace.edit("tutor_text");
@@ -104,9 +125,6 @@
   editor_tutor.getSession().on("change", function () {
     textarea.val(editor_tutor.getSession().getValue());
   });
-  editor_student.setOptions({
-    readOnly: true,
-  })
   {% if feedback.final %}
   editor_tutor.setOptions({
     readOnly: true,
diff --git a/populatedb.py b/populatedb.py
index 45421e96..6faf2e6a 100644
--- a/populatedb.py
+++ b/populatedb.py
@@ -58,6 +58,7 @@ def add_empty_feedback(submission):
     feedback.text = "--- You have not submitted any code for this task ---"
     feedback.final = True
     feedback.empty = False
+    feedback.origin = Feedback.WAS_EMPTY
     feedback.of_submission = submission
     feedback.of_tutor = auto_correct
     feedback.save()
-- 
GitLab