Commit 0b1d01ae by Stephen Sanchez

Merge pull request #188 from edx/sanchez/TIM-326-Due-Dates

Adding datetime displays to assessment modules
parents 694a0a7b 5db4f40b
......@@ -11,7 +11,14 @@
<span class="step__counter"></span>
<span class="wrapper--copy">
<span class="step__label">Assess Peers</span>
<span class="step__deadline">due <span class="date">{{ formatted_due_datetime }}</span></span>
{% if peer_due %}
<span class="step__deadline">due
<span class="date">
{{ peer_due }}
(in {{ peer_due|timeuntil }})
</span>
</span>
{% endif %}
</span>
</h2>
......
......@@ -12,7 +12,14 @@
<span class="step__counter"></span>
<span class="wrapper--copy">
<span class="step__label">Assess Yourself</span>
<span class="step__deadline">due <span class="date">{{ formatted_due_datetime }}</span></span>
{% if self_due %}
<span class="step__deadline">due
<span class="date">
{{ self_due }}
(in {{ self_due|timeuntil }})
</span>
</span>
{% endif %}
</span>
</h2>
......
......@@ -2,6 +2,7 @@
import datetime as dt
import logging
import dateutil
import pkg_resources
import pytz
......@@ -155,6 +156,9 @@ DEFAULT_ASSESSMENT_MODULES = [
DEFAULT_SELF_ASSESSMENT,
]
DATE_FORMAT = "%A, %B %d, %Y"
DATETIME_FORMAT = "%A, %B %d, %Y %X"
def load(path):
"""Handy helper for getting resources from our kit."""
......@@ -366,16 +370,34 @@ class OpenAssessmentBlock(
context_dict = {}
if self.start:
context_dict["formatted_start_date"] = self.start.strftime("%A, %B %d, %Y")
context_dict["formatted_start_datetime"] = self.start.strftime("%A, %B %d, %Y %X")
context_dict["formatted_start_date"] = self.start.strftime(DATE_FORMAT)
context_dict["formatted_start_datetime"] = self.start.strftime(DATETIME_FORMAT)
if self.due:
context_dict["formatted_due_date"] = self.due.strftime("%A, %B %d, %Y")
context_dict["formatted_due_datetime"] = self.due.strftime("%A, %B %d, %Y %X")
context_dict["formatted_due_date"] = self.due.strftime(DATE_FORMAT)
context_dict["formatted_due_datetime"] = self.due.strftime(DATETIME_FORMAT)
template = get_template(path)
context = Context(context_dict)
return Response(template.render(context), content_type='application/html', charset='UTF-8')
def format_datetime_string(self, datetime_str):
"""Takes a datetime string, and formats it to be a user facing time.
Format a datetime string to be user facing. Datetimes are stored as
strings in the XBlock configuration for an assessment module. This
function is used to get back the Datetime object for rendering the start
and due dates on the front end.
Args:
datetime_str (str): A ISO formatted Datetime String, to be converted
to a datetime object with UTC timezone.
Returns:
datetime with UTC timezone from the given string.
"""
return dateutil.parser.parse(unicode(datetime_str)).replace(tzinfo=pytz.utc)
def add_xml_to_node(self, node):
"""
Serialize the XBlock to XML for exporting.
......
......@@ -149,6 +149,9 @@ class PeerAssessmentMixin(object):
context_dict["submit_button_text"] = (
"Submit your assessment & move to response #{}"
).format(count + 2)
if assessment.get('due'):
context_dict["peer_due"] = self.format_datetime_string(assessment["due"])
if date == "due" and not problem_open:
path = 'openassessmentblock/peer/oa_peer_closed.html'
......
......@@ -24,11 +24,17 @@ class SelfAssessmentMixin(object):
@XBlock.handler
def render_self_assessment(self, data, suffix=''):
context = {}
assessment_module = self.get_assessment_module('self-assessment')
if assessment_module and assessment_module.get('due'):
context["self_due"] = self.format_datetime_string(assessment_module["due"])
path = 'openassessmentblock/self/oa_self_unavailable.html'
problem_open, date = self.is_open(step="self")
workflow = self.get_workflow_info()
if not workflow:
return self.render_assessment(path, context)
try:
submission = submission_api.get_submission(self.submission_uuid)
assessment = self_api.get_assessment(
......
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