Commit 97655d03 by Diana Huang

Remove the requirement that the problem peer grading module

has to have a certain naming structure
parent 04f6d6d0
...@@ -32,6 +32,7 @@ from .stringify import stringify_children ...@@ -32,6 +32,7 @@ from .stringify import stringify_children
from .x_module import XModule from .x_module import XModule
from .xml_module import XmlDescriptor from .xml_module import XmlDescriptor
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from timeinfo import TimeInfo from timeinfo import TimeInfo
from peer_grading_service import peer_grading_service, GradingServiceError from peer_grading_service import peer_grading_service, GradingServiceError
...@@ -109,10 +110,14 @@ class PeerGradingModule(XModule): ...@@ -109,10 +110,14 @@ class PeerGradingModule(XModule):
self.max_grade = int(self.max_grade) self.max_grade = int(self.max_grade)
def closed(self): def closed(self):
if self.timeinfo.close_date is not None and datetime.utcnow() > self.timeinfo.close_date: return self._closed(self.timeinfo)
def _closed(self, timeinfo):
if timeinfo.close_date is not None and datetime.utcnow() > timeinfo.close_date:
return True return True
return False return False
def _err_response(self, msg): def _err_response(self, msg):
""" """
Return a HttpResponse with a json dump with success=False, and the given error message. Return a HttpResponse with a json dump with success=False, and the given error message.
...@@ -456,6 +461,44 @@ class PeerGradingModule(XModule): ...@@ -456,6 +461,44 @@ class PeerGradingModule(XModule):
error_text = "Could not get problem list" error_text = "Could not get problem list"
success = False success = False
# grab all peer grading module descriptors for this course
peer_grading_modules = modulestore().get_items(['i4x', self.location.org, self.location.course, 'peergrading', None], self.system.course_id)
# construct a dictionary for fast lookups
module_dict = {}
for module in peer_grading_modules:
linked_location = module.metadata.get("link_to_location", None)
if linked_location:
module_dict[linked_location] = module
def _find_corresponding_module_for_location(location):
if location in module_dict:
return module_dict[location]
else:
return None
for problem in problem_list:
problem_location = problem['location']
descriptor = _find_corresponding_module_for_location(problem_location)
if descriptor:
problem['due'] = descriptor.metadata.get('due', None)
grace_period_string = descriptor.metadata.get('graceperiod', None)
try:
problem_timeinfo = TimeInfo(problem['due'], grace_period_string)
except:
log.error("Malformed due date or grace period string for location {0}".format(problem_location))
raise
if self._closed(problem_timeinfo):
problem['closed'] = True
else:
problem['closed'] = False
else:
# if we can't find the due date, assume that it doesn't have one
problem['due'] = None
problem['closed'] = False
ajax_url = self.ajax_url ajax_url = self.ajax_url
html = self.system.render_template('peer_grading/peer_grading.html', { html = self.system.render_template('peer_grading/peer_grading.html', {
'course_id': self.system.course_id, 'course_id': self.system.course_id,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<table class="problem-list"> <table class="problem-list">
<tr> <tr>
<th>Problem Name</th> <th>Problem Name</th>
<th>Due date</th>
<th>Graded</th> <th>Graded</th>
<th>Available</th> <th>Available</th>
<th>Required</th> <th>Required</th>
...@@ -22,7 +23,18 @@ ...@@ -22,7 +23,18 @@
%for problem in problem_list: %for problem in problem_list:
<tr data-graded="${problem['num_graded']}" data-required="${problem['num_required']}"> <tr data-graded="${problem['num_graded']}" data-required="${problem['num_required']}">
<td class="problem-name"> <td class="problem-name">
%if problem['closed']:
${problem['problem_name']}
%else:
<a href="#problem" data-location="${problem['location']}" class="problem-button">${problem['problem_name']}</a> <a href="#problem" data-location="${problem['location']}" class="problem-button">${problem['problem_name']}</a>
%endif
</td>
<td>
% if problem['due']:
${problem['due']}
% else:
No due date
% endif
</td> </td>
<td> <td>
${problem['num_graded']} ${problem['num_graded']}
......
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