Commit 764ae02e by Stephen Sanchez

Changing the start due date logic to be its own function

parent a70972d6
...@@ -245,7 +245,7 @@ def get_assessment_median_scores(submission_id, must_be_graded_by): ...@@ -245,7 +245,7 @@ def get_assessment_median_scores(submission_id, must_be_graded_by):
# found in an assessment. # found in an assessment.
try: try:
submission = Submission.objects.get(uuid=submission_id) submission = Submission.objects.get(uuid=submission_id)
scores = Assessment.get_assessment_scores_by_criterion(submission, must_be_graded_by) scores = Assessment.scores_by_criterion(submission, must_be_graded_by)
return Assessment.get_median_score_dict(scores) return Assessment.get_median_score_dict(scores)
except DatabaseError: except DatabaseError:
error_message = ( error_message = (
......
...@@ -273,7 +273,7 @@ class Assessment(models.Model): ...@@ -273,7 +273,7 @@ class Assessment(models.Model):
return median_score return median_score
@classmethod @classmethod
def get_assessment_scores_by_criterion(cls, submission, must_be_graded_by): def scores_by_criterion(cls, submission, must_be_graded_by):
"""Create a dictionary of lists for scores associated with criterion """Create a dictionary of lists for scores associated with criterion
Create a key value in a dict with a list of values, for every criterion Create a key value in a dict with a list of values, for every criterion
...@@ -290,7 +290,7 @@ class Assessment(models.Model): ...@@ -290,7 +290,7 @@ class Assessment(models.Model):
this score analysis. this score analysis.
Examples: Examples:
>>> Attribute.get_assessment_scores_by_criterion(submission, 3) >>> Assessment.scores_by_criterion(submission, 3)
{ {
"foo": [1, 2, 3], "foo": [1, 2, 3],
"bar": [6, 7, 8] "bar": [6, 7, 8]
......
...@@ -395,3 +395,30 @@ class OpenAssessmentBlock(XBlock, SubmissionMixin, PeerAssessmentMixin, SelfAsse ...@@ -395,3 +395,30 @@ class OpenAssessmentBlock(XBlock, SubmissionMixin, PeerAssessmentMixin, SelfAsse
template = get_template(path) template = get_template(path)
context = Context(context_dict) context = Context(context_dict)
return Response(template.render(context), content_type='application/html', charset='UTF-8') return Response(template.render(context), content_type='application/html', charset='UTF-8')
def is_open(self):
"""Checks if the question is open.
Determines if the start date has occurred and the end date has not
passed.
Returns:
(tuple): True if the question is open, False if not. If False,
specifies if the "start" date or "due" date is the closing
factor.
Examples:
>>> is_open()
False, "due"
"""
# Is the question closed?
if self.start_datetime:
start = datetime.datetime.strptime(self.start_datetime, TIME_PARSE_FORMAT)
if start > datetime.datetime.utcnow():
return False, "start"
if self.due_datetime:
due = datetime.datetime.strptime(self.due_datetime, TIME_PARSE_FORMAT)
if due < datetime.datetime.utcnow():
return False, "due"
return True, None
...@@ -136,14 +136,12 @@ class SubmissionMixin(object): ...@@ -136,14 +136,12 @@ class SubmissionMixin(object):
student_item = self.get_student_item_dict() student_item = self.get_student_item_dict()
# Has the student submitted? # Has the student submitted?
student_submission = self._get_user_submission(student_item) student_submission = self._get_user_submission(student_item)
# Is the question closed?
due = datetime.datetime.strptime(self.due_datetime, "%Y-%m-%dT%H:%M:%S")
# Has it been graded yet? # Has it been graded yet?
student_score = self._get_submission_score(student_item) student_score = self._get_submission_score(student_item)
step_status = "Graded" if student_score else "Submitted" step_status = "Graded" if student_score else "Submitted"
step_status = step_status if student_submission else "Incomplete" step_status = step_status if student_submission else "Incomplete"
assessment_ui_model = self.get_assessment_module('peer-assessment') assessment_ui_model = self.get_assessment_module('peer-assessment')
problem_open, date = self.is_open()
context = { context = {
"student_submission": student_submission, "student_submission": student_submission,
"student_score": student_score, "student_score": student_score,
...@@ -166,7 +164,7 @@ class SubmissionMixin(object): ...@@ -166,7 +164,7 @@ class SubmissionMixin(object):
path = 'openassessmentblock/oa_response_graded.html' path = 'openassessmentblock/oa_response_graded.html'
elif student_submission: elif student_submission:
path = 'openassessmentblock/oa_response_submitted.html' path = 'openassessmentblock/oa_response_submitted.html'
elif due < datetime.datetime.now() and not student_submission: elif not problem_open and date == "due" and not student_submission:
path = 'openassessmentblock/oa_response_closed.html' path = 'openassessmentblock/oa_response_closed.html'
return self.render_assessment(path, context_dict=context) return self.render_assessment(path, context_dict=context)
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
Tests the Open Assessment XBlock functionality. Tests the Open Assessment XBlock functionality.
""" """
import json import json
import datetime
from django.test import TestCase from django.test import TestCase
from mock import patch from mock import patch
from workbench.runtime import WorkbenchRuntime from workbench.runtime import WorkbenchRuntime
import webob import webob
from openassessment.xblock.openassessmentblock import TIME_PARSE_FORMAT
from openassessment.xblock.submission_mixin import SubmissionMixin from openassessment.xblock.submission_mixin import SubmissionMixin
from submissions import api as sub_api from submissions import api as sub_api
...@@ -144,5 +146,28 @@ class TestOpenAssessment(TestCase): ...@@ -144,5 +146,28 @@ class TestOpenAssessment(TestCase):
self.assertIsNotNone(submission_response) self.assertIsNotNone(submission_response)
self.assertTrue(submission_response.body.find("openassessment__response")) self.assertTrue(submission_response.body.find("openassessment__response"))
def test_start_end_date_checks(self):
"""
Check if the start and end date checks work appropriately.
"""
now = datetime.datetime.utcnow()
past = now - datetime.timedelta(minutes = 10)
future = now + datetime.timedelta(minutes = 10)
way_future = now + datetime.timedelta(minutes = 20)
self.assessment.start_datetime = past.strftime(TIME_PARSE_FORMAT)
self.assessment.due_datetime = past.strftime(TIME_PARSE_FORMAT)
problem_open, reason = self.assessment.is_open()
self.assertFalse(problem_open)
self.assertEqual("due", reason)
self.assessment.start_datetime = past.strftime(TIME_PARSE_FORMAT)
self.assessment.due_datetime = future.strftime(TIME_PARSE_FORMAT)
problem_open, reason = self.assessment.is_open()
self.assertTrue(problem_open)
self.assertEqual(None, reason)
self.assessment.start_datetime = future.strftime(TIME_PARSE_FORMAT)
self.assessment.due_datetime = way_future.strftime(TIME_PARSE_FORMAT)
problem_open, reason = self.assessment.is_open()
self.assertFalse(problem_open)
self.assertEqual("start", reason)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment