Provide access to the course_id directly on XModules/Descriptors
Fixes [BLD-456] and [LMS-1392], but making sure that we're always asking XModules about their course_id (since the ModuleSystem has access to that data).
This commit is contained in:
@@ -4,6 +4,7 @@ some xmodules by conditions.
|
||||
|
||||
import json
|
||||
import logging
|
||||
from lazy import lazy
|
||||
from lxml import etree
|
||||
from pkg_resources import resource_string
|
||||
|
||||
@@ -97,10 +98,12 @@ class ConditionalModule(ConditionalFields, XModule):
|
||||
return xml_value, attr_name
|
||||
raise Exception('Error in conditional module: unknown condition "%s"' % xml_attr)
|
||||
|
||||
def is_condition_satisfied(self):
|
||||
self.required_modules = [self.system.get_module(descriptor) for
|
||||
descriptor in self.descriptor.get_required_module_descriptors()]
|
||||
@lazy
|
||||
def required_modules(self):
|
||||
return [self.system.get_module(descriptor) for
|
||||
descriptor in self.descriptor.get_required_module_descriptors()]
|
||||
|
||||
def is_condition_satisfied(self):
|
||||
xml_value, attr_name = self._get_condition()
|
||||
|
||||
if xml_value and self.required_modules:
|
||||
|
||||
@@ -181,7 +181,7 @@ class LTIModule(LTIFields, XModule):
|
||||
]
|
||||
|
||||
# Obtains client_key and client_secret credentials from current course:
|
||||
course_id = self.runtime.course_id
|
||||
course_id = self.course_id
|
||||
course_location = CourseDescriptor.id_to_location(course_id)
|
||||
course = self.descriptor.runtime.modulestore.get_item(course_location)
|
||||
client_key = client_secret = ''
|
||||
|
||||
@@ -519,7 +519,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
|
||||
error_text = ""
|
||||
problem_list = []
|
||||
try:
|
||||
problem_list_json = self.peer_gs.get_problem_list(self.system.course_id, self.system.anonymous_student_id)
|
||||
problem_list_json = self.peer_gs.get_problem_list(self.course_id, self.system.anonymous_student_id)
|
||||
problem_list_dict = problem_list_json
|
||||
success = problem_list_dict['success']
|
||||
if 'error' in problem_list_dict:
|
||||
@@ -569,7 +569,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
|
||||
|
||||
ajax_url = self.ajax_url
|
||||
html = self.system.render_template('peer_grading/peer_grading.html', {
|
||||
'course_id': self.system.course_id,
|
||||
'course_id': self.course_id,
|
||||
'ajax_url': ajax_url,
|
||||
'success': success,
|
||||
'problem_list': good_problem_list,
|
||||
@@ -603,7 +603,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
|
||||
html = self.system.render_template('peer_grading/peer_grading_problem.html', {
|
||||
'view_html': '',
|
||||
'problem_location': problem_location,
|
||||
'course_id': self.system.course_id,
|
||||
'course_id': self.course_id,
|
||||
'ajax_url': ajax_url,
|
||||
# Checked above
|
||||
'staff_access': False,
|
||||
|
||||
@@ -133,6 +133,10 @@ class XModuleMixin(XBlockMixin):
|
||||
default=None
|
||||
)
|
||||
|
||||
@property
|
||||
def course_id(self):
|
||||
return self.runtime.course_id
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.location.url()
|
||||
@@ -743,6 +747,7 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
|
||||
self.xmodule_runtime.xmodule_instance = descriptor._xmodule # pylint: disable=protected-access
|
||||
return self.xmodule_runtime.xmodule_instance
|
||||
|
||||
course_id = module_attr('course_id')
|
||||
displayable_items = module_attr('displayable_items')
|
||||
get_display_items = module_attr('get_display_items')
|
||||
get_icon_class = module_attr('get_icon_class')
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
<%
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
# course_id = module.location.course_id
|
||||
def get_course_id(module):
|
||||
return module.location.org +'/' + module.location.course +'/' + \
|
||||
module.system.ajax_url.split('/')[4]
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
def _message(reqm, message):
|
||||
return message.format(link="<a href={url}>{url_name}</a>".format(
|
||||
url = reverse('jump_to', kwargs=dict(course_id=get_course_id(reqm),
|
||||
url = reverse('jump_to', kwargs=dict(course_id=reqm.course_id,
|
||||
location=reqm.location.url())),
|
||||
url_name = reqm.display_name_with_default))
|
||||
%>
|
||||
|
||||
Reference in New Issue
Block a user