Commit 4ea1daaa by Calen Pennington

Make user profiles work again after the switch to an XMLModuleStore. Staff user…

Make user profiles work again after the switch to an XMLModuleStore. Staff user histograms are still broken
parent 0ff4af9a
......@@ -88,8 +88,5 @@ class Module(XModule):
def get_children(self):
return [self.module_from_xml(child) for child in self._xml_children()]
def rendered_children(self):
return [self.render_function(child) for child in self._xml_children()]
def get_html(self):
return '\n'.join(child.get_html() for child in self.get_children())
......@@ -229,7 +229,13 @@ class CapaModule(XModule):
# TODO: Should be: self.filename=only_one(dom2.xpath('/problem/@filename'))
self.filename = "problems/" + only_one(dom2.xpath('/problem/@filename')) + ".xml"
self.name = only_one(dom2.xpath('/problem/@name'))
self.weight = only_one(dom2.xpath('/problem/@weight'))
weight_string = only_one(dom2.xpath('/problem/@weight'))
if weight_string:
self.weight = float(weight_string)
else:
self.weight = 1
if self.rerandomize == 'never':
seed = 1
elif self.rerandomize == "per_student" and hasattr(system, 'id'):
......
......@@ -50,7 +50,6 @@ class VideoModule(XModule):
'id': self.location.html_id(),
'position': self.position,
'name': self.name,
'annotations': self.annotations,
})
def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs):
......@@ -65,9 +64,6 @@ class VideoModule(XModule):
if 'position' in state:
self.position = int(float(state['position']))
self.annotations = [(e.get("name"), self.render_function(e)) \
for e in xmltree]
class VideoDescriptor(RawDescriptor):
module_class = VideoModule
......@@ -83,6 +83,7 @@ class XModule(object):
self.id = self.location.url()
self.name = self.location.name
self.display_name = kwargs.get('display_name', '')
self.type = self.location.category
self._loaded_children = None
def get_name(self):
......
......@@ -75,8 +75,16 @@ class StudentModuleCache(object):
'''
if user.is_authenticated():
module_ids = self._get_module_state_keys(descriptor, depth)
self.cache = list(StudentModule.objects.filter(student=user,
module_state_key__in=module_ids))
# This works around a limitation in sqlite3 on the number of parameters
# that can be put into a single query
self.cache = []
chunk_size = 500
for id_chunk in [module_ids[i:i+chunk_size] for i in xrange(0, len(module_ids), chunk_size)]:
self.cache.extend(StudentModule.objects.filter(
student=user,
module_state_key__in=id_chunk)
)
else:
self.cache = []
......
......@@ -29,7 +29,7 @@ class I4xSystem(object):
and user, or other environment-specific info.
'''
def __init__(self, ajax_url, track_function, render_function,
get_module, render_template, request=None,
get_module, render_template, user=None,
filestore=None):
'''
Create a closure around the system environment.
......@@ -47,7 +47,7 @@ class I4xSystem(object):
and 'type'.
render_template - a function that takes (template_file, context), and returns
rendered html.
request - the request in progress
user - The user to base the seed off of for this request
filestore - A filestore ojbect. Defaults to an instance of OSFS based at
settings.DATA_DIR.
'''
......@@ -59,7 +59,7 @@ class I4xSystem(object):
self.render_template = render_template
self.exception404 = Http404
self.DEBUG = settings.DEBUG
self.id = request.user.id if request is not None else 0
self.seed = user.id if user is not None else 0
def get(self, attr):
''' provide uniform access to attributes (like etree).'''
......@@ -234,13 +234,13 @@ def get_module(user, request, location, student_module_cache, position=None):
system = I4xSystem(track_function=make_track_function(request),
render_function=lambda xml: render_x_module(
user, request, xml, student_module_cache, position),
user, xml, student_module_cache, position),
render_template=render_to_string,
ajax_url=ajax_url,
request=request,
# TODO (cpennington): Figure out how to share info between systems
filestore=descriptor.system.resources_fs,
get_module=_get_module,
user=user,
)
# pass position specified in URL to module through I4xSystem
system.set('position', position)
......@@ -272,7 +272,7 @@ def get_module(user, request, location, student_module_cache, position=None):
return (module, instance_module, shared_module, descriptor.type)
def render_x_module(user, request, module_xml, student_module_cache, position=None):
def render_x_module(user, module, student_module_cache, position=None):
''' Generic module for extensions. This renders to HTML.
modules include sequential, vertical, problem, video, html
......@@ -282,10 +282,9 @@ def render_x_module(user, request, module_xml, student_module_cache, position=No
Arguments:
- user : current django User
- request : current django HTTPrequest
- module_xml : lxml etree of xml subtree for the current module
- student_module_cache : list of StudentModule objects, one of which may match this module type and id
- position : extra information from URL for user-specified position within module
- module : lxml etree of xml subtree for the current module
- student_module_cache : list of StudentModule objects, one of which may match this module type and id
- position : extra information from URL for user-specified position within module
Returns:
......@@ -296,7 +295,7 @@ def render_x_module(user, request, module_xml, student_module_cache, position=No
return {"content": ""}
(instance, _, _, module_type) = get_module(
user, request, module_xml, student_module_cache, position)
user, module_xml, student_module_cache, position)
content = instance.get_html()
......
......@@ -20,17 +20,16 @@ from module_render import render_x_module, toc_for_course, get_module, get_secti
from models import StudentModuleCache
from student.models import UserProfile
from multicourse import multicourse_settings
from keystore.django import keystore
import courseware.content_parser as content_parser
import courseware.grades as grades
from courseware import grades, content_parser
log = logging.getLogger("mitx.courseware")
etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False,
remove_comments = True))
remove_comments=True))
template_imports={'urllib':urllib}
template_imports = {'urllib': urllib}
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
def gradebook(request):
......@@ -49,6 +48,7 @@ def gradebook(request):
return render_to_response('gradebook.html', {'students': student_info})
@login_required
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
def profile(request, student_id=None):
......@@ -60,11 +60,14 @@ def profile(request, student_id=None):
else:
if 'course_admin' not in content_parser.user_groups(request.user):
raise Http404
student = User.objects.get( id = int(student_id))
student = User.objects.get(id=int(student_id))
user_info = UserProfile.objects.get(user=student) # request.user.profile_cache #
user_info = UserProfile.objects.get(user=student)
coursename = multicourse_settings.get_coursename_from_request(request)
course_location = multicourse_settings.get_course_location(coursename)
student_module_cache = StudentModuleCache(request.user, keystore().get_item(course_location))
course, _, _, _ = get_module(request.user, request, course_location, student_module_cache)
context = {'name': user_info.name,
'username': student.username,
......@@ -74,7 +77,7 @@ def profile(request, student_id=None):
'format_url_params': content_parser.format_url_params,
'csrf': csrf(request)['csrf_token']
}
context.update(grades.grade_sheet(student, coursename))
context.update(grades.grade_sheet(student, course, student_module_cache))
return render_to_response('profile.html', context)
......@@ -127,7 +130,7 @@ def render_section(request, section):
student_module_cache = StudentModuleCache(request.user, dom)
try:
module = render_x_module(user, request, dom, student_module_cache)
module = render_x_module(user, dom, student_module_cache)
except:
log.exception("Unable to load module")
context.update({
......
......@@ -132,7 +132,7 @@ COURSE_DEFAULT = '6.002_Spring_2012'
COURSE_SETTINGS = {'6.002_Spring_2012': {'number' : '6.002x',
'title' : 'Circuits and Electronics',
'xmlpath': '6002x/',
'location': 'i4x://edx/6002xs12/course/6_002_Spring_2012',
'location': 'i4x://edx/6002xs12/course/6.002_Spring_2012',
}
}
......
......@@ -13,11 +13,3 @@
</article>
</div>
</div>
<ol class="video-mod">
% for t in annotations:
<li id="video-${annotations.index(t)}">
${t[1]['content']}
</li>
% endfor
</ol>
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