per-section rendering works, if unclean
--HG-- branch : pmitros-section
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from datetime import timedelta
|
||||
@@ -141,12 +142,15 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None):
|
||||
#to its children later.
|
||||
return
|
||||
|
||||
def user_groups(user):
|
||||
# TODO: Rewrite in Django
|
||||
return [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])]
|
||||
|
||||
def course_file(user):
|
||||
# TODO: Cache.
|
||||
filename = UserProfile.objects.get(user=user).courseware
|
||||
|
||||
# TODO: Rewrite in Django
|
||||
groups = [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])]
|
||||
groups = user_groups(user)
|
||||
|
||||
options = {'dev_content':settings.DEV_CONTENT,
|
||||
'groups' : groups}
|
||||
@@ -158,6 +162,24 @@ def course_file(user):
|
||||
propogate_downward_tag(tree, "graceperiod")
|
||||
return tree
|
||||
|
||||
def section_file(user, section):
|
||||
filename = section+".xml"
|
||||
|
||||
if filename not in os.listdir(settings.DATA_DIR + '/sections/'):
|
||||
print filename+" not in "+str(os.listdir(settings.DATA_DIR + '/sections/'))
|
||||
return None
|
||||
|
||||
options = {'dev_content':settings.DEV_CONTENT,
|
||||
'groups' : user_groups(user)}
|
||||
|
||||
tree = etree.XML(render_to_string(filename, options, namespace = 'sections'))
|
||||
id_tag(tree)
|
||||
propogate_downward_tag(tree, "due")
|
||||
propogate_downward_tag(tree, "graded")
|
||||
propogate_downward_tag(tree, "graceperiod")
|
||||
return tree
|
||||
|
||||
|
||||
def module_xml(coursefile, module, id_tag, module_id):
|
||||
''' Get XML for a module based on module and module_id. Assumes
|
||||
module occurs once in courseware XML file.. '''
|
||||
|
||||
@@ -71,8 +71,8 @@ def profile(request):
|
||||
response = response_by_id[id]
|
||||
if response.grade!=None:
|
||||
correct=response.grade
|
||||
|
||||
total=courseware.modules.capa_module.Module(etree.tostring(p), "id").max_score() # TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
|
||||
# TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
|
||||
total=courseware.modules.capa_module.Module(etree.tostring(p), "id").max_score()
|
||||
scores.append((int(correct),total, graded ))
|
||||
|
||||
|
||||
@@ -247,6 +247,40 @@ def render_accordion(request,course,chapter,section):
|
||||
return {'init_js':render_to_string('accordion_init.js',context),
|
||||
'content':render_to_string('accordion.html',context)}
|
||||
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
def render_section(request, section):
|
||||
''' TODO: Consolidate with index
|
||||
'''
|
||||
user = request.user
|
||||
if not settings.COURSEWARE_ENABLED or not user.is_authenticated():
|
||||
return redirect('/')
|
||||
|
||||
# try:
|
||||
dom = content_parser.section_file(user, section)
|
||||
#except:
|
||||
# raise Http404
|
||||
|
||||
accordion=render_accordion(request, '', '', '')
|
||||
|
||||
module_ids = dom.xpath("//@id")
|
||||
|
||||
module_object_preload = list(StudentModule.objects.filter(student=user,
|
||||
module_id__in=module_ids))
|
||||
|
||||
module=render_module(user, request, dom, module_object_preload)
|
||||
|
||||
if 'init_js' not in module:
|
||||
module['init_js']=''
|
||||
|
||||
context={'init':accordion['init_js']+module['init_js'],
|
||||
'accordion':accordion['content'],
|
||||
'content':module['content'],
|
||||
'csrf':csrf(request)['csrf_token']}
|
||||
|
||||
result = render_to_response('courseware.html', context)
|
||||
return result
|
||||
|
||||
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
def index(request, course="6.002 Spring 2012", chapter="Using the System", section="Hints"):
|
||||
''' Displays courseware accordion, and any associated content.
|
||||
|
||||
2
urls.py
2
urls.py
@@ -40,6 +40,7 @@ if settings.COURSEWARE_ENABLED:
|
||||
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index', name="courseware_section"),
|
||||
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/$', 'courseware.views.index', name="courseware_chapter"),
|
||||
url(r'^courseware/(?P<course>[^/]*)/$', 'courseware.views.index', name="courseware_course"),
|
||||
url(r'^section/(?P<section>[^/]*)/$', 'courseware.views.render_section'),
|
||||
url(r'^modx/(?P<module>[^/]*)/(?P<id>[^/]*)/(?P<dispatch>[^/]*)$', 'courseware.views.modx_dispatch'), #reset_problem'),
|
||||
url(r'^profile$', 'courseware.views.profile'),
|
||||
url(r'^change_setting$', 'student.views.change_setting'),
|
||||
@@ -63,3 +64,4 @@ if settings.ASKBOT_ENABLED:
|
||||
)
|
||||
|
||||
urlpatterns = patterns(*urlpatterns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user