Commit 0a357651 by Stephen Sanchez

Adding datetime displays to assessment modules

Aside from properly displaying assessment due dates, also hiding the 'due' label when no due date is set for an assessment module
parent 5518d52d
......@@ -11,7 +11,9 @@
<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 }}</span></span>
{% endif %}
</span>
</h2>
......
......@@ -12,7 +12,9 @@
<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 }}</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,36 @@ 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_date_string(self, date):
"""Takes a date string, and formats it to be a user facing date.
Format a date string to be user facing.
"""
return dateutil.parser.parse(
unicode(date)
).replace(tzinfo=pytz.utc).strftime(DATE_FORMAT)
def format_datetime_string(self, datetime):
"""Takes a datetime string, and formats it to be a user facing time.
Format a datetime string to be user facing.
"""
return dateutil.parser.parse(
unicode(datetime)
).replace(tzinfo=pytz.utc).strftime(DATETIME_FORMAT)
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