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

Resolve "Add the Option to give half points"

parent e9dbd6b4
Branches
Tags
No related merge requests found
Pipeline #93753 passed
# Generated by Django 2.1.4 on 2019-03-08 14:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0012_auto_20190306_1611'),
]
operations = [
migrations.AlterField(
model_name='feedback',
name='score',
field=models.DecimalField(decimal_places=2, default=0, max_digits=5),
),
]
......@@ -447,7 +447,7 @@ class Feedback(models.Model):
origin : IntegerField
Of whom was this feedback originally created. She below for the choices
"""
score = models.PositiveIntegerField(default=0)
score = models.DecimalField(max_digits=5, decimal_places=2, default=0)
created = models.DateTimeField(auto_now_add=True)
is_final = models.BooleanField(default=False)
......@@ -456,6 +456,9 @@ class Feedback(models.Model):
on_delete=models.CASCADE,
related_name='feedback')
# the denominators that are allowed for the decimal score interpreted as a fraction
ALLOWED_DENOMINATORS = [1, 2]
# how was this feedback created
(
WAS_EMPTY,
......
......@@ -163,6 +163,12 @@ class FeedbackSerializer(DynamicFieldsModelSerializer):
raise serializers.ValidationError(
f'Score has to be in range [0..{submission.type.full_score}].')
if score.as_integer_ratio()[1] not in Feedback.ALLOWED_DENOMINATORS:
raise serializers.ValidationError(
f'For fractional scores, the denominator must be one of '
f'{Feedback.ALLOWED_DENOMINATORS}'
)
has_full_score = score == submission.type.full_score
has_feedback_lines = ('feedback_lines' in data and
len(data['feedback_lines']) > 0 or
......
......@@ -115,6 +115,7 @@ class FeedbackCreateTestCase(APITestCase):
text=text)
def setUp(self):
self.sub.refresh_from_db()
self.client.force_authenticate(user=self.tutor)
self.subscription = models.SubmissionSubscription.objects.create(
owner=self.tutor,
......@@ -179,6 +180,32 @@ class FeedbackCreateTestCase(APITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Feedback.objects.count(), 0)
def test_cannot_create_feedback_with_score_with_invalid_fractional_denominator(self):
data = {
'score': 1.500000001,
'is_final': False,
'of_submission': self.assignment.submission.pk
}
self.assertEqual(Feedback.objects.count(), 0)
response = self.client.post(self.url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Feedback.objects.count(), 0)
def test_can_create_feedback_with_half_points(self):
data = {
'score': 0.5,
'is_final': False,
'of_submission': self.assignment.submission.pk,
'feedback_lines': {
'2': {
'text': 'Why you no learn how to code, man?'
}
}
}
self.client.post(self.url, data, format='json')
object_score = self.sub.feedback.score
self.assertEqual(object_score, 0.5)
def test_check_score_is_set_accordingly(self):
data = {
'score': 5,
......@@ -200,7 +227,7 @@ class FeedbackCreateTestCase(APITestCase):
'is_final': False,
'of_submission': self.assignment.submission.pk,
'feedback_lines': {
'4': {
'3': {
'text': 'Nice meth!'
}
}
......
......@@ -12,10 +12,6 @@
<span>Skip this submission</span>
</v-tooltip>
<v-spacer />
<v-alert class="score-alert ma-3"
color="error"
icon="warning"
:value="scoreError">{{ scoreError }}</v-alert>
</v-flex>
<v-flex>
<v-layout wrap class="score-submit-container">
......@@ -24,6 +20,7 @@
<input class="score-text-field"
id="score-input"
type="number"
step="0.5"
v-model="score"
@input="validateScore"
@change="validateScore" />
......@@ -71,6 +68,12 @@
</v-flex>
</v-layout>
</v-flex>
<v-flex v-if="scoreError">
<v-alert class="score-alert ma-3"
color="error"
icon="warning"
:value="scoreError">{{ scoreError }}</v-alert>
</v-flex>
</v-layout>
</v-container>
</template>
......
......@@ -150,6 +150,7 @@ REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'djangorestframework_camel_case.parser.CamelCaseJSONParser',
),
'COERCE_DECIMAL_TO_STRING': False,
}
JSON_CAMEL_CASE = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment