Commit 5e8fbcdc by ichuang

fix multicourse; fix bug in I4xSystem - self.filestore not set when

filestore not None.  mitxhome.html now properly automatically lists
all courses given in settings.COURSE_SETTINGS.  mitxhome now served
from multicourse.views.  optioninput.html was missing; fixed. cleaned
up access to request.session for coursename in courseware/views.py
parent b8b9928a
......@@ -13,8 +13,8 @@ from fs.osfs import OSFS
from django.conf import settings
from mitxmako.shortcuts import render_to_string
from models import StudentModule
from multicourse import multicourse_settings
import courseware.modules
......@@ -31,6 +31,8 @@ class I4xSystem(object):
self.track_function = track_function
if not filestore:
self.filestore = OSFS(settings.DATA_DIR)
else:
self.filestore = filestore
self.render_function = render_function
self.exception404 = Http404
def __repr__(self):
......@@ -95,15 +97,15 @@ def render_x_module(user, request, xml_module, module_object_preload):
state = smod.state
# get coursename if stored
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
xp = multicourse_settings.get_course_xmlpath(coursename) # path to XML for the course
# Create a new instance
ajax_url = settings.MITX_ROOT_URL + '/modx/'+module_type+'/'+module_id+'/'
system = I4xSystem(track_function = make_track_function(request),
render_function = lambda x: render_module(user, request, x, module_object_preload),
ajax_url = ajax_url,
filestore = None
filestore = OSFS(settings.DATA_DIR + xp),
)
instance=module_class(system,
etree.tostring(xml_module),
......
......@@ -2,6 +2,8 @@ import logging
import urllib
import json
from fs.osfs import OSFS
from django.conf import settings
from django.core.context_processors import csrf
from django.contrib.auth.models import User
......@@ -38,9 +40,7 @@ def gradebook(request):
if 'course_admin' not in content_parser.user_groups(request.user):
raise Http404
# TODO: This should be abstracted out. We repeat this logic many times.
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
student_objects = User.objects.all()[:100]
student_info = [{'username' :s.username,
......@@ -68,8 +68,7 @@ def profile(request, student_id = None):
user_info = UserProfile.objects.get(user=student) # request.user.profile_cache #
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
context={'name':user_info.name,
'username':student.username,
......@@ -110,8 +109,7 @@ def render_section(request, section):
if not settings.COURSEWARE_ENABLED:
return redirect('/')
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
try:
dom = content_parser.section_file(user, section, coursename)
......@@ -251,8 +249,8 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
ajax_url = settings.MITX_ROOT_URL + '/modx/'+module+'/'+id+'/'
# get coursename if stored
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
xp = multicourse_settings.get_course_xmlpath(coursename) # path to XML for the course
# Grab the XML corresponding to the request from course.xml
try:
......@@ -269,7 +267,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
system = I4xSystem(track_function = make_track_function(request),
render_function = None,
ajax_url = ajax_url,
filestore = None
filestore = OSFS(settings.DATA_DIR + xp),
)
try:
......@@ -311,8 +309,8 @@ def quickedit(request, id=None):
return redirect('/')
# get coursename if stored
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
coursename = multicourse_settings.get_coursename_from_request(request)
xp = multicourse_settings.get_course_xmlpath(coursename) # path to XML for the course
def get_lcp(coursename,id):
# Grab the XML corresponding to the request from course.xml
......@@ -325,9 +323,8 @@ def quickedit(request, id=None):
system = I4xSystem(track_function = make_track_function(request),
render_function = None,
ajax_url = ajax_url,
filestore = None,
coursename = coursename,
role = 'staff' if request.user.is_staff else 'student', # TODO: generalize this
filestore = OSFS(settings.DATA_DIR + xp),
#role = 'staff' if request.user.is_staff else 'student', # TODO: generalize this
)
instance=courseware.modules.get_module_class(module)(system,
xml,
......
......@@ -42,6 +42,11 @@ else: # default to 6.002_Spring_2012
#-----------------------------------------------------------------------------
# wrapper functions around course settings
def get_coursename_from_request(request):
if 'coursename' in request.session: coursename = request.session['coursename']
else: coursename = None
return coursename
def get_course_settings(coursename):
if not coursename:
if hasattr(settings,'COURSE_DEFAULT'):
......
# multicourse/views.py
import datetime
import json
import sys
from django.conf import settings
from django.contrib.auth.models import User
from django.core.context_processors import csrf
from django.core.mail import send_mail
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string
import courseware.capa.calc
import track.views
from multicourse import multicourse_settings
def mitxhome(request):
''' Home page (link from main header). List of courses. '''
if settings.ENABLE_MULTICOURSE:
context = {'courseinfo' : multicourse_settings.COURSE_SETTINGS}
return render_to_response("mitxhome.html", context)
return info(request)
......@@ -61,12 +61,6 @@ def info(request):
''' Info page (link from main header) '''
return render_to_response("info.html", {})
def mitxhome(request):
''' Home page (link from main header). List of courses. '''
if settings.ENABLE_MULTICOURSE:
return render_to_response("mitxhome.html", {})
return info(request)
# From http://djangosnippets.org/snippets/1042/
def parse_accept_header(accept):
"""Parse the Accept header *accept*, returning a list with pairs of
......
......@@ -28,10 +28,10 @@ $(document).ready(function(){
<hr width="100%">
<h3>Courses available:</h3>
<ul>
<li><a href=${ MITX_ROOT_URL }/courseware/6.002_Spring_2012/>6.002 (Spring 2012)</a></li>
<li><a href=${ MITX_ROOT_URL }/courseware/8.02_Spring_2013/>8.02 (Spring 2013)</a></li>
<li><a href=${ MITX_ROOT_URL }/courseware/8.01_Spring_2013/>8.01 (Spring 201x)</a></li>
</ul>
% for coursename, info in courseinfo.items():
<li><a href=${ MITX_ROOT_URL }/courseware/${coursename}/>${info['title']} (${coursename})</a></li>
% endfor
</ul>
</section>
</div>
</section>
<form class="option-input">
<select name="input_${id}" id="input_${id}" >
<option value="option_${id}_dummy_default"> </option>
% for option_id, option_description in options.items():
<option value="${option_id}"
% if (option_id==value):
selected="true"
% endif
> ${option_description}</option>
% endfor
</select>
<span id="answer_${id}"></span>
% if state == 'unsubmitted':
<span class="unanswered" style="display:inline-block;" id="status_${id}"></span>
% elif state == 'correct':
<span class="correct" id="status_${id}"></span>
% elif state == 'incorrect':
<span class="incorrect" id="status_${id}"></span>
% elif state == 'incomplete':
<span class="incorrect" id="status_${id}"></span>
% endif
</form>
......@@ -70,7 +70,7 @@ if settings.COURSEWARE_ENABLED:
)
if settings.ENABLE_MULTICOURSE:
urlpatterns += (url(r'^mitxhome$', 'util.views.mitxhome'),)
urlpatterns += (url(r'^mitxhome$', 'multicourse.views.mitxhome'),)
if settings.QUICKEDIT:
urlpatterns += (url(r'^quickedit/(?P<id>[^/]*)$', 'courseware.views.quickedit'),)
......
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