Merge pull request #57 from MITx/fix-multicourse
fix multicourse; fix bug in I4xSystem - self.filestore not set when
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
def contextualize_text(text, context): # private
|
||||
''' Takes a string with variables. E.g. $a+$b.
|
||||
Does a substitution of those variables from the context '''
|
||||
if not text: return text
|
||||
for key in sorted(context, lambda x,y:cmp(len(y),len(x))):
|
||||
text=text.replace('$'+key, str(context[key]))
|
||||
return text
|
||||
|
||||
@@ -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:
|
||||
@@ -307,12 +305,12 @@ def quickedit(request, id=None):
|
||||
print "In deployed use, this will only edit on one server"
|
||||
print "We need a setting to disable for production where there is"
|
||||
print "a load balanacer"
|
||||
if not request.user.is_staff():
|
||||
if not request.user.is_staff:
|
||||
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'):
|
||||
|
||||
@@ -1 +1,24 @@
|
||||
# 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
|
||||
|
||||
89
templates/mathjax_include.html
Normal file
89
templates/mathjax_include.html
Normal file
@@ -0,0 +1,89 @@
|
||||
##
|
||||
## File: templates/mathjax_include.html
|
||||
##
|
||||
## Advanced mathjax using 2.0-latest CDN for Dynamic Math
|
||||
##
|
||||
## This enables ASCIIMathJAX, and is used by js_textbox
|
||||
|
||||
<script type="text/x-mathjax-config">
|
||||
|
||||
// (function () {
|
||||
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
|
||||
var math = null;
|
||||
var jaxset = {}; // associative array of the element jaxs for the math output.
|
||||
var mmlset = {}; // associative array of mathml from each jax
|
||||
|
||||
// constructs mathML of the specified jax element
|
||||
function toMathML(jax,callback) {
|
||||
var mml;
|
||||
try {
|
||||
mml = jax.root.toMathML("");
|
||||
} catch(err) {
|
||||
if (!err.restart) {throw err} // an actual error
|
||||
return MathJax.Callback.After([toMathML,jax,callback],err.restart);
|
||||
}
|
||||
MathJax.Callback(callback)(mml);
|
||||
}
|
||||
|
||||
// function to queue in MathJax to get put the MathML expression in in the right document element
|
||||
function UpdateMathML(jax,id) {
|
||||
toMathML(jax,function (mml) {
|
||||
// document.getElementById(id+'_fromjs').value=math.originalText+ "\n\n=>\n\n"+ mml;
|
||||
delem = document.getElementById("input_" + id + "_fromjs");
|
||||
if (delem) { delem.value=mml; };
|
||||
mmlset[id] = mml;
|
||||
})
|
||||
}
|
||||
|
||||
MathJax.Hub.Config({
|
||||
tex2jax: {
|
||||
inlineMath: [
|
||||
["\\(","\\)"],
|
||||
['[mathjaxinline]','[/mathjaxinline]']
|
||||
],
|
||||
displayMath: [
|
||||
["\\[","\\]"],
|
||||
['[mathjax]','[/mathjax]']
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// The onchange event handler that typesets the
|
||||
// math entered by the user
|
||||
//
|
||||
window.UpdateMath = function (Am,id) {
|
||||
QUEUE.Push(["Text",jaxset[id],Am]);
|
||||
QUEUE.Push(UpdateMathML(jaxset[id],id));
|
||||
}
|
||||
|
||||
// })();
|
||||
|
||||
function DoUpdateMath(inputId) {
|
||||
var str = document.getElementById("input_"+inputId).value;
|
||||
|
||||
// make sure the input field is in the jaxset
|
||||
if ($.inArray(inputId,jaxset) == -1){
|
||||
//alert('missing '+inputId);
|
||||
if (document.getElementById("display_" + inputId)){
|
||||
MathJax.Hub.queue.Push(function () {
|
||||
math = MathJax.Hub.getAllJax("display_" + inputId)[0];
|
||||
if (math){
|
||||
jaxset[inputId] = math;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
UpdateMath(str,inputId)
|
||||
}
|
||||
|
||||
</script>
|
||||
<%block name="headextra"/>
|
||||
|
||||
<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates -->
|
||||
<!-- TODO: move to settings -->
|
||||
<script type="text/javascript"
|
||||
src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-MML-AM_HTMLorMML-full">
|
||||
</script>
|
||||
|
||||
@@ -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>
|
||||
|
||||
25
templates/optioninput.html
Normal file
25
templates/optioninput.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<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>
|
||||
@@ -2,6 +2,15 @@
|
||||
% if problem['weight']:
|
||||
: ${ problem['weight'] } points
|
||||
% endif
|
||||
% if settings.QUICKEDIT:
|
||||
<span class="staff">
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<font size=-2><a href=${MITX_ROOT_URL}/quickedit/${id}>Quick
|
||||
Edit Problem</a></font></span>
|
||||
% endif
|
||||
</h2>
|
||||
|
||||
<section class="problem">
|
||||
|
||||
2
urls.py
2
urls.py
@@ -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'),)
|
||||
|
||||
Reference in New Issue
Block a user