Commit 449ddde1 by Stephen Sanchez

Changing is_open to is_closed. We're negative like that.

parent c2509762
...@@ -418,12 +418,12 @@ class OpenAssessmentBlock( ...@@ -418,12 +418,12 @@ class OpenAssessmentBlock(
template = get_template('openassessmentblock/oa_error.html') template = get_template('openassessmentblock/oa_error.html')
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, step=None): def is_closed(self, step=None):
""" """
Checks if the question is open. Checks if the question is closed.
Determines if the start date has occurred and the end date has not Determines if the start date is in the future or the end date has
passed. Optionally limited to a particular step in the workflow. passed. Optionally limited to a particular step in the workflow.
Kwargs: Kwargs:
step (str): The step in the workflow to check. Options are: step (str): The step in the workflow to check. Options are:
...@@ -433,17 +433,17 @@ class OpenAssessmentBlock( ...@@ -433,17 +433,17 @@ class OpenAssessmentBlock(
"self-assessment": check whether the self-assessment section is open. "self-assessment": check whether the self-assessment section is open.
Returns: Returns:
(tuple): True if the question is open, False if not. If False, (tuple): True if the question is closed, False if not. If True,
specifies if the "start" date or "due" date is the closing specifies if the "start" date or "due" date is the closing
factor. factor.
Examples: Examples:
>>> is_open() >>> is_closed()
True, None False, None
>>> is_open(step="submission") >>> is_closed(step="submission")
False, "due" True, "due"
>>> is_open(step="self-assessment") >>> is_closed(step="self-assessment")
False, "start" True, "start"
""" """
submission_range = (self.start, self.submission_due) submission_range = (self.start, self.submission_due)
...@@ -470,11 +470,11 @@ class OpenAssessmentBlock( ...@@ -470,11 +470,11 @@ class OpenAssessmentBlock(
now = dt.datetime.now().replace(tzinfo=pytz.utc) now = dt.datetime.now().replace(tzinfo=pytz.utc)
if now < open_range[0]: if now < open_range[0]:
return False, "start" return True, "start"
elif now >= open_range[1]: elif now >= open_range[1]:
return False, "due" return True, "due"
else: else:
return True, None return False, None
def is_released(self, step=None): def is_released(self, step=None):
""" """
...@@ -492,8 +492,8 @@ class OpenAssessmentBlock( ...@@ -492,8 +492,8 @@ class OpenAssessmentBlock(
""" """
# By default, assume that we're published, in case the runtime doesn't support publish date. # By default, assume that we're published, in case the runtime doesn't support publish date.
is_published = getattr(self, 'published_date', True) is not None is_published = getattr(self, 'published_date', True) is not None
is_open, reason = self.is_open(step=step) is_closed, reason = self.is_closed(step=step)
return is_published and (is_open or reason == 'due') return is_published and (not is_closed or reason == 'due')
def get_assessment_module(self, mixin_name): def get_assessment_module(self, mixin_name):
""" """
......
...@@ -112,14 +112,13 @@ class PeerAssessmentMixin(object): ...@@ -112,14 +112,13 @@ class PeerAssessmentMixin(object):
path = 'openassessmentblock/peer/oa_peer_unavailable.html' path = 'openassessmentblock/peer/oa_peer_unavailable.html'
finished = False finished = False
problem_open, date = self.is_open(step="peer-assessment") problem_closed, date = self.is_closed(step="peer-assessment")
context_dict = { context_dict = {
"rubric_criteria": self.rubric_criteria, "rubric_criteria": self.rubric_criteria,
"estimated_time": "20 minutes" # TODO: Need to configure this. "estimated_time": "20 minutes" # TODO: Need to configure this.
} }
submissions_open, __ = self.is_open(step="submission") submissions_closed, __ = self.is_closed(step="submission")
over_grading = not submissions_open
workflow = self.get_workflow_info() workflow = self.get_workflow_info()
if workflow is None: if workflow is None:
...@@ -127,7 +126,7 @@ class PeerAssessmentMixin(object): ...@@ -127,7 +126,7 @@ class PeerAssessmentMixin(object):
continue_grading = ( continue_grading = (
data.params.get('continue_grading', False) data.params.get('continue_grading', False)
and workflow["status_details"]["peer"]["complete"] and workflow["status_details"]["peer"]["complete"]
and over_grading and submissions_closed
) )
student_item = self.get_student_item_dict() student_item = self.get_student_item_dict()
...@@ -157,14 +156,15 @@ class PeerAssessmentMixin(object): ...@@ -157,14 +156,15 @@ class PeerAssessmentMixin(object):
if assessment.get('due'): if assessment.get('due'):
context_dict["peer_due"] = self.format_datetime_string(assessment["due"]) context_dict["peer_due"] = self.format_datetime_string(assessment["due"])
if date == 'due' and not problem_open:
if date == "due" and problem_closed:
path = 'openassessmentblock/peer/oa_peer_closed.html' path = 'openassessmentblock/peer/oa_peer_closed.html'
elif date == 'start' and not problem_open: elif date == 'start' and problem_closed:
if assessment.get('start'): if assessment.get('start'):
context_dict["peer_start"] = self.format_datetime_string(assessment["start"]) context_dict["peer_start"] = self.format_datetime_string(assessment["start"])
path = 'openassessmentblock/peer/oa_peer_unavailable.html' path = 'openassessmentblock/peer/oa_peer_unavailable.html'
elif workflow.get("status") == "peer": elif workflow.get("status") == "peer":
peer_sub = self.get_peer_submission(student_item, assessment, over_grading) peer_sub = self.get_peer_submission(student_item, assessment, submissions_closed)
if peer_sub: if peer_sub:
path = 'openassessmentblock/peer/oa_peer_assessment.html' path = 'openassessmentblock/peer/oa_peer_assessment.html'
context_dict["peer_submission"] = peer_sub context_dict["peer_submission"] = peer_sub
...@@ -186,8 +186,9 @@ class PeerAssessmentMixin(object): ...@@ -186,8 +186,9 @@ class PeerAssessmentMixin(object):
self, self,
student_item_dict, student_item_dict,
assessment, assessment,
over_grading=False over_grading
): ):
submissions_closed, __ = self.is_closed(step="submission")
peer_submission = False peer_submission = False
try: try:
peer_submission = peer_api.get_submission_to_assess( peer_submission = peer_api.get_submission_to_assess(
......
...@@ -28,10 +28,10 @@ class SelfAssessmentMixin(object): ...@@ -28,10 +28,10 @@ class SelfAssessmentMixin(object):
assessment_module = self.get_assessment_module('self-assessment') assessment_module = self.get_assessment_module('self-assessment')
path = 'openassessmentblock/self/oa_self_unavailable.html' path = 'openassessmentblock/self/oa_self_unavailable.html'
problem_open, date = self.is_open(step="self-assessment") problem_closed, date = self.is_closed(step="self-assessment")
due_date = assessment_module.get('due') due_date = assessment_module.get('due')
if date == 'start' and not problem_open: if date == 'start' and problem_closed:
context["self_start"] = self.format_datetime_string(assessment_module["start"]) context["self_start"] = self.format_datetime_string(assessment_module["start"])
elif due_date: elif due_date:
context["self_due"] = self.format_datetime_string(assessment_module["due"]) context["self_due"] = self.format_datetime_string(assessment_module["due"])
...@@ -60,7 +60,7 @@ class SelfAssessmentMixin(object): ...@@ -60,7 +60,7 @@ class SelfAssessmentMixin(object):
} }
elif assessment is not None: elif assessment is not None:
path = 'openassessmentblock/self/oa_self_complete.html' path = 'openassessmentblock/self/oa_self_complete.html'
elif date == 'due' and not problem_open: elif date == "due" and problem_closed:
path = 'openassessmentblock/self/oa_self_closed.html' path = 'openassessmentblock/self/oa_self_closed.html'
return self.render_assessment(path, context) return self.render_assessment(path, context)
......
import copy
import dateutil import dateutil
import logging import logging
...@@ -6,7 +5,6 @@ from django.utils.translation import ugettext as _ ...@@ -6,7 +5,6 @@ from django.utils.translation import ugettext as _
from xblock.core import XBlock from xblock.core import XBlock
from submissions import api from submissions import api
from openassessment.assessment import peer_api
from openassessment.workflow import api as workflow_api from openassessment.workflow import api as workflow_api
...@@ -177,7 +175,7 @@ class SubmissionMixin(object): ...@@ -177,7 +175,7 @@ class SubmissionMixin(object):
""" """
workflow = self.get_workflow_info() workflow = self.get_workflow_info()
problem_open, date = self.is_open('submission') problem_closed, date = self.is_closed('submission')
sub_due = None sub_due = None
if self.submission_due is not None: if self.submission_due is not None:
submission_deadline = dateutil.parser.parse(self.submission_due) submission_deadline = dateutil.parser.parse(self.submission_due)
...@@ -189,7 +187,7 @@ class SubmissionMixin(object): ...@@ -189,7 +187,7 @@ class SubmissionMixin(object):
"submission_due": sub_due, "submission_due": sub_due,
} }
if not workflow and not problem_open: if not workflow and problem_closed:
path = 'openassessmentblock/response/oa_response_closed.html' path = 'openassessmentblock/response/oa_response_closed.html'
elif not workflow: elif not workflow:
path = "openassessmentblock/response/oa_response.html" path = "openassessmentblock/response/oa_response.html"
......
...@@ -146,31 +146,31 @@ class TestDates(XBlockHandlerTestCase): ...@@ -146,31 +146,31 @@ class TestDates(XBlockHandlerTestCase):
xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat() xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat()
xblock.due = dt.datetime(2014, 3, 5).replace(tzinfo=pytz.utc).isoformat() xblock.due = dt.datetime(2014, 3, 5).replace(tzinfo=pytz.utc).isoformat()
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 2, 28, 23, 59, 59), dt.datetime(2014, 2, 28, 23, 59, 59),
None, False, "start", None, True, "start",
released=False released=False
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 1, 1, 1, 1), dt.datetime(2014, 3, 1, 1, 1, 1),
None, True, None, None, False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 4, 23, 59, 59), dt.datetime(2014, 3, 4, 23, 59, 59),
None, True, None, None, False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 5, 1, 1, 1), dt.datetime(2014, 3, 5, 1, 1, 1),
None, False, "due", None, True, "due",
released=True released=True
) )
...@@ -180,31 +180,31 @@ class TestDates(XBlockHandlerTestCase): ...@@ -180,31 +180,31 @@ class TestDates(XBlockHandlerTestCase):
xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat() xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat()
xblock.due = None xblock.due = None
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 2, 28, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2014, 2, 28, 23, 59, 59).replace(tzinfo=pytz.utc),
"submission", False, "start", "submission", True, "start",
released=False released=False
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 1, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2014, 3, 1, 1, 1, 1).replace(tzinfo=pytz.utc),
"submission", True, None, "submission", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2014, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc),
"submission", True, None, "submission", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2014, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc),
"submission", False, "due", "submission", True, "due",
released=True released=True
) )
...@@ -214,31 +214,31 @@ class TestDates(XBlockHandlerTestCase): ...@@ -214,31 +214,31 @@ class TestDates(XBlockHandlerTestCase):
xblock.start = None xblock.start = None
xblock.due = None xblock.due = None
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2015, 1, 1, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2015, 1, 1, 23, 59, 59).replace(tzinfo=pytz.utc),
"peer-assessment", False, "start", "peer-assessment", True, "start",
released=False released=False
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2015, 1, 2, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2015, 1, 2, 1, 1, 1).replace(tzinfo=pytz.utc),
"peer-assessment", True, None, "peer-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2015, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2015, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc),
"peer-assessment", True, None, "peer-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2015, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2015, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc),
"peer-assessment", False, "due", "peer-assessment", True, "due",
released=True released=True
) )
...@@ -248,31 +248,31 @@ class TestDates(XBlockHandlerTestCase): ...@@ -248,31 +248,31 @@ class TestDates(XBlockHandlerTestCase):
xblock.start = None xblock.start = None
xblock.due = None xblock.due = None
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 1, 1, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2016, 1, 1, 23, 59, 59).replace(tzinfo=pytz.utc),
"self-assessment", False, "start", "self-assessment", True, "start",
released=False released=False
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 1, 2, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2016, 1, 2, 1, 1, 1).replace(tzinfo=pytz.utc),
"self-assessment", True, None, "self-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc),
"self-assessment", True, None, "self-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2016, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc),
"self-assessment", False, "due", "self-assessment", True, "due",
released=True released=True
) )
...@@ -284,31 +284,31 @@ class TestDates(XBlockHandlerTestCase): ...@@ -284,31 +284,31 @@ class TestDates(XBlockHandlerTestCase):
xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat() xblock.start = dt.datetime(2014, 3, 1).replace(tzinfo=pytz.utc).isoformat()
xblock.due = None xblock.due = None
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 2, 28, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2014, 2, 28, 23, 59, 59).replace(tzinfo=pytz.utc),
"peer-assessment", False, "start", "peer-assessment", True, "start",
released=False released=False
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2014, 3, 1, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2014, 3, 1, 1, 1, 1).replace(tzinfo=pytz.utc),
"peer-assessment", True, None, "peer-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 5, 1, 23, 59, 59).replace(tzinfo=pytz.utc), dt.datetime(2016, 5, 1, 23, 59, 59).replace(tzinfo=pytz.utc),
"peer-assessment", True, None, "peer-assessment", False, None,
released=True released=True
) )
self.assert_is_open( self.assert_is_closed(
xblock, xblock,
dt.datetime(2016, 5, 2, 1, 1, 1).replace(tzinfo=pytz.utc), dt.datetime(2016, 5, 2, 1, 1, 1).replace(tzinfo=pytz.utc),
"peer-assessment", False, "due", "peer-assessment", True, "due",
released=True released=True
) )
...@@ -333,7 +333,7 @@ class TestDates(XBlockHandlerTestCase): ...@@ -333,7 +333,7 @@ class TestDates(XBlockHandlerTestCase):
# If the runtime doesn't provide a published_date field, assume we've been published # If the runtime doesn't provide a published_date field, assume we've been published
self.assertTrue(xblock.is_released()) self.assertTrue(xblock.is_released())
def assert_is_open(self, xblock, now, step, expected_is_open, expected_reason, released=None): def assert_is_closed(self, xblock, now, step, expected_is_closed, expected_reason, released=None):
""" """
Assert whether the XBlock step is open/closed. Assert whether the XBlock step is open/closed.
...@@ -358,8 +358,8 @@ class TestDates(XBlockHandlerTestCase): ...@@ -358,8 +358,8 @@ class TestDates(XBlockHandlerTestCase):
self.addCleanup(datetime_patcher.stop) self.addCleanup(datetime_patcher.stop)
mocked_datetime.datetime.now.return_value = now mocked_datetime.datetime.now.return_value = now
is_open, reason = xblock.is_open(step=step) is_closed, reason = xblock.is_closed(step=step)
self.assertEqual(is_open, expected_is_open) self.assertEqual(is_closed, expected_is_closed)
self.assertEqual(reason, expected_reason) self.assertEqual(reason, expected_reason)
if released is not None: if released is not None:
......
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