Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion submissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = u'2.0.14'
__version__ = u'2.0.15'
26 changes: 26 additions & 0 deletions submissions/migrations/0006_auto_20180510_0732.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
from decimal import Decimal
import django.core.validators


class Migration(migrations.Migration):

dependencies = [
('submissions', '0005_remove_django_extensions'),
]

operations = [
migrations.AlterField(
model_name='score',
name='points_earned',
field=models.DecimalField(default=Decimal('0.0'), max_digits=6, decimal_places=2, validators=[django.core.validators.MinValueValidator(Decimal('0.0'))]),
),
migrations.AlterField(
model_name='score',
name='points_possible',
field=models.DecimalField(default=Decimal('0.0'), max_digits=6, decimal_places=2, validators=[django.core.validators.MinValueValidator(Decimal('0.0'))]),
),
]
24 changes: 18 additions & 6 deletions submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

"""
import logging
from decimal import Decimal
from uuid import uuid4

from django.core.validators import MinValueValidator
from django.db import models, DatabaseError
from django.db.models.signals import post_save
from django.dispatch import receiver, Signal
Expand Down Expand Up @@ -177,8 +179,18 @@ class Score(models.Model):
"""
student_item = models.ForeignKey(StudentItem)
submission = models.ForeignKey(Submission, null=True)
points_earned = models.PositiveIntegerField(default=0)
points_possible = models.PositiveIntegerField(default=0)
points_earned = models.DecimalField(
decimal_places=2,
default=Decimal('0.0'),
max_digits=6,
validators=[MinValueValidator(Decimal('0.0'))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do users see an error message when one of these fails, or a 500 error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess consumers handle those errors, SGA does on the front end.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't realize this doesn't have views/controllers.

)
points_possible = models.DecimalField(
decimal_places=2,
default=Decimal('0.0'),
max_digits=6,
validators=[MinValueValidator(Decimal('0.0'))]
)
created_at = models.DateTimeField(editable=False, default=now, db_index=True)

# Flag to indicate that this score should reset the current "highest" score
Expand Down Expand Up @@ -214,9 +226,9 @@ def to_float(self):
float or None

"""
if self.points_possible == 0:
if self.points_possible == Decimal('0.0'):
return None
return float(self.points_earned) / self.points_possible
return float(self.points_earned / self.points_possible)

def __repr__(self):
return repr(dict(
Expand All @@ -236,7 +248,7 @@ def is_hidden(self):
bool: Whether the score should be hidden.

"""
return self.points_possible == 0
return self.points_possible == Decimal('0.0')

@classmethod
def create_reset_score(cls, student_item):
Expand Down Expand Up @@ -264,7 +276,7 @@ def create_reset_score(cls, student_item):
student_item=student_item,
submission=None,
points_earned=0,
points_possible=0,
points_possible=Decimal('0.0'),
reset=True,
)

Expand Down