Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit 0e9e739

Browse files
authored
Merge pull request #3 from ExtensionEngine/mjevtic/NDPD-1222
[NDPD-1222] Submissions should allow score points to have a decimal value
2 parents 2b67d3d + 67667a6 commit 0e9e739

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

submissions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = u'2.0.14'
1+
__version__ = u'2.0.15'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
from decimal import Decimal
6+
import django.core.validators
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('submissions', '0005_remove_django_extensions'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='score',
18+
name='points_earned',
19+
field=models.DecimalField(default=Decimal('0.0'), max_digits=6, decimal_places=2, validators=[django.core.validators.MinValueValidator(Decimal('0.0'))]),
20+
),
21+
migrations.AlterField(
22+
model_name='score',
23+
name='points_possible',
24+
field=models.DecimalField(default=Decimal('0.0'), max_digits=6, decimal_places=2, validators=[django.core.validators.MinValueValidator(Decimal('0.0'))]),
25+
),
26+
]

submissions/models.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
1111
"""
1212
import logging
13+
from decimal import Decimal
1314
from uuid import uuid4
1415

16+
from django.core.validators import MinValueValidator
1517
from django.db import models, DatabaseError
1618
from django.db.models.signals import post_save
1719
from django.dispatch import receiver, Signal
@@ -177,8 +179,18 @@ class Score(models.Model):
177179
"""
178180
student_item = models.ForeignKey(StudentItem)
179181
submission = models.ForeignKey(Submission, null=True)
180-
points_earned = models.PositiveIntegerField(default=0)
181-
points_possible = models.PositiveIntegerField(default=0)
182+
points_earned = models.DecimalField(
183+
decimal_places=2,
184+
default=Decimal('0.0'),
185+
max_digits=6,
186+
validators=[MinValueValidator(Decimal('0.0'))]
187+
)
188+
points_possible = models.DecimalField(
189+
decimal_places=2,
190+
default=Decimal('0.0'),
191+
max_digits=6,
192+
validators=[MinValueValidator(Decimal('0.0'))]
193+
)
182194
created_at = models.DateTimeField(editable=False, default=now, db_index=True)
183195

184196
# Flag to indicate that this score should reset the current "highest" score
@@ -214,9 +226,9 @@ def to_float(self):
214226
float or None
215227
216228
"""
217-
if self.points_possible == 0:
229+
if self.points_possible == Decimal('0.0'):
218230
return None
219-
return float(self.points_earned) / self.points_possible
231+
return float(self.points_earned / self.points_possible)
220232

221233
def __repr__(self):
222234
return repr(dict(
@@ -236,7 +248,7 @@ def is_hidden(self):
236248
bool: Whether the score should be hidden.
237249
238250
"""
239-
return self.points_possible == 0
251+
return self.points_possible == Decimal('0.0')
240252

241253
@classmethod
242254
def create_reset_score(cls, student_item):
@@ -264,7 +276,7 @@ def create_reset_score(cls, student_item):
264276
student_item=student_item,
265277
submission=None,
266278
points_earned=0,
267-
points_possible=0,
279+
points_possible=Decimal('0.0'),
268280
reset=True,
269281
)
270282

0 commit comments

Comments
 (0)