Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions common/lib/xmodule/xmodule/peer_grading_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,28 @@ class PeerGradingModule(PeerGradingFields, XModule):
def __init__(self, *args, **kwargs):
super(PeerGradingModule, self).__init__(*args, **kwargs)

#We need to set the location here so the child modules can use it
# Copy this to a new variable so that we can edit it if needed.
# We need to edit it if the linked module cannot be found, so
# we can revert to panel model.
self.use_for_single_location_local = self.use_for_single_location

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the names here clearly indicate which value one should use. Better names would be "request_use_for_single_location" and "use_for_single_location". Going with this would mean that a bunch of the places in this file that switched to local would not have to switch, but it would require changing the name of the current field, and I'm guessing that's unacceptable. So I would prefer that use_for_single_location_local was renamed to something like "really_use_for_single_location".


# We need to set the location here so the child modules can use it.
self.runtime.set('location', self.location)
if (self.runtime.open_ended_grading_interface):
self.peer_gs = PeerGradingService(self.system.open_ended_grading_interface, self.system)
else:
self.peer_gs = MockPeerGradingService()

if self.use_for_single_location:
try:
linked_descriptors = self.descriptor.get_required_module_descriptors()
if len(linked_descriptors) == 0:
error_msg = "Peer grading module {0} is trying to use single problem mode without "
"a location specified.".format(self.location)
log.error(error_msg)
raise InvalidLinkLocation(error_msg)
if self.use_for_single_location_local:
linked_descriptors = self.descriptor.get_required_module_descriptors()
if len(linked_descriptors) == 0:
error_msg = "Peer grading module {0} is trying to use single problem mode without "
"a location specified.".format(self.location)
log.error(error_msg)
# Change module over to panel mode from single problem mode.
self.use_for_single_location_local = False
else:
self.linked_problem = self.system.get_module(linked_descriptors[0])
except ItemNotFoundError:
log.error("Linked location {0} for peer grading module {1} does not exist".format(
self.link_to_location, self.location))
raise
except NoPathToItem:
log.error("Linked location {0} for peer grading module {1} cannot be linked to.".format(
self.link_to_location, self.location))
raise

try:
self.timeinfo = TimeInfo(self.due, self.graceperiod)
Expand Down Expand Up @@ -175,7 +173,7 @@ def get_html(self):
"""
if self.closed():
return self.peer_grading_closed()
if not self.use_for_single_location:
if not self.use_for_single_location_local:
return self.peer_grading()
else:
return self.peer_grading_problem({'location': self.link_to_location})['html']
Expand Down Expand Up @@ -236,7 +234,7 @@ def get_score(self):
'score': score,
'total': max_score,
}
if not self.use_for_single_location or not self.graded:
if not self.use_for_single_location_local or not self.graded:
return score_dict

try:
Expand Down Expand Up @@ -270,7 +268,7 @@ def max_score(self):
randomization, and 5/7 on another
'''
max_grade = None
if self.use_for_single_location and self.graded:
if self.use_for_single_location_local and self.graded:
max_grade = self.weight
return max_grade

Expand Down Expand Up @@ -492,7 +490,7 @@ def peer_grading_closed(self):
Show the Peer grading closed template
'''
html = self.system.render_template('peer_grading/peer_grading_closed.html', {
'use_for_single_location': self.use_for_single_location
'use_for_single_location': self.use_for_single_location_local
})
return html

Expand Down Expand Up @@ -578,7 +576,7 @@ def peer_grading(self, _data=None):
'error_text': error_text,
# Checked above
'staff_access': False,
'use_single_location': self.use_for_single_location,
'use_single_location': self.use_for_single_location_local,
})

return html
Expand All @@ -588,7 +586,7 @@ def peer_grading_problem(self, data=None):
Show individual problem interface
'''
if data is None or data.get('location') is None:
if not self.use_for_single_location:
if not self.use_for_single_location_local:
# This is an error case, because it must be set to use a single location to be called without get parameters
# This is a dev_facing_error
log.error(
Expand All @@ -610,7 +608,7 @@ def peer_grading_problem(self, data=None):
# Checked above
'staff_access': False,
'track_changes': getattr(module, 'track_changes', False),
'use_single_location': self.use_for_single_location,
'use_single_location': self.use_for_single_location_local,
})

return {'html': html, 'success': True}
Expand Down Expand Up @@ -656,10 +654,24 @@ def non_editable_metadata_fields(self):
return non_editable_fields

def get_required_module_descriptors(self):
"""Returns a list of XModuleDescritpor instances upon which this module depends, but are
not children of this module"""
"""
Returns a list of XModuleDescriptor instances upon which this module depends, but are
not children of this module.
"""

# If use_for_single_location is True, this is linked to an open ended problem.
if self.use_for_single_location:
return [self.system.load_item(self.link_to_location)]
# Try to load the linked module.
# If we can't load it, return empty list to avoid exceptions on progress page.
try:
linked_module = self.system.load_item(self.link_to_location)
return [linked_module]
except (NoPathToItem, ItemNotFoundError):
error_message = ("Cannot find the combined open ended module "
"at location {0} being linked to from peer "
"grading module {1}").format(self.link_to_location, self.location)
log.error(error_message)
return []
else:
return []

Expand Down
Loading