Commit 4c8ff641 by John Jarvis

Merge branch 'master' of github.com:MITx/mitx into jarv/add-local-logging

parents 27725ab6 a27ba692
...@@ -61,7 +61,7 @@ class GithubSyncTestCase(TestCase): ...@@ -61,7 +61,7 @@ class GithubSyncTestCase(TestCase):
self.assertIn( self.assertIn(
Location('i4x://edX/toy/chapter/Overview'), Location('i4x://edX/toy/chapter/Overview'),
[child.location for child in self.import_course.get_children()]) [child.location for child in self.import_course.get_children()])
self.assertEquals(1, len(self.import_course.get_children())) self.assertEquals(2, len(self.import_course.get_children()))
@patch('github_sync.sync_with_github') @patch('github_sync.sync_with_github')
def test_sync_all_with_github(self, sync_with_github): def test_sync_all_with_github(self, sync_with_github):
......
...@@ -14,6 +14,8 @@ This is used by capa_module. ...@@ -14,6 +14,8 @@ This is used by capa_module.
from __future__ import division from __future__ import division
from datetime import datetime
import json
import logging import logging
import math import math
import numpy import numpy
...@@ -32,6 +34,7 @@ from correctmap import CorrectMap ...@@ -32,6 +34,7 @@ from correctmap import CorrectMap
import eia import eia
import inputtypes import inputtypes
from util import contextualize_text, convert_files_to_filenames from util import contextualize_text, convert_files_to_filenames
import xqueue_interface
# to be replaced with auto-registering # to be replaced with auto-registering
import responsetypes import responsetypes
...@@ -202,11 +205,24 @@ class LoncapaProblem(object): ...@@ -202,11 +205,24 @@ class LoncapaProblem(object):
''' '''
Returns True if any part of the problem has been submitted to an external queue Returns True if any part of the problem has been submitted to an external queue
''' '''
queued = False return any(self.correct_map.is_queued(answer_id) for answer_id in self.correct_map)
for answer_id in self.correct_map:
if self.correct_map.is_queued(answer_id):
queued = True def get_recentmost_queuetime(self):
return queued '''
Returns a DateTime object that represents the timestamp of the most recent queueing request, or None if not queued
'''
if not self.is_queued():
return None
# Get a list of timestamps of all queueing requests, then convert it to a DateTime object
queuetime_strs = [self.correct_map.get_queuetime_str(answer_id)
for answer_id in self.correct_map
if self.correct_map.is_queued(answer_id)]
queuetimes = [datetime.strptime(qt_str, xqueue_interface.dateformat) for qt_str in queuetime_strs]
return max(queuetimes)
def grade_answers(self, answers): def grade_answers(self, answers):
''' '''
......
...@@ -15,7 +15,8 @@ class CorrectMap(object): ...@@ -15,7 +15,8 @@ class CorrectMap(object):
- msg : string (may have HTML) giving extra message response (displayed below textline or textbox) - msg : string (may have HTML) giving extra message response (displayed below textline or textbox)
- hint : string (may have HTML) giving optional hint (displayed below textline or textbox, above msg) - hint : string (may have HTML) giving optional hint (displayed below textline or textbox, above msg)
- hintmode : one of (None,'on_request','always') criteria for displaying hint - hintmode : one of (None,'on_request','always') criteria for displaying hint
- queuekey : a random integer for xqueue_callback verification - queuestate : Dict {key:'', time:''} where key is a secret string, and time is a string dump
of a DateTime object in the format '%Y%m%d%H%M%S'. Is None when not queued
Behaves as a dict. Behaves as a dict.
''' '''
...@@ -31,14 +32,15 @@ class CorrectMap(object): ...@@ -31,14 +32,15 @@ class CorrectMap(object):
def __iter__(self): def __iter__(self):
return self.cmap.__iter__() return self.cmap.__iter__()
def set(self, answer_id=None, correctness=None, npoints=None, msg='', hint='', hintmode=None, queuekey=None): # See the documentation for 'set_dict' for the use of kwargs
def set(self, answer_id=None, correctness=None, npoints=None, msg='', hint='', hintmode=None, queuestate=None, **kwargs):
if answer_id is not None: if answer_id is not None:
self.cmap[answer_id] = {'correctness': correctness, self.cmap[answer_id] = {'correctness': correctness,
'npoints': npoints, 'npoints': npoints,
'msg': msg, 'msg': msg,
'hint': hint, 'hint': hint,
'hintmode': hintmode, 'hintmode': hintmode,
'queuekey': queuekey, 'queuestate': queuestate,
} }
def __repr__(self): def __repr__(self):
...@@ -52,25 +54,39 @@ class CorrectMap(object): ...@@ -52,25 +54,39 @@ class CorrectMap(object):
def set_dict(self, correct_map): def set_dict(self, correct_map):
''' '''
set internal dict to provided correct_map dict Set internal dict of CorrectMap to provided correct_map dict
for graceful migration, if correct_map is a one-level dict, then convert it to the new
dict of dicts format. correct_map is saved by LMS as a plaintext JSON dump of the correctmap dict. This means that
when the definition of CorrectMap (e.g. its properties) are altered, existing correct_map dict
not coincide with the newest CorrectMap format as defined by self.set.
For graceful migration, feed the contents of each correct map to self.set, rather than
making a direct copy of the given correct_map dict. This way, the common keys between
the incoming correct_map dict and the new CorrectMap instance will be written, while
mismatched keys will be gracefully ignored.
Special migration case:
If correct_map is a one-level dict, then convert it to the new dict of dicts format.
''' '''
if correct_map and not (type(correct_map[correct_map.keys()[0]]) == dict): if correct_map and not (type(correct_map[correct_map.keys()[0]]) == dict):
self.__init__() # empty current dict self.__init__() # empty current dict
for k in correct_map: self.set(k, correct_map[k]) # create new dict entries for k in correct_map: self.set(k, correct_map[k]) # create new dict entries
else: else:
self.cmap = correct_map self.__init__()
for k in correct_map: self.set(k, **correct_map[k])
def is_correct(self, answer_id): def is_correct(self, answer_id):
if answer_id in self.cmap: return self.cmap[answer_id]['correctness'] == 'correct' if answer_id in self.cmap: return self.cmap[answer_id]['correctness'] == 'correct'
return None return None
def is_queued(self, answer_id): def is_queued(self, answer_id):
return answer_id in self.cmap and self.cmap[answer_id]['queuekey'] is not None return answer_id in self.cmap and self.cmap[answer_id]['queuestate'] is not None
def is_right_queuekey(self, answer_id, test_key): def is_right_queuekey(self, answer_id, test_key):
return answer_id in self.cmap and self.cmap[answer_id]['queuekey'] == test_key return self.is_queued(answer_id) and self.cmap[answer_id]['queuestate']['key'] == test_key
def get_queuetime_str(self, answer_id):
return self.cmap[answer_id]['queuestate']['time']
def get_npoints(self, answer_id): def get_npoints(self, answer_id):
npoints = self.get_property(answer_id, 'npoints') npoints = self.get_property(answer_id, 'npoints')
......
...@@ -351,7 +351,7 @@ def filesubmission(element, value, status, render_template, msg=''): ...@@ -351,7 +351,7 @@ def filesubmission(element, value, status, render_template, msg=''):
if status == 'incomplete': # Flag indicating that the problem has been queued, 'msg' is length of queue if status == 'incomplete': # Flag indicating that the problem has been queued, 'msg' is length of queue
status = 'queued' status = 'queued'
queue_len = msg queue_len = msg
msg = 'Submitted to grader. (Queue length: %s)' % queue_len msg = 'Submitted to grader.'
context = { 'id': eid, 'state': status, 'msg': msg, 'value': value, context = { 'id': eid, 'state': status, 'msg': msg, 'value': value,
'queue_len': queue_len, 'allowed_files': allowed_files, 'queue_len': queue_len, 'allowed_files': allowed_files,
...@@ -384,7 +384,7 @@ def textbox(element, value, status, render_template, msg=''): ...@@ -384,7 +384,7 @@ def textbox(element, value, status, render_template, msg=''):
if status == 'incomplete': # Flag indicating that the problem has been queued, 'msg' is length of queue if status == 'incomplete': # Flag indicating that the problem has been queued, 'msg' is length of queue
status = 'queued' status = 'queued'
queue_len = msg queue_len = msg
msg = 'Submitted to grader. (Queue length: %s)' % queue_len msg = 'Submitted to grader.'
# For CodeMirror # For CodeMirror
mode = element.get('mode','python') mode = element.get('mode','python')
......
...@@ -8,6 +8,7 @@ Used by capa_problem.py ...@@ -8,6 +8,7 @@ Used by capa_problem.py
''' '''
# standard library imports # standard library imports
import cgi
import inspect import inspect
import json import json
import logging import logging
...@@ -26,6 +27,7 @@ import xml.sax.saxutils as saxutils ...@@ -26,6 +27,7 @@ import xml.sax.saxutils as saxutils
# specific library imports # specific library imports
from calc import evaluator, UndefinedVariable from calc import evaluator, UndefinedVariable
from correctmap import CorrectMap from correctmap import CorrectMap
from datetime import datetime
from util import * from util import *
from lxml import etree from lxml import etree
from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME? from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME?
...@@ -317,30 +319,37 @@ class JavascriptResponse(LoncapaResponse): ...@@ -317,30 +319,37 @@ class JavascriptResponse(LoncapaResponse):
def compile_display_javascript(self): def compile_display_javascript(self):
latestTimestamp = 0 # TODO FIXME
basepath = self.system.filestore.root_path + '/js/' # arjun: removing this behavior for now (and likely forever). Keeping
for filename in (self.display_dependencies + [self.display]): # until we decide on exactly how to solve this issue. For now, files are
filepath = basepath + filename # manually being compiled to DATA_DIR/js/compiled.
timestamp = os.stat(filepath).st_mtime
if timestamp > latestTimestamp: #latestTimestamp = 0
latestTimestamp = timestamp #basepath = self.system.filestore.root_path + '/js/'
#for filename in (self.display_dependencies + [self.display]):
h = hashlib.md5() # filepath = basepath + filename
h.update(self.answer_id + str(self.display_dependencies)) # timestamp = os.stat(filepath).st_mtime
compiled_filename = 'compiled/' + h.hexdigest() + '.js' # if timestamp > latestTimestamp:
compiled_filepath = basepath + compiled_filename # latestTimestamp = timestamp
#
if not os.path.exists(compiled_filepath) or os.stat(compiled_filepath).st_mtime < latestTimestamp: #h = hashlib.md5()
outfile = open(compiled_filepath, 'w') #h.update(self.answer_id + str(self.display_dependencies))
for filename in (self.display_dependencies + [self.display]): #compiled_filename = 'compiled/' + h.hexdigest() + '.js'
filepath = basepath + filename #compiled_filepath = basepath + compiled_filename
infile = open(filepath, 'r')
outfile.write(infile.read()) #if not os.path.exists(compiled_filepath) or os.stat(compiled_filepath).st_mtime < latestTimestamp:
outfile.write(';\n') # outfile = open(compiled_filepath, 'w')
infile.close() # for filename in (self.display_dependencies + [self.display]):
outfile.close() # filepath = basepath + filename
# infile = open(filepath, 'r')
self.display_filename = compiled_filename # outfile.write(infile.read())
# outfile.write(';\n')
# infile.close()
# outfile.close()
# TODO this should also be fixed when the above is fixed.
filename = self.system.ajax_url.split('/')[-1] + '.js'
self.display_filename = 'compiled/' + filename
def parse_xml(self): def parse_xml(self):
self.generator_xml = self.xml.xpath('//*[@id=$id]//generator', self.generator_xml = self.xml.xpath('//*[@id=$id]//generator',
...@@ -385,18 +394,22 @@ class JavascriptResponse(LoncapaResponse): ...@@ -385,18 +394,22 @@ class JavascriptResponse(LoncapaResponse):
tmp_env["NODE_PATH"] = node_path tmp_env["NODE_PATH"] = node_path
return tmp_env return tmp_env
def call_node(self, args):
subprocess_args = ["node"]
subprocess_args.extend(args)
return subprocess.check_output(subprocess_args, env=self.get_node_env())
def generate_problem_state(self): def generate_problem_state(self):
generator_file = os.path.dirname(os.path.normpath(__file__)) + '/javascript_problem_generator.js' generator_file = os.path.dirname(os.path.normpath(__file__)) + '/javascript_problem_generator.js'
output = subprocess.check_output(["node", output = self.call_node([generator_file,
generator_file,
self.generator, self.generator,
json.dumps(self.generator_dependencies), json.dumps(self.generator_dependencies),
json.dumps(str(self.system.seed)), json.dumps(str(self.system.seed)),
json.dumps(self.params) json.dumps(self.params)]).strip()
],
env=self.get_node_env()).strip()
return json.loads(output) return json.loads(output)
...@@ -407,7 +420,8 @@ class JavascriptResponse(LoncapaResponse): ...@@ -407,7 +420,8 @@ class JavascriptResponse(LoncapaResponse):
for param in self.xml.xpath('//*[@id=$id]//responseparam', for param in self.xml.xpath('//*[@id=$id]//responseparam',
id=self.xml.get('id')): id=self.xml.get('id')):
params[param.get("name")] = json.loads(param.get("value")) raw_param = param.get("value")
params[param.get("name")] = json.loads(contextualize_text(raw_param, self.context))
return params return params
...@@ -435,22 +449,23 @@ class JavascriptResponse(LoncapaResponse): ...@@ -435,22 +449,23 @@ class JavascriptResponse(LoncapaResponse):
(all_correct, evaluation, solution) = self.run_grader(json_submission) (all_correct, evaluation, solution) = self.run_grader(json_submission)
self.solution = solution self.solution = solution
correctness = 'correct' if all_correct else 'incorrect' correctness = 'correct' if all_correct else 'incorrect'
return CorrectMap(self.answer_id, correctness, msg=evaluation) if all_correct:
points = self.get_max_score()
else:
points = 0
return CorrectMap(self.answer_id, correctness, npoints=points, msg=evaluation)
def run_grader(self, submission): def run_grader(self, submission):
if submission is None or submission == '': if submission is None or submission == '':
submission = json.dumps(None) submission = json.dumps(None)
grader_file = os.path.dirname(os.path.normpath(__file__)) + '/javascript_problem_grader.js' grader_file = os.path.dirname(os.path.normpath(__file__)) + '/javascript_problem_grader.js'
outputs = subprocess.check_output(["node", outputs = self.call_node([grader_file,
grader_file,
self.grader, self.grader,
json.dumps(self.grader_dependencies), json.dumps(self.grader_dependencies),
submission, submission,
json.dumps(self.problem_state), json.dumps(self.problem_state),
json.dumps(self.params) json.dumps(self.params)]).split('\n')
],
env=self.get_node_env()).split('\n')
all_correct = json.loads(outputs[0].strip()) all_correct = json.loads(outputs[0].strip())
evaluation = outputs[1].strip() evaluation = outputs[1].strip()
...@@ -711,7 +726,8 @@ class NumericalResponse(LoncapaResponse): ...@@ -711,7 +726,8 @@ class NumericalResponse(LoncapaResponse):
# I think this is just pyparsing.ParseException, calc.UndefinedVariable: # I think this is just pyparsing.ParseException, calc.UndefinedVariable:
# But we'd need to confirm # But we'd need to confirm
except: except:
raise StudentInputError('Invalid input -- please use a number only') raise StudentInputError("Invalid input: could not parse '%s' as a number" %\
cgi.escape(student_answer))
if correct: if correct:
return CorrectMap(self.answer_id, 'correct') return CorrectMap(self.answer_id, 'correct')
...@@ -1005,7 +1021,7 @@ class CodeResponse(LoncapaResponse): ...@@ -1005,7 +1021,7 @@ class CodeResponse(LoncapaResponse):
''' '''
Grade student code using an external queueing server, called 'xqueue' Grade student code using an external queueing server, called 'xqueue'
Expects 'xqueue' dict in ModuleSystem with the following keys: Expects 'xqueue' dict in ModuleSystem with the following keys that are needed by CodeResponse:
system.xqueue = { 'interface': XqueueInterface object, system.xqueue = { 'interface': XqueueInterface object,
'callback_url': Per-StudentModule callback URL where results are posted (string), 'callback_url': Per-StudentModule callback URL where results are posted (string),
'default_queuename': Default queuename to submit request (string) 'default_queuename': Default queuename to submit request (string)
...@@ -1026,7 +1042,7 @@ class CodeResponse(LoncapaResponse): ...@@ -1026,7 +1042,7 @@ class CodeResponse(LoncapaResponse):
TODO: Determines whether in synchronous or asynchronous (queued) mode TODO: Determines whether in synchronous or asynchronous (queued) mode
''' '''
xml = self.xml xml = self.xml
self.url = xml.get('url', None) # XML can override external resource (grader/queue) URL self.url = xml.get('url', None) # TODO: XML can override external resource (grader/queue) URL
self.queue_name = xml.get('queuename', self.system.xqueue['default_queuename']) self.queue_name = xml.get('queuename', self.system.xqueue['default_queuename'])
# VS[compat]: # VS[compat]:
...@@ -1121,22 +1137,34 @@ class CodeResponse(LoncapaResponse): ...@@ -1121,22 +1137,34 @@ class CodeResponse(LoncapaResponse):
# Prepare xqueue request # Prepare xqueue request
#------------------------------------------------------------ #------------------------------------------------------------
qinterface = self.system.xqueue['interface'] qinterface = self.system.xqueue['interface']
qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat)
anonymous_student_id = self.system.anonymous_student_id
# Generate header # Generate header
queuekey = xqueue_interface.make_hashkey(str(self.system.seed)+self.answer_id) queuekey = xqueue_interface.make_hashkey(str(self.system.seed) + qtime +
anonymous_student_id +
self.answer_id)
xheader = xqueue_interface.make_xheader(lms_callback_url=self.system.xqueue['callback_url'], xheader = xqueue_interface.make_xheader(lms_callback_url=self.system.xqueue['callback_url'],
lms_key=queuekey, lms_key=queuekey,
queue_name=self.queue_name) queue_name=self.queue_name)
# Generate body # Generate body
if is_list_of_files(submission): if is_list_of_files(submission):
self.context.update({'submission': queuekey}) # For tracking. TODO: May want to record something else here self.context.update({'submission': ''}) # TODO: Get S3 pointer from the Queue
else: else:
self.context.update({'submission': submission}) self.context.update({'submission': submission})
contents = self.payload.copy() contents = self.payload.copy()
# Metadata related to the student submission revealed to the external grader
student_info = {'anonymous_student_id': anonymous_student_id,
'submission_time': qtime,
}
contents.update({'student_info': json.dumps(student_info)})
# Submit request. When successful, 'msg' is the prior length of the queue # Submit request. When successful, 'msg' is the prior length of the queue
if is_list_of_files(submission): if is_list_of_files(submission):
contents.update({'student_response': ''}) # TODO: Is there any information we want to send here? contents.update({'student_response': ''}) # TODO: Is there any information we want to send here?
...@@ -1148,16 +1176,21 @@ class CodeResponse(LoncapaResponse): ...@@ -1148,16 +1176,21 @@ class CodeResponse(LoncapaResponse):
(error, msg) = qinterface.send_to_queue(header=xheader, (error, msg) = qinterface.send_to_queue(header=xheader,
body=json.dumps(contents)) body=json.dumps(contents))
# State associated with the queueing request
queuestate = {'key': queuekey,
'time': qtime,
}
cmap = CorrectMap() cmap = CorrectMap()
if error: if error:
cmap.set(self.answer_id, queuekey=None, cmap.set(self.answer_id, queuestate=None,
msg='Unable to deliver your submission to grader. (Reason: %s.) Please try again later.' % msg) msg='Unable to deliver your submission to grader. (Reason: %s.) Please try again later.' % msg)
else: else:
# Queueing mechanism flags: # Queueing mechanism flags:
# 1) Backend: Non-null CorrectMap['queuekey'] indicates that the problem has been queued # 1) Backend: Non-null CorrectMap['queuestate'] indicates that the problem has been queued
# 2) Frontend: correctness='incomplete' eventually trickles down through inputtypes.textbox # 2) Frontend: correctness='incomplete' eventually trickles down through inputtypes.textbox
# and .filesubmission to inform the browser to poll the LMS # and .filesubmission to inform the browser to poll the LMS
cmap.set(self.answer_id, queuekey=queuekey, correctness='incomplete', msg=msg) cmap.set(self.answer_id, queuestate=queuestate, correctness='incomplete', msg=msg)
return cmap return cmap
...@@ -1165,7 +1198,7 @@ class CodeResponse(LoncapaResponse): ...@@ -1165,7 +1198,7 @@ class CodeResponse(LoncapaResponse):
(valid_score_msg, correct, points, msg) = self._parse_score_msg(score_msg) (valid_score_msg, correct, points, msg) = self._parse_score_msg(score_msg)
if not valid_score_msg: if not valid_score_msg:
oldcmap.set(self.answer_id, msg='Error: Invalid grader reply.') oldcmap.set(self.answer_id, msg='Invalid grader reply. Please contact the course staff.')
return oldcmap return oldcmap
correctness = 'correct' if correct else 'incorrect' correctness = 'correct' if correct else 'incorrect'
...@@ -1180,7 +1213,7 @@ class CodeResponse(LoncapaResponse): ...@@ -1180,7 +1213,7 @@ class CodeResponse(LoncapaResponse):
points = 0 points = 0
elif points > self.maxpoints[self.answer_id]: elif points > self.maxpoints[self.answer_id]:
points = self.maxpoints[self.answer_id] points = self.maxpoints[self.answer_id]
oldcmap.set(self.answer_id, npoints=points, correctness=correctness, msg=msg.replace('&nbsp;', '&#160;'), queuekey=None) # Queuekey is consumed oldcmap.set(self.answer_id, npoints=points, correctness=correctness, msg=msg.replace('&nbsp;', '&#160;'), queuestate=None) # Queuestate is consumed
else: else:
log.debug('CodeResponse: queuekey %s does not match for answer_id=%s.' % (queuekey, self.answer_id)) log.debug('CodeResponse: queuekey %s does not match for answer_id=%s.' % (queuekey, self.answer_id))
...@@ -1197,26 +1230,41 @@ class CodeResponse(LoncapaResponse): ...@@ -1197,26 +1230,41 @@ class CodeResponse(LoncapaResponse):
''' '''
Grader reply is a JSON-dump of the following dict Grader reply is a JSON-dump of the following dict
{ 'correct': True/False, { 'correct': True/False,
'score': # TODO -- Partial grading 'score': Numeric value (floating point is okay) to assign to answer
'msg': grader_msg } 'msg': grader_msg }
Returns (valid_score_msg, correct, score, msg): Returns (valid_score_msg, correct, score, msg):
valid_score_msg: Flag indicating valid score_msg format (Boolean) valid_score_msg: Flag indicating valid score_msg format (Boolean)
correct: Correctness of submission (Boolean) correct: Correctness of submission (Boolean)
score: # TODO: Implement partial grading score: Points to be assigned (numeric, can be float)
msg: Message from grader to display to student (string) msg: Message from grader to display to student (string)
''' '''
fail = (False, False, -1, '') fail = (False, False, 0, '')
try: try:
score_result = json.loads(score_msg) score_result = json.loads(score_msg)
except (TypeError, ValueError): except (TypeError, ValueError):
log.error("External grader message should be a JSON-serialized dict. Received score_msg = %s" % score_msg)
return fail return fail
if not isinstance(score_result, dict): if not isinstance(score_result, dict):
log.error("External grader message should be a JSON-serialized dict. Received score_result = %s" % score_result)
return fail return fail
for tag in ['correct', 'score', 'msg']: for tag in ['correct', 'score', 'msg']:
if not score_result.has_key(tag): if tag not in score_result:
log.error("External grader message is missing one or more required tags: 'correct', 'score', 'msg'")
return fail return fail
return (True, score_result['correct'], score_result['score'], score_result['msg'])
# Next, we need to check that the contents of the external grader message
# is safe for the LMS.
# 1) Make sure that the message is valid XML (proper opening/closing tags)
# 2) TODO: Is the message actually HTML?
msg = score_result['msg']
try:
etree.fromstring(msg)
except etree.XMLSyntaxError as err:
log.error("Unable to parse external grader message as valid XML: score_msg['msg']=%s" % msg)
return fail
return (True, score_result['correct'], score_result['score'], msg)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
...@@ -1471,11 +1519,12 @@ class FormulaResponse(LoncapaResponse): ...@@ -1471,11 +1519,12 @@ class FormulaResponse(LoncapaResponse):
cs=self.case_sensitive) cs=self.case_sensitive)
except UndefinedVariable as uv: except UndefinedVariable as uv:
log.debug('formularesponse: undefined variable in given=%s' % given) log.debug('formularesponse: undefined variable in given=%s' % given)
raise StudentInputError(uv.message + " not permitted in answer") raise StudentInputError("Invalid input: " + uv.message + " not permitted in answer")
except Exception as err: except Exception as err:
#traceback.print_exc() #traceback.print_exc()
log.debug('formularesponse: error %s in formula' % err) log.debug('formularesponse: error %s in formula' % err)
raise StudentInputError("Error in formula") raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %\
cgi.escape(given))
if numpy.isnan(student_result) or numpy.isinf(student_result): if numpy.isnan(student_result) or numpy.isinf(student_result):
return "incorrect" return "incorrect"
if not compare_with_tolerance(student_result, instructor_result, self.tolerance): if not compare_with_tolerance(student_result, instructor_result, self.tolerance):
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<span class="processing" id="status_${id}"></span> <span class="processing" id="status_${id}"></span>
<span style="display:none;" class="xqueue" id="${id}" >${queue_len}</span> <span style="display:none;" class="xqueue" id="${id}" >${queue_len}</span>
% endif % endif
<span class="debug">(${state})</span> <span style="display:none;" class="debug">(${state})</span>
<br/> <br/>
<span class="message">${msg|n}</span> <span class="message">${msg|n}</span>
<br/> <br/>
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<div style="display:none;" name="${hidden}" inputid="input_${id}" /> <div style="display:none;" name="${hidden}" inputid="input_${id}" />
% endif % endif
<br/> <br/>
<span class="debug">(${state})</span> <span style="display:none;" class="debug">(${state})</span>
<br/> <br/>
<span class="message">${msg|n}</span> <span class="message">${msg|n}</span>
<br/> <br/>
......
...@@ -5,20 +5,17 @@ import hashlib ...@@ -5,20 +5,17 @@ import hashlib
import json import json
import logging import logging
import requests import requests
import time
log = logging.getLogger('mitx.' + __name__) log = logging.getLogger('mitx.' + __name__)
dateformat = '%Y%m%d%H%M%S'
def make_hashkey(seed):
def make_hashkey(seed=None):
''' '''
Generate a string key by hashing Generate a string key by hashing
''' '''
h = hashlib.md5() h = hashlib.md5()
if seed is not None:
h.update(str(seed)) h.update(str(seed))
h.update(str(time.time()))
return h.hexdigest() return h.hexdigest()
......
...@@ -462,6 +462,15 @@ class CapaModule(XModule): ...@@ -462,6 +462,15 @@ class CapaModule(XModule):
self.system.track_function('save_problem_check_fail', event_info) self.system.track_function('save_problem_check_fail', event_info)
raise NotFoundError('Problem must be reset before it can be checked again') raise NotFoundError('Problem must be reset before it can be checked again')
# Problem queued. Students must wait a specified waittime before they are allowed to submit
if self.lcp.is_queued():
current_time = datetime.datetime.now()
prev_submit_time = self.lcp.get_recentmost_queuetime()
waittime_between_requests = self.system.xqueue['waittime']
if (current_time-prev_submit_time).total_seconds() < waittime_between_requests:
msg = 'You must wait at least %d seconds between submissions' % waittime_between_requests
return {'success': msg, 'html': ''} # Prompts a modal dialog in ajax callback
try: try:
old_state = self.lcp.get_state() old_state = self.lcp.get_state()
lcp_id = self.lcp.problem_id lcp_id = self.lcp.problem_id
......
from lxml import etree from lxml import etree
from pkg_resources import resource_string, resource_listdir
from xmodule.x_module import XModule from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor from xmodule.raw_module import RawDescriptor
...@@ -6,6 +7,11 @@ from xmodule.raw_module import RawDescriptor ...@@ -6,6 +7,11 @@ from xmodule.raw_module import RawDescriptor
import json import json
class DiscussionModule(XModule): class DiscussionModule(XModule):
js = {'coffee':
[resource_string(__name__, 'js/src/time.coffee'),
resource_string(__name__, 'js/src/discussion/display.coffee')]
}
js_module_name = "InlineDiscussion"
def get_html(self): def get_html(self):
context = { context = {
'discussion_id': self.discussion_id, 'discussion_id': self.discussion_id,
......
...@@ -4,9 +4,10 @@ import logging ...@@ -4,9 +4,10 @@ import logging
import os import os
import sys import sys
from lxml import etree from lxml import etree
from path import path
from .x_module import XModule from .x_module import XModule
from .xml_module import XmlDescriptor from .xml_module import XmlDescriptor, name_to_pathname
from .editing_module import EditingDescriptor from .editing_module import EditingDescriptor
from .stringify import stringify_children from .stringify import stringify_children
from .html_checker import check_html from .html_checker import check_html
...@@ -75,9 +76,19 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): ...@@ -75,9 +76,19 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor):
cls.clean_metadata_from_xml(definition_xml) cls.clean_metadata_from_xml(definition_xml)
return {'data': stringify_children(definition_xml)} return {'data': stringify_children(definition_xml)}
else: else:
# html is special. cls.filename_extension is 'xml', but if 'filename' is in the definition, # html is special. cls.filename_extension is 'xml', but
# that means to load from .html # if 'filename' is in the definition, that means to load
filepath = "{category}/{name}.html".format(category='html', name=filename) # from .html
# 'filename' in html pointers is a relative path
# (not same as 'html/blah.html' when the pointer is in a directory itself)
pointer_path = "{category}/{url_path}".format(category='html',
url_path=name_to_pathname(location.name))
base = path(pointer_path).dirname()
#log.debug("base = {0}, base.dirname={1}, filename={2}".format(base, base.dirname(), filename))
filepath = "{base}/{name}.html".format(base=base, name=filename)
#log.debug("looking for html file for {0} at {1}".format(location, filepath))
# VS[compat] # VS[compat]
# TODO (cpennington): If the file doesn't exist at the right path, # TODO (cpennington): If the file doesn't exist at the right path,
...@@ -128,13 +139,18 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): ...@@ -128,13 +139,18 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor):
pass pass
# Not proper format. Write html to file, return an empty tag # Not proper format. Write html to file, return an empty tag
filepath = u'{category}/{name}.html'.format(category=self.category, pathname = name_to_pathname(self.url_name)
name=self.url_name) pathdir = path(pathname).dirname()
filepath = u'{category}/{pathname}.html'.format(category=self.category,
pathname=pathname)
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(self.definition['data']) file.write(self.definition['data'])
# write out the relative name
relname = path(pathname).basename()
elt = etree.Element('html') elt = etree.Element('html')
elt.set("filename", self.url_name) elt.set("filename", relname)
return elt return elt
...@@ -192,8 +192,11 @@ class @Problem ...@@ -192,8 +192,11 @@ class @Problem
if file_not_selected if file_not_selected
errors.push 'You did not select any files to submit' errors.push 'You did not select any files to submit'
if errors.length > 0 error_html = '<ul>\n'
alert errors.join("\n") for error in errors
error_html += '<li>' + error + '</li>\n'
error_html += '</ul>'
@gentle_alert error_html
abort_submission = file_too_large or file_not_selected or unallowed_file_submitted or required_files_not_submitted abort_submission = file_too_large or file_not_selected or unallowed_file_submitted or required_files_not_submitted
...@@ -208,7 +211,7 @@ class @Problem ...@@ -208,7 +211,7 @@ class @Problem
@render(response.contents) @render(response.contents)
@updateProgress response @updateProgress response
else else
alert(response.success) @gentle_alert response.success
if not abort_submission if not abort_submission
$.ajaxWithPrefix("#{@url}/problem_check", settings) $.ajaxWithPrefix("#{@url}/problem_check", settings)
...@@ -220,8 +223,10 @@ class @Problem ...@@ -220,8 +223,10 @@ class @Problem
when 'incorrect', 'correct' when 'incorrect', 'correct'
@render(response.contents) @render(response.contents)
@updateProgress response @updateProgress response
if @el.hasClass 'showed'
@el.removeClass 'showed'
else else
alert(response.success) @gentle_alert response.success
reset: => reset: =>
Logger.log 'problem_reset', @answers Logger.log 'problem_reset', @answers
...@@ -253,11 +258,19 @@ class @Problem ...@@ -253,11 +258,19 @@ class @Problem
@el.removeClass 'showed' @el.removeClass 'showed'
@$('.show').val 'Show Answer' @$('.show').val 'Show Answer'
gentle_alert: (msg) =>
if @el.find('.capa_alert').length
@el.find('.capa_alert').remove()
alert_elem = "<div class='capa_alert'>" + msg + "</div>"
@el.find('.action').after(alert_elem)
@el.find('.capa_alert').animate(opacity: 0, 500).animate(opacity: 1, 500)
save: => save: =>
Logger.log 'problem_save', @answers Logger.log 'problem_save', @answers
$.postWithPrefix "#{@url}/problem_save", @answers, (response) => $.postWithPrefix "#{@url}/problem_save", @answers, (response) =>
if response.success if response.success
alert 'Saved' saveMessage = "Your answers have been saved but not graded. Hit 'Check' to grade them."
@gentle_alert saveMessage
@updateProgress response @updateProgress response
refreshMath: (event, element) => refreshMath: (event, element) =>
...@@ -293,6 +306,9 @@ class @Problem ...@@ -293,6 +306,9 @@ class @Problem
problemState = data.data("problem_state") problemState = data.data("problem_state")
displayClass = window[data.data('display_class')] displayClass = window[data.data('display_class')]
if evaluation == ''
evaluation = null
container = $(element).find(".javascriptinput_container") container = $(element).find(".javascriptinput_container")
submissionField = $(element).find(".javascriptinput_input") submissionField = $(element).find(".javascriptinput_input")
......
class @InlineDiscussion
constructor: (element) ->
@el = $(element).find('.discussion-module')
@view = new DiscussionModuleView(el: @el)
...@@ -2,6 +2,7 @@ class @Sequence ...@@ -2,6 +2,7 @@ class @Sequence
constructor: (element) -> constructor: (element) ->
@el = $(element).find('.sequence') @el = $(element).find('.sequence')
@contents = @$('.seq_contents') @contents = @$('.seq_contents')
@num_contents = @contents.length
@id = @el.data('id') @id = @el.data('id')
@modx_url = @el.data('course_modx_root') @modx_url = @el.data('course_modx_root')
@initProgress() @initProgress()
...@@ -90,9 +91,17 @@ class @Sequence ...@@ -90,9 +91,17 @@ class @Sequence
@toggleArrows() @toggleArrows()
@hookUpProgressEvent() @hookUpProgressEvent()
sequence_links = @$('#seq_content a.seqnav')
sequence_links.click @goto
goto: (event) => goto: (event) =>
event.preventDefault() event.preventDefault()
if $(event.target).hasClass 'seqnav' # Links from courseware <a class='seqnav' href='n'>...</a>
new_position = $(event.target).attr('href')
else # Tab links generated by backend template
new_position = $(event.target).data('element') new_position = $(event.target).data('element')
if (1 <= new_position) and (new_position <= @num_contents)
Logger.log "seq_goto", old: @position, new: new_position, id: @id Logger.log "seq_goto", old: @position, new: new_position, id: @id
# On Sequence chage, destroy any existing polling thread # On Sequence chage, destroy any existing polling thread
...@@ -102,6 +111,8 @@ class @Sequence ...@@ -102,6 +111,8 @@ class @Sequence
delete window.queuePollerID delete window.queuePollerID
@render new_position @render new_position
else
alert 'Sequence error! Cannot navigate to tab ' + new_position + 'in the current SequenceModule. Please contact the course staff.'
next: (event) => next: (event) =>
event.preventDefault() event.preventDefault()
......
...@@ -3,6 +3,7 @@ class @Video ...@@ -3,6 +3,7 @@ class @Video
@el = $(element).find('.video') @el = $(element).find('.video')
@id = @el.attr('id').replace(/video_/, '') @id = @el.attr('id').replace(/video_/, '')
@caption_data_dir = @el.data('caption-data-dir') @caption_data_dir = @el.data('caption-data-dir')
@show_captions = @el.data('show-captions') == "true"
window.player = null window.player = null
@el = $("#video_#{@id}") @el = $("#video_#{@id}")
@parseVideos @el.data('streams') @parseVideos @el.data('streams')
......
class @VideoCaption extends Subview class @VideoCaption extends Subview
initialize: ->
@loaded = false
bind: -> bind: ->
$(window).bind('resize', @resize) $(window).bind('resize', @resize)
@$('.hide-subtitles').click @toggle @$('.hide-subtitles').click @toggle
...@@ -10,8 +13,12 @@ class @VideoCaption extends Subview ...@@ -10,8 +13,12 @@ class @VideoCaption extends Subview
"/static/#{@captionDataDir}/subs/#{@youtubeId}.srt.sjson" "/static/#{@captionDataDir}/subs/#{@youtubeId}.srt.sjson"
render: -> render: ->
# TODO: make it so you can have a video with no captions.
#@$('.video-wrapper').after """
# <ol class="subtitles"><li>Attempting to load captions...</li></ol>
# """
@$('.video-wrapper').after """ @$('.video-wrapper').after """
<ol class="subtitles"><li>Attempting to load captions...</li></ol> <ol class="subtitles"></ol>
""" """
@$('.video-controls .secondary-controls').append """ @$('.video-controls .secondary-controls').append """
<a href="#" class="hide-subtitles" title="Turn off captions">Captions</a> <a href="#" class="hide-subtitles" title="Turn off captions">Captions</a>
...@@ -24,6 +31,8 @@ class @VideoCaption extends Subview ...@@ -24,6 +31,8 @@ class @VideoCaption extends Subview
@captions = captions.text @captions = captions.text
@start = captions.start @start = captions.start
@loaded = true
if onTouchBasedDevice() if onTouchBasedDevice()
$('.subtitles li').html "Caption will be displayed when you start playing the video." $('.subtitles li').html "Caption will be displayed when you start playing the video."
else else
...@@ -47,6 +56,7 @@ class @VideoCaption extends Subview ...@@ -47,6 +56,7 @@ class @VideoCaption extends Subview
@rendered = true @rendered = true
search: (time) -> search: (time) ->
if @loaded
min = 0 min = 0
max = @start.length - 1 max = @start.length - 1
...@@ -56,17 +66,19 @@ class @VideoCaption extends Subview ...@@ -56,17 +66,19 @@ class @VideoCaption extends Subview
max = index - 1 max = index - 1
if time >= @start[index] if time >= @start[index]
min = index min = index
return min return min
play: -> play: ->
if @loaded
@renderCaption() unless @rendered @renderCaption() unless @rendered
@playing = true @playing = true
pause: -> pause: ->
if @loaded
@playing = false @playing = false
updatePlayTime: (time) -> updatePlayTime: (time) ->
if @loaded
# This 250ms offset is required to match the video speed # This 250ms offset is required to match the video speed
time = Math.round(Time.convert(time, @currentSpeed, '1.0') * 1000 + 250) time = Math.round(Time.convert(time, @currentSpeed, '1.0') * 1000 + 250)
newIndex = @search time newIndex = @search time
......
...@@ -13,18 +13,21 @@ from xmodule.errortracker import ErrorLog, make_error_tracker ...@@ -13,18 +13,21 @@ from xmodule.errortracker import ErrorLog, make_error_tracker
log = logging.getLogger('mitx.' + 'modulestore') log = logging.getLogger('mitx.' + 'modulestore')
URL_RE = re.compile(""" URL_RE = re.compile("""
(?P<tag>[^:]+):// (?P<tag>[^:]+)://
(?P<org>[^/]+)/ (?P<org>[^/]+)/
(?P<course>[^/]+)/ (?P<course>[^/]+)/
(?P<category>[^/]+)/ (?P<category>[^/]+)/
(?P<name>[^/]+) (?P<name>[^@]+)
(/(?P<revision>[^/]+))? (@(?P<revision>[^/]+))?
""", re.VERBOSE) """, re.VERBOSE)
# TODO (cpennington): We should decide whether we want to expand the # TODO (cpennington): We should decide whether we want to expand the
# list of valid characters in a location # list of valid characters in a location
INVALID_CHARS = re.compile(r"[^\w.-]") INVALID_CHARS = re.compile(r"[^\w.-]")
# Names are allowed to have colons.
INVALID_CHARS_NAME = re.compile(r"[^\w.:-]")
_LocationBase = namedtuple('LocationBase', 'tag org course category name revision') _LocationBase = namedtuple('LocationBase', 'tag org course category name revision')
...@@ -34,7 +37,7 @@ class Location(_LocationBase): ...@@ -34,7 +37,7 @@ class Location(_LocationBase):
Encodes a location. Encodes a location.
Locations representations of URLs of the Locations representations of URLs of the
form {tag}://{org}/{course}/{category}/{name}[/{revision}] form {tag}://{org}/{course}/{category}/{name}[@{revision}]
However, they can also be represented a dictionaries (specifying each component), However, they can also be represented a dictionaries (specifying each component),
tuples or list (specified in order), or as strings of the url tuples or list (specified in order), or as strings of the url
...@@ -81,7 +84,7 @@ class Location(_LocationBase): ...@@ -81,7 +84,7 @@ class Location(_LocationBase):
location - Can be any of the following types: location - Can be any of the following types:
string: should be of the form string: should be of the form
{tag}://{org}/{course}/{category}/{name}[/{revision}] {tag}://{org}/{course}/{category}/{name}[@{revision}]
list: should be of the form [tag, org, course, category, name, revision] list: should be of the form [tag, org, course, category, name, revision]
...@@ -99,10 +102,11 @@ class Location(_LocationBase): ...@@ -99,10 +102,11 @@ class Location(_LocationBase):
ommitted. ommitted.
Components must be composed of alphanumeric characters, or the Components must be composed of alphanumeric characters, or the
characters '_', '-', and '.' characters '_', '-', and '.'. The name component is additionally allowed to have ':',
which is interpreted specially for xml storage.
Components may be set to None, which may be interpreted by some contexts Components may be set to None, which may be interpreted in some contexts
to mean wildcard selection to mean wildcard selection.
""" """
...@@ -116,14 +120,23 @@ class Location(_LocationBase): ...@@ -116,14 +120,23 @@ class Location(_LocationBase):
return _LocationBase.__new__(_cls, *([None] * 6)) return _LocationBase.__new__(_cls, *([None] * 6))
def check_dict(dict_): def check_dict(dict_):
check_list(dict_.itervalues()) # Order matters, so flatten out into a list
keys = ['tag', 'org', 'course', 'category', 'name', 'revision']
list_ = [dict_[k] for k in keys]
check_list(list_)
def check_list(list_): def check_list(list_):
for val in list_: def check(val, regexp):
if val is not None and INVALID_CHARS.search(val) is not None: if val is not None and regexp.search(val) is not None:
log.debug('invalid characters val="%s", list_="%s"' % (val, list_)) log.debug('invalid characters val="%s", list_="%s"' % (val, list_))
raise InvalidLocationError(location) raise InvalidLocationError(location)
list_ = list(list_)
for val in list_[:4] + [list_[5]]:
check(val, INVALID_CHARS)
# names allow colons
check(list_[4], INVALID_CHARS_NAME)
if isinstance(location, basestring): if isinstance(location, basestring):
match = URL_RE.match(location) match = URL_RE.match(location)
if match is None: if match is None:
...@@ -162,7 +175,7 @@ class Location(_LocationBase): ...@@ -162,7 +175,7 @@ class Location(_LocationBase):
""" """
url = "{tag}://{org}/{course}/{category}/{name}".format(**self.dict()) url = "{tag}://{org}/{course}/{category}/{name}".format(**self.dict())
if self.revision: if self.revision:
url += "/" + self.revision url += "@" + self.revision
return url return url
def html_id(self): def html_id(self):
...@@ -170,6 +183,7 @@ class Location(_LocationBase): ...@@ -170,6 +183,7 @@ class Location(_LocationBase):
Return a string with a version of the location that is safe for use in Return a string with a version of the location that is safe for use in
html id attributes html id attributes
""" """
# TODO: is ':' ok in html ids?
return "-".join(str(v) for v in self.list() return "-".join(str(v) for v in self.list()
if v is not None).replace('.', '_') if v is not None).replace('.', '_')
......
...@@ -5,8 +5,8 @@ Passes settings.MODULESTORE as kwargs to MongoModuleStore ...@@ -5,8 +5,8 @@ Passes settings.MODULESTORE as kwargs to MongoModuleStore
""" """
from __future__ import absolute_import from __future__ import absolute_import
from importlib import import_module from importlib import import_module
from os import environ
from django.conf import settings from django.conf import settings
...@@ -43,3 +43,8 @@ def modulestore(name='default'): ...@@ -43,3 +43,8 @@ def modulestore(name='default'):
) )
return _MODULESTORES[name] return _MODULESTORES[name]
# if 'DJANGO_SETTINGS_MODULE' in environ:
# # Initialize the modulestores immediately
# for store_name in settings.MODULESTORE:
# modulestore(store_name)
...@@ -10,7 +10,7 @@ def check_string_roundtrip(url): ...@@ -10,7 +10,7 @@ def check_string_roundtrip(url):
def test_string_roundtrip(): def test_string_roundtrip():
check_string_roundtrip("tag://org/course/category/name") check_string_roundtrip("tag://org/course/category/name")
check_string_roundtrip("tag://org/course/category/name/revision") check_string_roundtrip("tag://org/course/category/name@revision")
input_dict = { input_dict = {
...@@ -21,18 +21,28 @@ input_dict = { ...@@ -21,18 +21,28 @@ input_dict = {
'org': 'org' 'org': 'org'
} }
also_valid_dict = {
'tag': 'tag',
'course': 'course',
'category': 'category',
'name': 'name:more_name',
'org': 'org'
}
input_list = ['tag', 'org', 'course', 'category', 'name'] input_list = ['tag', 'org', 'course', 'category', 'name']
input_str = "tag://org/course/category/name" input_str = "tag://org/course/category/name"
input_str_rev = "tag://org/course/category/name/revision" input_str_rev = "tag://org/course/category/name@revision"
valid = (input_list, input_dict, input_str, input_str_rev) valid = (input_list, input_dict, input_str, input_str_rev, also_valid_dict)
invalid_dict = { invalid_dict = {
'tag': 'tag', 'tag': 'tag',
'course': 'course', 'course': 'course',
'category': 'category', 'category': 'category',
'name': 'name/more_name', 'name': 'name@more_name',
'org': 'org' 'org': 'org'
} }
...@@ -45,8 +55,9 @@ invalid_dict2 = { ...@@ -45,8 +55,9 @@ invalid_dict2 = {
} }
invalid = ("foo", ["foo"], ["foo", "bar"], invalid = ("foo", ["foo"], ["foo", "bar"],
["foo", "bar", "baz", "blat", "foo/bar"], ["foo", "bar", "baz", "blat:blat", "foo:bar"], # ':' ok in name, not in category
"tag://org/course/category/name with spaces/revision", "tag://org/course/category/name with spaces@revision",
"tag://org/course/category/name/with/slashes@revision",
invalid_dict, invalid_dict,
invalid_dict2) invalid_dict2)
...@@ -62,16 +73,15 @@ def test_dict(): ...@@ -62,16 +73,15 @@ def test_dict():
assert_equals(dict(revision=None, **input_dict), Location(input_dict).dict()) assert_equals(dict(revision=None, **input_dict), Location(input_dict).dict())
input_dict['revision'] = 'revision' input_dict['revision'] = 'revision'
assert_equals("tag://org/course/category/name/revision", Location(input_dict).url()) assert_equals("tag://org/course/category/name@revision", Location(input_dict).url())
assert_equals(input_dict, Location(input_dict).dict()) assert_equals(input_dict, Location(input_dict).dict())
def test_list(): def test_list():
assert_equals("tag://org/course/category/name", Location(input_list).url()) assert_equals("tag://org/course/category/name", Location(input_list).url())
assert_equals(input_list + [None], Location(input_list).list()) assert_equals(input_list + [None], Location(input_list).list())
input_list.append('revision') input_list.append('revision')
assert_equals("tag://org/course/category/name/revision", Location(input_list).url()) assert_equals("tag://org/course/category/name@revision", Location(input_list).url())
assert_equals(input_list, Location(input_list).list()) assert_equals(input_list, Location(input_list).list())
...@@ -87,8 +97,10 @@ def test_none(): ...@@ -87,8 +97,10 @@ def test_none():
def test_invalid_locations(): def test_invalid_locations():
assert_raises(InvalidLocationError, Location, "foo") assert_raises(InvalidLocationError, Location, "foo")
assert_raises(InvalidLocationError, Location, ["foo", "bar"]) assert_raises(InvalidLocationError, Location, ["foo", "bar"])
assert_raises(InvalidLocationError, Location, ["foo", "bar", "baz", "blat/blat", "foo"])
assert_raises(InvalidLocationError, Location, ["foo", "bar", "baz", "blat", "foo/bar"]) assert_raises(InvalidLocationError, Location, ["foo", "bar", "baz", "blat", "foo/bar"])
assert_raises(InvalidLocationError, Location, "tag://org/course/category/name with spaces/revision") assert_raises(InvalidLocationError, Location, "tag://org/course/category/name with spaces@revision")
assert_raises(InvalidLocationError, Location, "tag://org/course/category/name/revision")
def test_equality(): def test_equality():
......
import hashlib
import json import json
import logging import logging
import os import os
...@@ -43,14 +44,76 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem): ...@@ -43,14 +44,76 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
xmlstore: the XMLModuleStore to store the loaded modules in xmlstore: the XMLModuleStore to store the loaded modules in
""" """
self.unnamed_modules = 0 self.unnamed = defaultdict(int) # category -> num of new url_names for that category
self.used_slugs = set() self.used_names = defaultdict(set) # category -> set of used url_names
self.org, self.course, self.url_name = course_id.split('/') self.org, self.course, self.url_name = course_id.split('/')
def process_xml(xml): def process_xml(xml):
"""Takes an xml string, and returns a XModuleDescriptor created from """Takes an xml string, and returns a XModuleDescriptor created from
that xml. that xml.
""" """
def make_name_unique(xml_data):
"""
Make sure that the url_name of xml_data is unique. If a previously loaded
unnamed descriptor stole this element's url_name, create a new one.
Removes 'slug' attribute if present, and adds or overwrites the 'url_name' attribute.
"""
# VS[compat]. Take this out once course conversion is done (perhaps leave the uniqueness check)
attr = xml_data.attrib
tag = xml_data.tag
id = lambda x: x
# Things to try to get a name, in order (key, cleaning function, remove key after reading?)
lookups = [('url_name', id, False),
('slug', id, True),
('name', Location.clean, False),
('display_name', Location.clean, False)]
url_name = None
for key, clean, remove in lookups:
if key in attr:
url_name = clean(attr[key])
if remove:
del attr[key]
break
def fallback_name():
"""Return the fallback name for this module. This is a function instead of a variable
because we want it to be lazy."""
# use the hash of the content--the first 12 bytes should be plenty.
return tag + "_" + hashlib.sha1(xml).hexdigest()[:12]
# Fallback if there was nothing we could use:
if url_name is None or url_name == "":
url_name = fallback_name()
# Don't log a warning--we don't need this in the log. Do
# put it in the error tracker--content folks need to see it.
need_uniq_names = ('problem', 'sequence', 'video', 'course', 'chapter')
if tag in need_uniq_names:
error_tracker("ERROR: no name of any kind specified for {tag}. Student "
"state won't work right. Problem xml: '{xml}...'".format(tag=tag, xml=xml[:100]))
else:
# TODO (vshnayder): We may want to enable this once course repos are cleaned up.
# (or we may want to give up on the requirement for non-state-relevant issues...)
#error_tracker("WARNING: no name specified for module. xml='{0}...'".format(xml[:100]))
pass
# Make sure everything is unique
if url_name in self.used_names[tag]:
msg = ("Non-unique url_name in xml. This may break content. url_name={0}. Content={1}"
.format(url_name, xml[:100]))
error_tracker("ERROR: " + msg)
log.warning(msg)
# Just set name to fallback_name--if there are multiple things with the same fallback name,
# they are actually identical, so it's fragile, but not immediately broken.
url_name = fallback_name()
self.used_names[tag].add(url_name)
xml_data.set('url_name', url_name)
try: try:
# VS[compat] # VS[compat]
# TODO (cpennington): Remove this once all fall 2012 courses # TODO (cpennington): Remove this once all fall 2012 courses
...@@ -62,32 +125,11 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem): ...@@ -62,32 +125,11 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
err=str(err), xml=xml)) err=str(err), xml=xml))
raise raise
# VS[compat]. Take this out once course conversion is done make_name_unique(xml_data)
if xml_data.get('slug') is None and xml_data.get('url_name') is None:
if xml_data.get('name'):
slug = Location.clean(xml_data.get('name'))
elif xml_data.get('display_name'):
slug = Location.clean(xml_data.get('display_name'))
else:
self.unnamed_modules += 1
slug = '{tag}_{count}'.format(tag=xml_data.tag,
count=self.unnamed_modules)
while slug in self.used_slugs:
self.unnamed_modules += 1
slug = '{slug}_{count}'.format(slug=slug,
count=self.unnamed_modules)
self.used_slugs.add(slug)
# log.debug('-> slug=%s' % slug)
xml_data.set('url_name', slug)
descriptor = XModuleDescriptor.load_from_xml( descriptor = XModuleDescriptor.load_from_xml(
etree.tostring(xml_data), self, self.org, etree.tostring(xml_data), self, self.org,
self.course, xmlstore.default_class) self.course, xmlstore.default_class)
#log.debug('==> importing descriptor location %s' %
# repr(descriptor.location))
descriptor.metadata['data_dir'] = course_dir descriptor.metadata['data_dir'] = course_dir
xmlstore.modules[course_id][descriptor.location] = descriptor xmlstore.modules[course_id][descriptor.location] = descriptor
......
...@@ -19,6 +19,8 @@ import capa.calc as calc ...@@ -19,6 +19,8 @@ import capa.calc as calc
import capa.capa_problem as lcp import capa.capa_problem as lcp
from capa.correctmap import CorrectMap from capa.correctmap import CorrectMap
from capa.util import convert_files_to_filenames from capa.util import convert_files_to_filenames
from capa.xqueue_interface import dateformat
from datetime import datetime
from xmodule import graders, x_module from xmodule import graders, x_module
from xmodule.x_module import ModuleSystem from xmodule.x_module import ModuleSystem
from xmodule.graders import Score, aggregate_scores from xmodule.graders import Score, aggregate_scores
...@@ -35,8 +37,9 @@ i4xs = ModuleSystem( ...@@ -35,8 +37,9 @@ i4xs = ModuleSystem(
user=Mock(), user=Mock(),
filestore=fs.osfs.OSFS(os.path.dirname(os.path.realpath(__file__))+"/test_files"), filestore=fs.osfs.OSFS(os.path.dirname(os.path.realpath(__file__))+"/test_files"),
debug=True, debug=True,
xqueue={'interface':None, 'callback_url':'/', 'default_queuename': 'testqueue'}, xqueue={'interface':None, 'callback_url':'/', 'default_queuename': 'testqueue', 'waittime': 10},
node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules") node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
anonymous_student_id = 'student'
) )
...@@ -282,29 +285,65 @@ class StringResponseWithHintTest(unittest.TestCase): ...@@ -282,29 +285,65 @@ class StringResponseWithHintTest(unittest.TestCase):
class CodeResponseTest(unittest.TestCase): class CodeResponseTest(unittest.TestCase):
''' '''
Test CodeResponse Test CodeResponse
TODO: Add tests for external grader messages
''' '''
@staticmethod
def make_queuestate(key, time):
timestr = datetime.strftime(time, dateformat)
return {'key': key, 'time': timestr}
def test_is_queued(self):
'''
Simple test of whether LoncapaProblem knows when it's been queued
'''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
with open(problem_file) as input_file:
test_lcp = lcp.LoncapaProblem(input_file.read(), '1', system=i4xs)
answer_ids = sorted(test_lcp.get_question_answers())
# CodeResponse requires internal CorrectMap state. Build it now in the unqueued state
cmap = CorrectMap()
for answer_id in answer_ids:
cmap.update(CorrectMap(answer_id=answer_id, queuestate=None))
test_lcp.correct_map.update(cmap)
self.assertEquals(test_lcp.is_queued(), False)
# Now we queue the LCP
cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuestate = CodeResponseTest.make_queuestate(i, datetime.now())
cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate))
test_lcp.correct_map.update(cmap)
self.assertEquals(test_lcp.is_queued(), True)
def test_update_score(self): def test_update_score(self):
problem_file = os.path.dirname(__file__) + "/test_files/coderesponse.xml" '''
test_lcp = lcp.LoncapaProblem(open(problem_file).read(), '1', system=i4xs) Test whether LoncapaProblem.update_score can deliver queued result to the right subproblem
'''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
with open(problem_file) as input_file:
test_lcp = lcp.LoncapaProblem(input_file.read(), '1', system=i4xs)
# CodeResponse requires internal CorrectMap state. Build it now in the 'queued' state answer_ids = sorted(test_lcp.get_question_answers())
old_cmap = CorrectMap()
answer_ids = sorted(test_lcp.get_question_answers().keys())
numAnswers = len(answer_ids)
for i in range(numAnswers):
old_cmap.update(CorrectMap(answer_id=answer_ids[i], queuekey=1000 + i))
# TODO: Message format inherited from ExternalResponse # CodeResponse requires internal CorrectMap state. Build it now in the queued state
#correct_score_msg = "<edxgrade><awarddetail>EXACT_ANS</awarddetail><message>MESSAGE</message></edxgrade>" old_cmap = CorrectMap()
#incorrect_score_msg = "<edxgrade><awarddetail>WRONG_FORMAT</awarddetail><message>MESSAGE</message></edxgrade>" for i, answer_id in enumerate(answer_ids):
queuekey = 1000 + i
queuestate = CodeResponseTest.make_queuestate(1000+i, datetime.now())
old_cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate))
# New message format common to external graders # Message format common to external graders
correct_score_msg = json.dumps({'correct':True, 'score':1, 'msg':'MESSAGE'}) grader_msg = '<span>MESSAGE</span>' # Must be valid XML
incorrect_score_msg = json.dumps({'correct':False, 'score':0, 'msg':'MESSAGE'}) correct_score_msg = json.dumps({'correct':True, 'score':1, 'msg': grader_msg})
incorrect_score_msg = json.dumps({'correct':False, 'score':0, 'msg': grader_msg})
xserver_msgs = {'correct': correct_score_msg, xserver_msgs = {'correct': correct_score_msg,
'incorrect': incorrect_score_msg, 'incorrect': incorrect_score_msg,}
}
# Incorrect queuekey, state should not be updated # Incorrect queuekey, state should not be updated
for correctness in ['correct', 'incorrect']: for correctness in ['correct', 'incorrect']:
...@@ -314,32 +353,68 @@ class CodeResponseTest(unittest.TestCase): ...@@ -314,32 +353,68 @@ class CodeResponseTest(unittest.TestCase):
test_lcp.update_score(xserver_msgs[correctness], queuekey=0) test_lcp.update_score(xserver_msgs[correctness], queuekey=0)
self.assertEquals(test_lcp.correct_map.get_dict(), old_cmap.get_dict()) # Deep comparison self.assertEquals(test_lcp.correct_map.get_dict(), old_cmap.get_dict()) # Deep comparison
for i in range(numAnswers): for answer_id in answer_ids:
self.assertTrue(test_lcp.correct_map.is_queued(answer_ids[i])) # Should be still queued, since message undelivered self.assertTrue(test_lcp.correct_map.is_queued(answer_id)) # Should be still queued, since message undelivered
# Correct queuekey, state should be updated # Correct queuekey, state should be updated
for correctness in ['correct', 'incorrect']: for correctness in ['correct', 'incorrect']:
for i in range(numAnswers): # Target specific answer_id's for i, answer_id in enumerate(answer_ids):
test_lcp.correct_map = CorrectMap() test_lcp.correct_map = CorrectMap()
test_lcp.correct_map.update(old_cmap) test_lcp.correct_map.update(old_cmap)
new_cmap = CorrectMap() new_cmap = CorrectMap()
new_cmap.update(old_cmap) new_cmap.update(old_cmap)
npoints = 1 if correctness=='correct' else 0 npoints = 1 if correctness=='correct' else 0
new_cmap.set(answer_id=answer_ids[i], npoints=npoints, correctness=correctness, msg='MESSAGE', queuekey=None) new_cmap.set(answer_id=answer_id, npoints=npoints, correctness=correctness, msg=grader_msg, queuestate=None)
test_lcp.update_score(xserver_msgs[correctness], queuekey=1000 + i) test_lcp.update_score(xserver_msgs[correctness], queuekey=1000 + i)
self.assertEquals(test_lcp.correct_map.get_dict(), new_cmap.get_dict()) self.assertEquals(test_lcp.correct_map.get_dict(), new_cmap.get_dict())
for j in range(numAnswers): for j, test_id in enumerate(answer_ids):
if j == i: if j == i:
self.assertFalse(test_lcp.correct_map.is_queued(answer_ids[j])) # Should be dequeued, message delivered self.assertFalse(test_lcp.correct_map.is_queued(test_id)) # Should be dequeued, message delivered
else: else:
self.assertTrue(test_lcp.correct_map.is_queued(answer_ids[j])) # Should be queued, message undelivered self.assertTrue(test_lcp.correct_map.is_queued(test_id)) # Should be queued, message undelivered
def test_recentmost_queuetime(self):
'''
Test whether the LoncapaProblem knows about the time of queue requests
'''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
with open(problem_file) as input_file:
test_lcp = lcp.LoncapaProblem(input_file.read(), '1', system=i4xs)
answer_ids = sorted(test_lcp.get_question_answers())
# CodeResponse requires internal CorrectMap state. Build it now in the unqueued state
cmap = CorrectMap()
for answer_id in answer_ids:
cmap.update(CorrectMap(answer_id=answer_id, queuestate=None))
test_lcp.correct_map.update(cmap)
self.assertEquals(test_lcp.get_recentmost_queuetime(), None)
# CodeResponse requires internal CorrectMap state. Build it now in the queued state
cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuekey = 1000 + i
latest_timestamp = datetime.now()
queuestate = CodeResponseTest.make_queuestate(1000+i, latest_timestamp)
cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate))
test_lcp.correct_map.update(cmap)
# Queue state only tracks up to second
latest_timestamp = datetime.strptime(datetime.strftime(latest_timestamp, dateformat), dateformat)
self.assertEquals(test_lcp.get_recentmost_queuetime(), latest_timestamp)
def test_convert_files_to_filenames(self): def test_convert_files_to_filenames(self):
problem_file = os.path.dirname(__file__) + "/test_files/coderesponse.xml" '''
fp = open(problem_file) Test whether file objects are converted to filenames without altering other structures
'''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
with open(problem_file) as fp:
answers_with_file = {'1_2_1': 'String-based answer', answers_with_file = {'1_2_1': 'String-based answer',
'1_3_1': ['answer1', 'answer2', 'answer3'], '1_3_1': ['answer1', 'answer2', 'answer3'],
'1_4_1': [fp, fp]} '1_4_1': [fp, fp]}
......
...@@ -9,91 +9,23 @@ ...@@ -9,91 +9,23 @@
Write a program to compute the square of a number Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate"> <coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/> <textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[ <codeparam>
initial_display = """ <initial_display>def square(x):</initial_display>
def square(n): <answer_display>answer</answer_display>
""" <grader_payload>grader stuff</grader_payload>
</codeparam>
answer = """
def square(n):
return n**2
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testSquare(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: square(%d)'%n
return str(square(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testSquare(0))
elif test == 2: f.write(testSquare(1))
else: f.write(testSquare())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse> </coderesponse>
</text> </text>
<text> <text>
Write a program to compute the cube of a number Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate"> <coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/> <textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[ <codeparam>
initial_display = """ <initial_display>def square(x):</initial_display>
def cube(n): <answer_display>answer</answer_display>
""" <grader_payload>grader stuff</grader_payload>
</codeparam>
answer = """
def cube(n):
return n**3
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testCube(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: cube(%d)'%n
return str(cube(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testCube(0))
elif test == 2: f.write(testCube(1))
else: f.write(testCube())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse> </coderesponse>
</text> </text>
......
<problem>
<text>
<h2>Code response</h2>
<p>
</p>
<text>
Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[
initial_display = """
def square(n):
"""
answer = """
def square(n):
return n**2
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testSquare(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: square(%d)'%n
return str(square(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testSquare(0))
elif test == 2: f.write(testSquare(1))
else: f.write(testSquare())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse>
</text>
<text>
Write a program to compute the cube of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[
initial_display = """
def cube(n):
"""
answer = """
def cube(n):
return n**3
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testCube(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: cube(%d)'%n
return str(cube(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testCube(0))
elif test == 2: f.write(testCube(1))
else: f.write(testCube())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse>
</text>
</text>
</problem>
// Generated by CoffeeScript 1.3.3
(function() {
var MinimaxProblemDisplay, root,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
MinimaxProblemDisplay = (function(_super) {
__extends(MinimaxProblemDisplay, _super);
function MinimaxProblemDisplay(state, submission, evaluation, container, submissionField, parameters) {
this.state = state;
this.submission = submission;
this.evaluation = evaluation;
this.container = container;
this.submissionField = submissionField;
this.parameters = parameters != null ? parameters : {};
MinimaxProblemDisplay.__super__.constructor.call(this, this.state, this.submission, this.evaluation, this.container, this.submissionField, this.parameters);
}
MinimaxProblemDisplay.prototype.render = function() {};
MinimaxProblemDisplay.prototype.createSubmission = function() {
var id, value, _ref, _results;
this.newSubmission = {};
if (this.submission != null) {
_ref = this.submission;
_results = [];
for (id in _ref) {
value = _ref[id];
_results.push(this.newSubmission[id] = value);
}
return _results;
}
};
MinimaxProblemDisplay.prototype.getCurrentSubmission = function() {
return this.newSubmission;
};
return MinimaxProblemDisplay;
})(XProblemDisplay);
root = typeof exports !== "undefined" && exports !== null ? exports : this;
root.TestProblemDisplay = TestProblemDisplay;
}).call(this);
;
...@@ -255,3 +255,37 @@ class ImportTestCase(unittest.TestCase): ...@@ -255,3 +255,37 @@ class ImportTestCase(unittest.TestCase):
two_toy_video = modulestore.get_instance(two_toy_id, location) two_toy_video = modulestore.get_instance(two_toy_id, location)
self.assertEqual(toy_video.metadata['youtube'], "1.0:p2Q6BrNhdh8") self.assertEqual(toy_video.metadata['youtube'], "1.0:p2Q6BrNhdh8")
self.assertEqual(two_toy_video.metadata['youtube'], "1.0:p2Q6BrNhdh9") self.assertEqual(two_toy_video.metadata['youtube'], "1.0:p2Q6BrNhdh9")
def test_colon_in_url_name(self):
"""Ensure that colons in url_names convert to file paths properly"""
print "Starting import"
modulestore = XMLModuleStore(DATA_DIR, eager=True, course_dirs=['toy'])
courses = modulestore.get_courses()
self.assertEquals(len(courses), 1)
course = courses[0]
course_id = course.id
print "course errors:"
for (msg, err) in modulestore.get_item_errors(course.location):
print msg
print err
chapters = course.get_children()
self.assertEquals(len(chapters), 2)
ch2 = chapters[1]
self.assertEquals(ch2.url_name, "secret:magic")
print "Ch2 location: ", ch2.location
also_ch2 = modulestore.get_instance(course_id, ch2.location)
self.assertEquals(ch2, also_ch2)
print "making sure html loaded"
cloc = course.location
loc = Location(cloc.tag, cloc.org, cloc.course, 'html', 'secret:toylab')
html = modulestore.get_instance(course_id, loc)
self.assertEquals(html.display_name, "Toy lab")
...@@ -30,6 +30,7 @@ class VideoModule(XModule): ...@@ -30,6 +30,7 @@ class VideoModule(XModule):
xmltree = etree.fromstring(self.definition['data']) xmltree = etree.fromstring(self.definition['data'])
self.youtube = xmltree.get('youtube') self.youtube = xmltree.get('youtube')
self.position = 0 self.position = 0
self.show_captions = xmltree.get('show_captions', 'true')
if instance_state is not None: if instance_state is not None:
state = json.loads(instance_state) state = json.loads(instance_state)
...@@ -75,6 +76,7 @@ class VideoModule(XModule): ...@@ -75,6 +76,7 @@ class VideoModule(XModule):
'display_name': self.display_name, 'display_name': self.display_name,
# TODO (cpennington): This won't work when we move to data that isn't on the filesystem # TODO (cpennington): This won't work when we move to data that isn't on the filesystem
'data_dir': self.metadata['data_dir'], 'data_dir': self.metadata['data_dir'],
'show_captions': self.show_captions
}) })
......
...@@ -717,7 +717,8 @@ class ModuleSystem(object): ...@@ -717,7 +717,8 @@ class ModuleSystem(object):
filestore=None, filestore=None,
debug=False, debug=False,
xqueue=None, xqueue=None,
node_path=""): node_path="",
anonymous_student_id=''):
''' '''
Create a closure around the system environment. Create a closure around the system environment.
...@@ -742,11 +743,16 @@ class ModuleSystem(object): ...@@ -742,11 +743,16 @@ class ModuleSystem(object):
at settings.DATA_DIR. at settings.DATA_DIR.
xqueue - Dict containing XqueueInterface object, as well as parameters xqueue - Dict containing XqueueInterface object, as well as parameters
for the specific StudentModule for the specific StudentModule:
xqueue = {'interface': XQueueInterface object,
'callback_url': Callback into the LMS,
'queue_name': Target queuename in Xqueue}
replace_urls - TEMPORARY - A function like static_replace.replace_urls replace_urls - TEMPORARY - A function like static_replace.replace_urls
that capa_module can use to fix up the static urls in that capa_module can use to fix up the static urls in
ajax results. ajax results.
anonymous_student_id - Used for tracking modules with student id
''' '''
self.ajax_url = ajax_url self.ajax_url = ajax_url
self.xqueue = xqueue self.xqueue = xqueue
...@@ -758,6 +764,7 @@ class ModuleSystem(object): ...@@ -758,6 +764,7 @@ class ModuleSystem(object):
self.seed = user.id if user is not None else 0 self.seed = user.id if user is not None else 0
self.replace_urls = replace_urls self.replace_urls = replace_urls
self.node_path = node_path self.node_path = node_path
self.anonymous_student_id = anonymous_student_id
def get(self, attr): def get(self, attr):
''' provide uniform access to attributes (like etree).''' ''' provide uniform access to attributes (like etree).'''
......
...@@ -12,6 +12,12 @@ import sys ...@@ -12,6 +12,12 @@ import sys
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def name_to_pathname(name):
"""
Convert a location name for use in a path: replace ':' with '/'.
This allows users of the xml format to organize content into directories
"""
return name.replace(':', '/')
def is_pointer_tag(xml_obj): def is_pointer_tag(xml_obj):
""" """
...@@ -245,8 +251,8 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -245,8 +251,8 @@ class XmlDescriptor(XModuleDescriptor):
# VS[compat] -- detect new-style each-in-a-file mode # VS[compat] -- detect new-style each-in-a-file mode
if is_pointer_tag(xml_object): if is_pointer_tag(xml_object):
# new style: # new style:
# read the actual definition file--named using url_name # read the actual definition file--named using url_name.replace(':','/')
filepath = cls._format_filepath(xml_object.tag, url_name) filepath = cls._format_filepath(xml_object.tag, name_to_pathname(url_name))
definition_xml = cls.load_file(filepath, system.resources_fs, location) definition_xml = cls.load_file(filepath, system.resources_fs, location)
else: else:
definition_xml = xml_object # this is just a pointer, not the real definition content definition_xml = xml_object # this is just a pointer, not the real definition content
...@@ -292,7 +298,8 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -292,7 +298,8 @@ class XmlDescriptor(XModuleDescriptor):
"""If this returns True, write the definition of this descriptor to a separate """If this returns True, write the definition of this descriptor to a separate
file. file.
NOTE: Do not override this without a good reason. It is here specifically for customtag... NOTE: Do not override this without a good reason. It is here
specifically for customtag...
""" """
return True return True
...@@ -335,7 +342,8 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -335,7 +342,8 @@ class XmlDescriptor(XModuleDescriptor):
if self.export_to_file(): if self.export_to_file():
# Write the definition to a file # Write the definition to a file
filepath = self.__class__._format_filepath(self.category, self.url_name) url_path = name_to_pathname(self.url_name)
filepath = self.__class__._format_filepath(self.category, url_path)
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(etree.tostring(xml_object, pretty_print=True)) file.write(etree.tostring(xml_object, pretty_print=True))
......
<chapter>
<video url_name="toyvideo" youtube="blahblah"/>
</chapter>
<course> <course>
<chapter url_name="Overview"> <chapter url_name="Overview">
<videosequence url_name="Toy_Videos"> <videosequence url_name="Toy_Videos">
<html url_name="toylab"/> <html url_name="secret:toylab"/>
<video url_name="Video_Resources" youtube="1.0:1bK-WdDi6Qw"/> <video url_name="Video_Resources" youtube="1.0:1bK-WdDi6Qw"/>
</videosequence> </videosequence>
<video url_name="Welcome" youtube="1.0:p2Q6BrNhdh8"/> <video url_name="Welcome" youtube="1.0:p2Q6BrNhdh8"/>
</chapter> </chapter>
<chapter url_name="secret:magic"/>
</course> </course>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"display_name": "Toy Videos", "display_name": "Toy Videos",
"format": "Lecture Sequence" "format": "Lecture Sequence"
}, },
"html/toylab": { "html/secret:toylab": {
"display_name": "Toy lab" "display_name": "Toy lab"
}, },
"video/Video_Resources": { "video/Video_Resources": {
......
...@@ -105,7 +105,7 @@ NUMPY_VER="1.6.2" ...@@ -105,7 +105,7 @@ NUMPY_VER="1.6.2"
SCIPY_VER="0.10.1" SCIPY_VER="0.10.1"
BREW_FILE="$BASE/mitx/brew-formulas.txt" BREW_FILE="$BASE/mitx/brew-formulas.txt"
LOG="/var/tmp/install-$(date +%Y%m%d-%H%M%S).log" LOG="/var/tmp/install-$(date +%Y%m%d-%H%M%S).log"
APT_PKGS="curl git python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript graphviz" APT_PKGS="curl git python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript graphviz libgraphviz-dev"
if [[ $EUID -eq 0 ]]; then if [[ $EUID -eq 0 ]]; then
error "This script should not be run using sudo or as the root user" error "This script should not be run using sudo or as the root user"
......
This doc is a rough spec of our xml format # edX xml format tutorial
Every content element (within a course) should have a unique id. This id is formed as {category}/{url_name}. Categories are the different tag types ('chapter', 'problem', 'html', 'sequential', etc). Url_name is a string containing a-z, A-Z, dot (.) and _. This is what appears in urls that point to this object. ## Goals of this document
File layout: * This was written assuming the reader has no prior programming/CS knowledge and has jumped cold turkey into the edX platform.
* To educate the reader on how to build and maintain the back end structure of the course content. This is important for debugging and standardization.
* After reading this, you should be able to add content to a course and make sure it shows up in the courseware and does not break the code.
* __Prerequisites:__ it would be helpful to know a little bit about xml. Here is a [simple example](http://www.ultraslavonic.info/intro-to-xml/) if you've never seen it before.
- Xml files have content ## Outline
- "policy", which is also called metadata in various places, should live in a policy file.
- each module (except customtag and course, which are special, see below) should live in a file, located at {category}/{url_name].xml * First, we will show a sample course structure as a case study/model of how xml and files in a course are organized to introductory understanding.
To include this module in another one (e.g. to put a problem in a vertical), put in a "pointer tag": <{category} url_name="{url_name}"/>. When we read that, we'll load the actual contents.
Customtag is already a pointer, you can just use it in place: <customtag url_name="my_custom_tag" impl="blah" attr1="..."/> * More technical details are below, including discussion of some special cases.
Course tags:
- the top level course pointer tag lives in course.xml
- have 2 extra required attributes: "org" and "course" -- organization name, and course name. Note that the course name is referring to the platonic ideal of this course, not to any particular run of this course. The url_name should be particular run of this course. E.g.
If course.xml contains: ## Introduction
<course org="HarvardX" course="cs50" url_name="2012"/>
we would load the actual course definition from course/2012.xml * The course is organized hierarchically. We start by describing course-wide parameters, then break the course into chapters, and then go deeper and deeper until we reach a specific pset, video, etc.
To support multiple different runs of the course, you could have a different course.xml, containing * You could make an analogy to finding a green shirt in your house - front door -> bedroom -> closet -> drawer -> shirts -> green shirt
<course org="HarvardX" course="cs50" url_name="2012H"/>
which would load the Harvard-internal version from course/2012H.xml ## Case Study
If there is only one run of the course for now, just have a single course.xml with the right url_name. Let's jump right in by looking at the directory structure of a very simple toy course:
If there is more than one run of the course, the different course root pointer files should live in toy/
roots/url_name.xml, and course.xml should be a symbolic link to the one you want to run in your dev instance. course
course.xml
problem
policies
roots
If you want to run both versions, you need to checkout the repo twice, and have course.xml point to different root/{url_name}.xml files. The only top level file is `course.xml`, which should contain one line, looking something like this:
Policies: <course org="edX" course="toy" url_name="2012_Fall"/>
- the policy for a course url_name lives in policies/{url_name}.json
The format is called "json", and is best shown by example (though also feel free to google :) This gives all the information to uniquely identify a particular run of any course--which organization is producing the course, what the course name is, and what "run" this is, specified via the `url_name` attribute.
the file is a dictionary (mapping from keys to values, syntax "{ key : value, key2 : value2, etc}" Obviously, this doesn't actually specify any of the course content, so we need to find that next. To know where to look, you need to know the standard organizational structure of our system: _course elements are uniquely identified by the combination `(category, url_name)`_. In this case, we are looking for a `course` element with the `url_name` "2012_Fall". The definition of this element will be in `course/2012_Fall.xml`. Let's look there next:
Keys are in the form "{category}/{url_name}", which should uniquely id a content element. `course/2012_Fall.xml`
<course>
<chapter url_name="Overview">
<videosequence url_name="Toy_Videos">
<problem url_name="warmup"/>
<video url_name="Video_Resources" youtube="1.0:1bK-WdDi6Qw"/>
</videosequence>
<video url_name="Welcome" youtube="1.0:p2Q6BrNhdh8"/>
</chapter>
</course>
Aha. Now we found some content. We can see that the course is organized hierarchically, in this case with only one chapter, with `url_name` "Overview". The chapter contains a `videosequence` and a `video`, with the sequence containing a problem and another video. When viewed in the courseware, chapters are shown at the top level of the navigation accordion on the left, with any elements directly included in the chapter below.
Looking at this file, we can see the course structure, and the youtube urls for the videos, but what about the "warmup" problem? There is no problem content here! Where should we look? This is a good time to pause and try to answer that question based on our organizational structure above.
As you hopefully guessed, the problem would be in `problem/warmup.xml`. (Note: This tutorial doesn't discuss the xml format for problems--there are chapters of edx4edx that describe it.) This is an instance of a _pointer tag:_ any xml tag with only the category and a url_name attribute will point to the file `{category}/{url_name}.xml`. For example, this means that our toy `course.xml` could have also been written as
`course/2012_Fall.xml`
<course>
<chapter url_name="Overview"/>
</course>
with `chapter/Overview.xml` containing
<chapter>
<videosequence url_name="Toy_Videos">
<problem url_name="warmup"/>
<video url_name="Video_Resources" youtube="1.0:1bK-WdDi6Qw"/>
</videosequence>
<video url_name="Welcome" youtube="1.0:p2Q6BrNhdh8"/>
</chapter>
In fact, this is the recommended structure for real courses--putting each chapter into its own file makes it easy to have different people work on each without conflicting or having to merge. Similarly, as sequences get large, it can be handy to split them out as well (in `sequence/{url_name}.xml`, of course).
Note that the `url_name` is only specified once per element--either the inline definition, or in the pointer tag.
## Policy files
We still haven't looked at two of the directoies in the top-level listing above: `policies` and `roots`. Let's look at policies next. The policy directory contains one file:
policies:
2012_Fall.json
and that file is named {course-url_name}.json. As you might expect, this file contains a policy for the course. In our example, it looks like this:
2012_Fall.json:
{
"course/2012_Fall": {
"graceperiod": "2 days 5 hours 59 minutes 59 seconds",
"start": "2015-07-17T12:00",
"display_name": "Toy Course"
},
"chapter/Overview": {
"display_name": "Overview"
},
"videosequence/Toy_Videos": {
"display_name": "Toy Videos",
"format": "Lecture Sequence"
},
"problem/warmup": {
"display_name": "Getting ready for the semester"
},
"video/Video_Resources": {
"display_name": "Video Resources"
},
"video/Welcome": {
"display_name": "Welcome"
}
}
The policy specifies metadata about the content elements--things which are not inherent to the definition of the content, but which describe how the content is presented to the user and used in the course. See below for a full list of metadata attributes; as the example shows, they include `display_name`, which is what is shown when this piece of content is referenced or shown in the courseware, and various dates and times, like `start`, which specifies when the content becomes visible to students, and various problem-specific parameters like the allowed number of attempts. One important point is that some metadata is inherited: for example, specifying the start date on the course makes it the default for every element in the course. See below for more details.
It is possible to put metadata directly in the xml, as attributes of the appropriate tag, but using a policy file has two benefits: it puts all the policy in one place, making it easier to check that things like due dates are set properly, and it allows the content definitions to be easily used in another run of the same course, with the same or similar content, but different policy.
## Roots
The last directory in the top level listing is `roots`. In our toy course, it contains a single file:
roots/
2012_Fall.xml
This file is identical to the top-level `course.xml`, containing
<course org="edX" course="toy" url_name="2012_Fall"/>
In fact, the top level `course.xml` is a symbolic link to this file. When there is only one run of a course, the roots directory is not really necessary, and the top-level course.xml file can just specify the `url_name` of the course. However, if we wanted to make a second run of our toy course, we could add another file called, e.g., `roots/2013_Spring.xml`, containing
<course org="edX" course="toy" url_name="2013_Spring"/>
After creating `course/2013_Spring.xml` with the course structure (possibly as a symbolic link or copy of `course/2012_Fall.xml` if no content was changing), and `policies/2013_Spring.json`, we would have two different runs of the toy course in the course repository. Our build system understands this roots structure, and will build a course package for each root. (Dev note: if you're using a local development environment, make the top level `course.xml` point to the desired root, and check out the repo multiple times if you need multiple runs simultaneously).
That's basically all there is to the organizational structure. Read the next section for details on the tags we support, including some special case tags like `customtag` and `html` invariants, and look at the end for some tips that will make the editing process easier.
----------
# Tag types
* `abtest` -- Support for A/B testing. TODO: add details..
* `chapter` -- top level organization unit of a course. The courseware display code currently expects the top level `course` element to contain only chapters, though there is no philosophical reason why this is required, so we may change it to properly display non-chapters at the top level.
* `course` -- top level tag. Contains everything else.
* `customtag` -- render an html template, filling in some parameters, and return the resulting html. See below for details.
* `html` -- a reference to an html file.
* `error` -- don't put these in by hand :) The internal representation of content that has an error, such as malformed xml or some broken invariant. You may see this in the xml once the CMS is in use...
* `problem` -- a problem. See elsewhere in edx4edx for documentation on the format.
* `problemset` -- logically, a series of related problems. Currently displayed vertically. May contain explanatory html, videos, etc.
* `sequential` -- a sequence of content, currently displayed with a horizontal list of tabs. If possible, use a more semantically meaningful tag (currently, we only have `videosequence`).
* `vertical` -- a sequence of content, displayed vertically. Content will be accessed all at once, on the right part of the page. No navigational bar. May have to use browser scroll bars. Content split with separators. If possible, use a more semantically meaningful tag (currently, we only have `problemset`).
* `video` -- a link to a video, currently expected to be hosted on youtube.
* `videosequence` -- a sequence of videos. This can contain various non-video content; it just signals to the system that this is logically part of an explanatory sequence of content, as opposed to say an exam sequence.
## Tag details
### Container tags
Container tags include `chapter`, `sequential`, `videosequence`, `vertical`, and `problemset`. They are all specified in the same way in the xml, as shown in the tutorial above.
### `course`
`course` is also a container, and is similar, with one extra wrinkle: the top level pointer tag _must_ have `org` and `course` attributes specified--the organization name, and course name. Note that `course` is referring to the platonic ideal of this course (e.g. "6.002x"), not to any particular run of this course. The `url_name` should be the particular run of this course.
### `customtag`
When we see `<customtag impl="special" animal="unicorn" hat="blue"/>`, we will:
* look for a file called `custom_tags/special` in your course dir.
* render it as a mako template, passing parameters {'animal':'unicorn', 'hat':'blue'}, generating html. (Google `mako` for template syntax, or look at existing examples).
Since `customtag` is already a pointer, there is generally no need to put it into a separate file--just use it in place: <customtag url_name="my_custom_tag" impl="blah" attr1="..."/>
### `html`
Most of our content is in xml, but some html content may not be proper xml (all tags matched, single top-level tag, etc), since browsers are fairly lenient in what they'll display. So, there are two ways to include html content:
* If your html content is in a proper xml format, just put it in `html/{url_name}.xml`.
* If your html content is not in proper xml format, you can put it in `html/{filename}.html`, and put `<html filename={filename} />` in `html/{filename}.xml`. This allows another level of indirection, and makes sure that we can read the xml file and then just return the actual html content without trying to parse it.
### `video`
Videos have an attribute youtube, which specifies a series of speeds + youtube videos id:
<video youtube="0.75:1yk1A8-FPbw,1.0:vNMrbPvwhU4,1.25:gBW_wqe7rDc,1.50:7AE_TKgaBwA" url_name="S15V14_Response_to_impulse_limit_case"/>
This video has been encoded at 4 different speeds: 0.75x, 1x, 1.25x, and 1.5x.
## More on `url_name`s
Every content element (within a course) should have a unique id. This id is formed as `{category}/{url_name}`, or automatically generated from the content if `url_name` is not specified. Categories are the different tag types ('chapter', 'problem', 'html', 'sequential', etc). Url_name is a string containing a-z, A-Z, dot (.), underscore (_), and ':'. This is what appears in urls that point to this object.
Colon (':') is special--when looking for the content definition in an xml, ':' will be replaced with '/'. This allows organizing content into folders. For example, given the pointer tag
<problem url_name="conceptual:add_apples_and_oranges"/>
we would look for the problem definition in `problem/conceptual/add_apples_and_oranges.xml`. (There is a technical reason why we can't just allow '/' in the url_name directly.)
__IMPORTANT__: A student's state for a particular content element is tied to the element id, so the automatic id generation if only ok for elements that do not need to store any student state (e.g. verticals or customtags). For problems, sequentials, and videos, and any other element where we keep track of what the student has done and where they are at, you should specify a unique `url_name`. Of course, any content element that is split out into a file will need a `url_name` to specify where to find the definition. When the CMS comes online, it will use these ids to enable content reuse, so if there is a logical name for something, please do specify it.
-----
## Policy files
* A policy file is useful when running different versions of a course e.g. internal, external, fall, spring, etc. as you can change due dates, etc, by creating multiple policy files.
* A policy file provides information on the metadata of the course--things that are not inherent to the definitions of the contents, but that may vary from run to run.
* Note: We will be expanding our understanding and format for metadata in the not-too-distant future, but for now it is simply a set of key-value pairs.
### Policy file location
* The policy for a course run `some_url_name` lives in `policies/some_url_name.json`
### Policy file contents
* The file format is "json", and is best shown by example, as in the tutorial above (though also feel free to google :)
* The expected contents are a dictionary mapping from keys to values (syntax "{ key : value, key2 : value2, etc}")
* Keys are in the form "{category}/{url_name}", which should uniquely identify a content element.
Values are dictionaries of the form {"metadata-key" : "metadata-value"}. Values are dictionaries of the form {"metadata-key" : "metadata-value"}.
* The order in which things appear does not matter, though it may be helpful to organize the file in the same order as things appear in the content.
* NOTE: json is picky about commas. If you have trailing commas before closing braces, it will complain and refuse to parse the file. This can be irritating at first.
### Available metadata
__Not inherited:__
* `display_name` - name that will appear when this content is displayed in the courseware. Useful for all tag types.
* `format` - subheading under display name -- currently only displayed for chapter sub-sections. Also used by the the grader to know how to process students assessments that the
section contains. New formats can be defined as a 'type' in the GRADER variable in course_settings.json. Optional. (TODO: double check this--what's the current behavior?)
* `hide_from_toc` -- If set to true for a chapter or chapter subsection, will hide that element from the courseware navigation accordion. This is useful if you'd like to link to the content directly instead (e.g. for tutorials)
* `ispublic` -- specify whether the course is public. You should be able to use start dates instead (?)
__Inherited:__
metadata can also live in the xml files, but anything defined in the policy file overrides anything in the xml. This is primarily for backwards compatibility, and you should probably not use both. If you do leave some metadata tags in the xml, please be consistent (e.g. if display_names stay in xml, they should all stay in xml). * `start` -- when this content should be shown to students. Note that anyone with staff access to the course will always see everything.
- note, some xml attributes are not metadata. e.g. in <video youtube="xyz987293487293847"/>, the youtube attribute specifies what video this is, and is logically part of the content, not the policy, so it should stay in video/{url_name}.xml. * `showanswer` - When to show answer. For 'attempted', will show answer after first attempt. Values: never, attempted, answered, closed. Default: closed. Optional.
* `graded` - Whether this section will count towards the students grade. "true" or "false". Defaults to "false".
* `rerandomise` - Randomize question on each attempt. Values: 'always' (students see a different version of the problem after each attempt to solve it)
'never' (all students see the same version of the problem)
'per_student' (individual students see the same version of the problem each time the look at it, but that version is different from what other students see)
Default: 'always'. Optional.
* `due` - Due date for assignment. Assignment will be closed after that. Values: valid date. Default: none. Optional.
* attempts: Number of allowed attempts. Values: integer. Default: infinite. Optional.
* `graceperiod` - A default length of time that the problem is still accessible after the due date in the format "2 days 3 hours" or "1 day 15 minutes". Note, graceperiods are currently the easiest way to handle time zones. Due dates are all expressed in UCT.
* `xqa_key` -- for integration with Ike's content QA server. -- should typically be specified at the course level.
Example policy file: __Inheritance example:__
{
This is a sketch ("tue" is not a valid start date), that should help illustrate how metadata inheritance works.
<course start="tue">
<chap1> -- start tue
<problem> --- start tue
</chap1>
<chap2 start="wed"> -- start wed
<problem2 start="thu"> -- start thu
<problem3> -- start wed
</chap2>
</course>
## Specifying metadata in the xml file
Metadata can also live in the xml files, but anything defined in the policy file overrides anything in the xml. This is primarily for backwards compatibility, and you should probably not use both. If you do leave some metadata tags in the xml, you should be consistent (e.g. if `display_name`s stay in xml, they should all stay in xml).
- note, some xml attributes are not metadata. e.g. in `<video youtube="xyz987293487293847"/>`, the `youtube` attribute specifies what video this is, and is logically part of the content, not the policy, so it should stay in the xml.
Another example policy file:
{
"course/2012": { "course/2012": {
"graceperiod": "1 day", "graceperiod": "1 day",
"start": "2012-10-15T12:00", "start": "2012-10-15T12:00",
...@@ -62,86 +278,44 @@ Example policy file: ...@@ -62,86 +278,44 @@ Example policy file:
"display_name": "Pre-Course Survey", "display_name": "Pre-Course Survey",
"format": "Survey" "format": "Survey"
} }
} }
NOTE: json is picky about commas. If you have trailing commas before closing braces, it will complain and refuse to parse the file. This is irritating.
Valid tag categories: ## Deprecated formats
abtest If you look at some older xml, you may see some tags or metadata attributes that aren't listed above. They are deprecated, and should not be used in new content. We include them here so that you can understand how old-format content works.
chapter
course
customtag
html
error -- don't put these in by hand :)
problem
problemset
sequential
vertical
video
videosequence
Obsolete tags: ### Obsolete tags:
Use customtag instead:
videodev
book
slides
image
discuss
Ex: instead of <book page="12"/>, use <customtag impl="book" page="12"/> * `section` : this used to be necessary within chapters. Now, you can just use any standard tag inside a chapter, so use the container tag that makes the most sense for grouping content--e.g. `problemset`, `videosequence`, and just include content directly if it belongs inside a chapter (e.g. `html`, `video`, `problem`)
Use something semantic instead, as makes sense: sequential, vertical, videosequence if it's actually a sequence. If the section would only contain a single element, just include that element directly. * There used to be special purpose tags that all basically did the same thing, and have been subsumed by `customtag`. The list is `videodev, book, slides, image, discuss`. Use `customtag` in new content. (e.g. instead of `<book page="12"/>`, use `<customtag impl="book" page="12"/>`)
section
In general, prefer the most "semantic" name for containers: e.g. use problemset rather than vertical for a problem set. That way, if we decide to display problem sets differently, we don't have to change the xml. ### Obsolete attributes
How customtags work: * `slug` -- old term for `url_name`. Use `url_name`
When we see <customtag impl="special" animal="unicorn" hat="blue"/>, we will: * `name` -- we didn't originally have a distinction between `url_name` and `display_name` -- this made content element ids fragile, so please use `url_name` as a stable unique identifier for the content, and `display_name` as the particular string you'd like to display for it.
- look for a file called custom_tags/special in your course dir.
- render it as a mako template, passing parameters {'animal':'unicorn', 'hat':'blue'}, generating html.
# Static links
METADATA if your content links (e.g. in an html file) to `"static/blah/ponies.jpg"`, we will look for this in `YOUR_COURSE_DIR/blah/ponies.jpg`. Note that this is not looking in a `static/` subfolder in your course dir. This may (should?) change at some point. Links that include `/course` will be rewritten to the root of your course in the courseware (e.g. `courses/{org}/{course}/{url_name}/` in the current url structure). This is useful for linking to the course wiki, for example.
Metadata that we generally understand: # Tips for content developers
Only on course tag in courses/url_name.xml
ispublic
xqa_key -- set only on course, inherited to everything else
Everything: * We will be making better tools for managing policy files soon. In the meantime, you can add dummy definitions to make it easier to search and separate the file visually. For example, you could add:
display_name
format (maybe only content containers, e.g. "Lecture sequence", "problem set", "lab", etc. )
start -- modules will not show up to non-course-staff users before the start date (in production)
hide_from_toc -- if this is true, don't show in table of contents for the course. Useful on chapters, and chapter subsections that are linked to from somewhere else.
Used for problems "WEEK 1" : "##################################################",
graceperiod
showanswer
rerandomize
graded
due
before the week 1 material to make it easy to find in the file.
These are _inherited_ : if specified on the course, will apply to everything in the course, except for things that explicitly specify them, and their children. * Come up with a consistent pattern for url_names, so that it's easy to know where to look for any piece of content. It will also help to come up with a standard way of splitting your content files. As a point of departure, we suggest splitting chapters, sequences, html, and problems into separate files.
'graded', 'start', 'due', 'graceperiod', 'showanswer', 'rerandomize',
# TODO (ichuang): used for Fall 2012 xqa server access
'xqa_key',
Example sketch: * A heads up: our content management system will allow you to develop content through a web browser, but will be backed by this same xml at first. Once that happens, every element will be in its own file to make access and updates faster.
<course start="tue">
<chap1> -- start tue
<problem> --- start tue
</chap1>
<chap2 start="wed"> -- start wed
<problem2 start="thu"> -- start thu
<problem3> -- start wed
</chap2>
</course>
* Prefer the most "semantic" name for containers: e.g., use problemset rather than vertical for a problem set. That way, if we decide to display problem sets differently, we don't have to change the xml.
STATIC LINKS: ----
if your content links (e.g. in an html file) to "static/blah/ponies.jpg", we will look for this in YOUR_COURSE_DIR/blah/ponies.jpg. Note that this is not looking in a static/ subfolder in your course dir. This may (should?) change at some point. (Dev note: This file is generated from the mitx repo, in `doc/xml-format.md`. Please make edits there.)
...@@ -4,9 +4,12 @@ from django.utils.encoding import force_unicode ...@@ -4,9 +4,12 @@ from django.utils.encoding import force_unicode
from django.utils.html import conditional_escape from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.template.loader import render_to_string
from wiki.editors.base import BaseEditor from wiki.editors.base import BaseEditor
from wiki.editors.markitup import MarkItUpAdminWidget from wiki.editors.markitup import MarkItUpAdminWidget
class CodeMirrorWidget(forms.Widget): class CodeMirrorWidget(forms.Widget):
def __init__(self, attrs=None): def __init__(self, attrs=None):
# The 'rows' and 'cols' attributes are required for HTML correctness. # The 'rows' and 'cols' attributes are required for HTML correctness.
...@@ -18,9 +21,15 @@ class CodeMirrorWidget(forms.Widget): ...@@ -18,9 +21,15 @@ class CodeMirrorWidget(forms.Widget):
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
if value is None: value = '' if value is None: value = ''
final_attrs = self.build_attrs(attrs, name=name) final_attrs = self.build_attrs(attrs, name=name)
return mark_safe(u'<div><textarea%s>%s</textarea></div>' % (flatatt(final_attrs),
conditional_escape(force_unicode(value)))) # TODO use the help_text field of edit form instead of rendering a template
return render_to_string('wiki/includes/editor_widget.html',
{'attrs': mark_safe(flatatt(final_attrs)),
'content': conditional_escape(force_unicode(value)),
})
class CodeMirror(BaseEditor): class CodeMirror(BaseEditor):
...@@ -50,5 +59,6 @@ class CodeMirror(BaseEditor): ...@@ -50,5 +59,6 @@ class CodeMirror(BaseEditor):
"js/vendor/CodeMirror/xml.js", "js/vendor/CodeMirror/xml.js",
"js/vendor/CodeMirror/mitx_markdown.js", "js/vendor/CodeMirror/mitx_markdown.js",
"js/wiki/CodeMirror.init.js", "js/wiki/CodeMirror.init.js",
"js/wiki/cheatsheet.js",
) )
...@@ -17,6 +17,7 @@ log = logging.getLogger("mitx.courseware") ...@@ -17,6 +17,7 @@ log = logging.getLogger("mitx.courseware")
def yield_module_descendents(module): def yield_module_descendents(module):
stack = module.get_display_items() stack = module.get_display_items()
stack.reverse()
while len(stack) > 0: while len(stack) > 0:
next_module = stack.pop() next_module = stack.pop()
......
import hashlib
import json import json
import logging import logging
import sys import sys
...@@ -143,8 +144,9 @@ def get_module(user, request, location, student_module_cache, course_id, positio ...@@ -143,8 +144,9 @@ def get_module(user, request, location, student_module_cache, course_id, positio
exists. exists.
Arguments: Arguments:
- user : current django User - user : User for whom we're getting the module
- request : current django HTTPrequest - request : current django HTTPrequest. Note: request.user isn't used for anything--all auth
and such works based on user.
- location : A Location-like object identifying the module to load - location : A Location-like object identifying the module to load
- student_module_cache : a StudentModuleCache - student_module_cache : a StudentModuleCache
- course_id : the course_id in the context of which to load module - course_id : the course_id in the context of which to load module
...@@ -173,7 +175,13 @@ def _get_module(user, request, location, student_module_cache, course_id, positi ...@@ -173,7 +175,13 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
if not has_access(user, descriptor, 'load'): if not has_access(user, descriptor, 'load'):
return None return None
#TODO Only check the cache if this module can possibly have state # Anonymized student identifier
h = hashlib.md5()
h.update(settings.SECRET_KEY)
h.update(str(user.id))
anonymous_student_id = h.hexdigest()
# Only check the cache if this module can possibly have state
instance_module = None instance_module = None
shared_module = None shared_module = None
if user.is_authenticated(): if user.is_authenticated():
...@@ -197,6 +205,8 @@ def _get_module(user, request, location, student_module_cache, course_id, positi ...@@ -197,6 +205,8 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
location=descriptor.location.url(), location=descriptor.location.url(),
dispatch=''), dispatch=''),
) )
# Intended use is as {ajax_url}/{dispatch_command}, so get rid of the trailing slash.
ajax_url = ajax_url.rstrip('/')
# Fully qualified callback URL for external queueing system # Fully qualified callback URL for external queueing system
xqueue_callback_url = '{proto}://{host}'.format( xqueue_callback_url = '{proto}://{host}'.format(
...@@ -217,7 +227,9 @@ def _get_module(user, request, location, student_module_cache, course_id, positi ...@@ -217,7 +227,9 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
xqueue = {'interface': xqueue_interface, xqueue = {'interface': xqueue_interface,
'callback_url': xqueue_callback_url, 'callback_url': xqueue_callback_url,
'default_queuename': xqueue_default_queuename.replace(' ', '_')} 'default_queuename': xqueue_default_queuename.replace(' ', '_'),
'waittime': settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS
}
def inner_get_module(location): def inner_get_module(location):
""" """
...@@ -241,7 +253,8 @@ def _get_module(user, request, location, student_module_cache, course_id, positi ...@@ -241,7 +253,8 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
# a module is coming through get_html and is therefore covered # a module is coming through get_html and is therefore covered
# by the replace_static_urls code below # by the replace_static_urls code below
replace_urls=replace_urls, replace_urls=replace_urls,
node_path=settings.NODE_PATH node_path=settings.NODE_PATH,
anonymous_student_id=anonymous_student_id
) )
# pass position specified in URL to module through ModuleSystem # pass position specified in URL to module through ModuleSystem
system.set('position', position) system.set('position', position)
...@@ -409,6 +422,10 @@ def modx_dispatch(request, dispatch, location, course_id): ...@@ -409,6 +422,10 @@ def modx_dispatch(request, dispatch, location, course_id):
''' '''
# ''' (fix emacs broken parsing) # ''' (fix emacs broken parsing)
# Check parameters and fail fast if there's a problem
if not Location.is_valid(location):
raise Http404("Invalid location")
# Check for submitted files and basic file size checks # Check for submitted files and basic file size checks
p = request.POST.copy() p = request.POST.copy()
if request.FILES: if request.FILES:
......
...@@ -411,8 +411,6 @@ class TestViewAuth(PageLoader): ...@@ -411,8 +411,6 @@ class TestViewAuth(PageLoader):
"""list of urls that only instructors/staff should be able to see""" """list of urls that only instructors/staff should be able to see"""
urls = reverse_urls(['instructor_dashboard','gradebook','grade_summary'], urls = reverse_urls(['instructor_dashboard','gradebook','grade_summary'],
course) course)
urls.append(reverse('student_progress', kwargs={'course_id': course.id,
'student_id': user(self.student).id}))
return urls return urls
def check_non_staff(course): def check_non_staff(course):
...@@ -435,6 +433,17 @@ class TestViewAuth(PageLoader): ...@@ -435,6 +433,17 @@ class TestViewAuth(PageLoader):
print 'checking for 200 on {0}'.format(url) print 'checking for 200 on {0}'.format(url)
self.check_for_get_code(200, url) self.check_for_get_code(200, url)
# The student progress tab is not accessible to a student
# before launch, so the instructor view-as-student feature should return a 404 as well.
# TODO (vshnayder): If this is not the behavior we want, will need
# to make access checking smarter and understand both the effective
# user (the student), and the requesting user (the prof)
url = reverse('student_progress', kwargs={'course_id': course.id,
'student_id': user(self.student).id})
print 'checking for 404 on view-as-student: {0}'.format(url)
self.check_for_get_code(404, url)
# First, try with an enrolled student # First, try with an enrolled student
print '=== Testing student access....' print '=== Testing student access....'
self.login(self.student, self.password) self.login(self.student, self.password)
......
...@@ -325,14 +325,21 @@ def progress(request, course_id, student_id=None): ...@@ -325,14 +325,21 @@ def progress(request, course_id, student_id=None):
raise Http404 raise Http404
student = User.objects.get(id=int(student_id)) student = User.objects.get(id=int(student_id))
# NOTE: To make sure impersonation by instructor works, use
# student instead of request.user in the rest of the function.
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents( student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(
course_id, request.user, course) course_id, student, course)
course_module = get_module(request.user, request, course.location, course_module = get_module(student, request, course.location,
student_module_cache, course_id) student_module_cache, course_id)
# The course_module should be accessible, but check anyway just in case something went wrong:
if course_module is None:
raise Http404("Course does not exist")
courseware_summary = grades.progress_summary(student, course_module, courseware_summary = grades.progress_summary(student, course_module,
course.grader, student_module_cache) course.grader, student_module_cache)
grade_summary = grades.grade(request.user, request, course, student_module_cache) grade_summary = grades.grade(student, request, course, student_module_cache)
context = {'course': course, context = {'course': course,
'courseware_summary': courseware_summary, 'courseware_summary': courseware_summary,
......
...@@ -21,11 +21,17 @@ def dashboard(request): ...@@ -21,11 +21,17 @@ def dashboard(request):
if not request.user.is_staff: if not request.user.is_staff:
raise Http404 raise Http404
query = "select count(user_id) as students, course_id from student_courseenrollment group by course_id order by students desc" queries=[]
queries.append("select count(user_id) as students, course_id from student_courseenrollment group by course_id order by students desc;")
queries.append("select count(distinct user_id) as unique_students from student_courseenrollment;")
queries.append("select registrations, count(registrations) from (select count(user_id) as registrations from student_courseenrollment group by user_id) as registrations_per_user group by registrations;")
from django.db import connection from django.db import connection
cursor = connection.cursor() cursor = connection.cursor()
results =[]
for query in queries:
cursor.execute(query) cursor.execute(query)
results = dictfetchall(cursor) results.append(dictfetchall(cursor))
return HttpResponse(json.dumps(results, indent=4)) return HttpResponse(json.dumps(results, indent=4))
#!/usr/bin/python
#
# File: manage_course_groups
#
# interactively list and edit membership in course staff and instructor groups
import os, sys, string, re
import datetime
from getpass import getpass
import json
import readline
from django.core.management.base import BaseCommand
from django.conf import settings
from django.contrib.auth.models import User, Group
#-----------------------------------------------------------------------------
# get all staff groups
class Command(BaseCommand):
help = "Manage course group membership, interactively."
def handle(self, *args, **options):
gset = Group.objects.all()
print "Groups:"
for cnt,g in zip(range(len(gset)), gset):
print "%d. %s" % (cnt,g)
gnum = int(raw_input('Choose group to manage (enter #): '))
group = gset[gnum]
#-----------------------------------------------------------------------------
# users in group
uall = User.objects.all()
if uall.count()<50:
print "----"
print "List of All Users: %s" % [str(x.username) for x in uall]
print "----"
else:
print "----"
print "There are %d users, which is too many to list" % uall.count()
print "----"
while True:
print "Users in the group:"
uset = group.user_set.all()
for cnt, u in zip(range(len(uset)), uset):
print "%d. %s" % (cnt, u)
action = raw_input('Choose user to delete (enter #) or enter usernames (comma delim) to add: ')
m = re.match('^[0-9]+$',action)
if m:
unum = int(action)
u = uset[unum]
print "Deleting user %s" % u
u.groups.remove(group)
else:
for uname in action.split(','):
try:
user = User.objects.get(username=action)
except Exception as err:
print "Error %s" % err
continue
print "adding %s to group %s" % (user, group)
user.groups.add(group)
...@@ -139,7 +139,7 @@ def gitreload(request, reload_dir=None): ...@@ -139,7 +139,7 @@ def gitreload(request, reload_dir=None):
ALLOWED_IPS = [] # allow none by default ALLOWED_IPS = [] # allow none by default
if hasattr(settings,'ALLOWED_GITRELOAD_IPS'): # allow override in settings if hasattr(settings,'ALLOWED_GITRELOAD_IPS'): # allow override in settings
ALLOWED_IPS = ALLOWED_GITRELOAD_IPS ALLOWED_IPS = settings.ALLOWED_GITRELOAD_IPS
if not (ip in ALLOWED_IPS or 'any' in ALLOWED_IPS): if not (ip in ALLOWED_IPS or 'any' in ALLOWED_IPS):
if request.user and request.user.is_staff: if request.user and request.user.is_staff:
......
...@@ -86,6 +86,9 @@ DEFAULT_GROUPS = [] ...@@ -86,6 +86,9 @@ DEFAULT_GROUPS = []
# If this is true, random scores will be generated for the purpose of debugging the profile graphs # If this is true, random scores will be generated for the purpose of debugging the profile graphs
GENERATE_PROFILE_SCORES = False GENERATE_PROFILE_SCORES = False
# Used with XQueue
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
############################# SET PATH INFORMATION ############################# ############################# SET PATH INFORMATION #############################
PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms
REPO_ROOT = PROJECT_ROOT.dirname() REPO_ROOT = PROJECT_ROOT.dirname()
......
...@@ -15,7 +15,7 @@ TEMPLATE_DEBUG = True ...@@ -15,7 +15,7 @@ TEMPLATE_DEBUG = True
MITX_FEATURES['DISABLE_START_DATES'] = True MITX_FEATURES['DISABLE_START_DATES'] = True
MITX_FEATURES['ENABLE_SQL_TRACKING_LOGS'] = True MITX_FEATURES['ENABLE_SQL_TRACKING_LOGS'] = True
MITX_FEATURES['SUBDOMAIN_COURSE_LISTINGS'] = True MITX_FEATURES['SUBDOMAIN_COURSE_LISTINGS'] = False # Enable to test subdomains--otherwise, want all courses to show up
MITX_FEATURES['SUBDOMAIN_BRANDING'] = True MITX_FEATURES['SUBDOMAIN_BRANDING'] = True
WIKI_ENABLED = True WIKI_ENABLED = True
...@@ -78,10 +78,10 @@ COURSE_LISTINGS = { ...@@ -78,10 +78,10 @@ COURSE_LISTINGS = {
'MITx/3.091x/2012_Fall', 'MITx/3.091x/2012_Fall',
'MITx/6.002x/2012_Fall', 'MITx/6.002x/2012_Fall',
'MITx/6.00x/2012_Fall'], 'MITx/6.00x/2012_Fall'],
'berkeley': ['BerkeleyX/CS169.1x/Cal_2012_Fall', 'berkeley': ['BerkeleyX/CS169/fa12',
'BerkeleyX/CS188.1x/Cal_2012_Fall'], 'BerkeleyX/CS188/fa12'],
'harvard': ['HarvardX/CS50x/2012H'], 'harvard': ['HarvardX/CS50x/2012H'],
'mit': [], 'mit': ['MITx/3.091/MIT_2012_Fall'],
'sjsu': ['MITx/6.002x-EE98/2012_Fall_SJSU'], 'sjsu': ['MITx/6.002x-EE98/2012_Fall_SJSU'],
} }
......
...@@ -58,7 +58,7 @@ XQUEUE_INTERFACE = { ...@@ -58,7 +58,7 @@ XQUEUE_INTERFACE = {
}, },
"basic_auth": ('anant', 'agarwal'), "basic_auth": ('anant', 'agarwal'),
} }
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
# TODO (cpennington): We need to figure out how envs/test.py can inject things # TODO (cpennington): We need to figure out how envs/test.py can inject things
# into common.py so that we don't have to repeat this sort of thing # into common.py so that we don't have to repeat this sort of thing
......
...@@ -124,7 +124,7 @@ if Backbone? ...@@ -124,7 +124,7 @@ if Backbone?
url = @model.urlFor('retrieve') url = @model.urlFor('retrieve')
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: $elem $elem: $elem
$loading: $(event.target) if event $loading: @$(".discussion-show-comments")
type: "GET" type: "GET"
url: url url: url
success: (response, textStatus) => success: (response, textStatus) =>
......
...@@ -169,7 +169,7 @@ if Backbone? ...@@ -169,7 +169,7 @@ if Backbone?
url = URI($elem.attr("action")).addSearch({text: @$(".search-input").val()}) url = URI($elem.attr("action")).addSearch({text: @$(".search-input").val()})
@reload($elem, url) @reload($elem, url)
sort: -> sort: (event) ->
$elem = $(event.target) $elem = $(event.target)
url = $elem.attr("sort-url") url = $elem.attr("sort-url")
@reload($elem, url) @reload($elem, url)
......
...@@ -3,9 +3,6 @@ $ -> ...@@ -3,9 +3,6 @@ $ ->
window.$$contents = {} window.$$contents = {}
window.$$discussions = {} window.$$discussions = {}
$(".discussion-module").each (index, elem) ->
view = new DiscussionModuleView(el: elem)
$("section.discussion").each (index, elem) -> $("section.discussion").each (index, elem) ->
discussionData = DiscussionUtil.getDiscussionData($(elem).attr("_id")) discussionData = DiscussionUtil.getDiscussionData($(elem).attr("_id"))
discussion = new Discussion() discussion = new Discussion()
......
$ -> $ ->
$.fn.extend $.fn.extend
loading: -> loading: ->
$(this).after("<span class='discussion-loading'></span>") @$_loading = $("<span class='discussion-loading'></span>")
$(this).after(@$_loading)
loaded: -> loaded: ->
$(this).parent().children(".discussion-loading").remove() @$_loading.remove()
class @DiscussionUtil class @DiscussionUtil
......
$(document).ready(function () {
$('#cheatsheetLink').click(function() {
$('#cheatsheetModal').modal('show');
});
$('#cheatsheetModal .close-btn').click(function(e) {
$('#cheatsheetModal').modal('hide');
});
});
\ No newline at end of file
...@@ -27,6 +27,12 @@ body.cs188 { ...@@ -27,6 +27,12 @@ body.cs188 {
margin-bottom: 1.416em; margin-bottom: 1.416em;
} }
.choicegroup {
input[type=checkbox], input[type=radio] {
margin-right: 5px;
}
}
} }
} }
...@@ -391,6 +391,18 @@ section.wiki { ...@@ -391,6 +391,18 @@ section.wiki {
line-height: 1.4em; line-height: 1.4em;
} }
#div_id_content {
position: relative;
}
#hint_id_content {
position: absolute;
top: 10px;
right: 0%;
font-size: 12px;
text-align:right;
}
.CodeMirror { .CodeMirror {
background: #fafafa; background: #fafafa;
border: 1px solid #c8c8c8; border: 1px solid #c8c8c8;
...@@ -567,11 +579,73 @@ section.wiki { ...@@ -567,11 +579,73 @@ section.wiki {
background: #f00 !important; background: #f00 !important;
} }
#cheatsheetLink {
text-align: right;
display: float;
}
#cheatsheetModal {
width: 950px;
margin-left: -450px;
margin-top: -100px;
.left-column {
margin-right: 10px;
}
.left-column,
.right-column {
float: left;
width: 450px;
}
.close-btn {
display: block;
position: absolute;
top: -8px;
right: -8px;
width: 30px;
height: 30px;
border-radius: 30px;
border: 1px solid #ccc;
@include linear-gradient(top, #eee, #d2d2d2);
font-size: 22px;
line-height: 28px;
color: #333;
text-align: center;
@include box-shadow(0 1px 0 #fff inset, 0 1px 2px rgba(0, 0, 0, .2));
}
}
#cheatsheet-body {
background: #fff;
text-align: left;
padding: 20px;
font-size: 14px;
@include clearfix;
h3 {
font-weight: bold;
}
ul {
list-style: circle;
line-height: 1.4;
color: #333;
}
}
#cheatsheet-body section + section {
margin-top: 40px;
}
#cheatsheet-body pre{
color: #000;
text-align: left;
background: #eee;
padding: 10px;
font-size: 12px;
}
/*----------------- /*-----------------
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
</div> </div>
<div class="discussion-right-wrapper"> <div class="discussion-right-wrapper">
<ul class="admin-actions"> <ul class="admin-actions">
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li> <li style="display: none;"><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
<li><a href="javascript:void(0)" class="admin-edit">Edit</a></li> <li style="display: none;"><a href="javascript:void(0)" class="admin-edit">Edit</a></li>
<li><a href="javascript:void(0)" class="admin-delete">Delete</a></li> <li style="display: none;"><a href="javascript:void(0)" class="admin-delete">Delete</a></li>
{{#thread}} {{#thread}}
<li><a href="javascript:void(0)" class="admin-openclose">{{close_thread_text}}</a></li> <li style="display: none;"><a href="javascript:void(0)" class="admin-openclose">{{close_thread_text}}</a></li>
{{/thread}} {{/thread}}
</ul> </ul>
{{#thread}} {{#thread}}
......
% if name is not UNDEFINED and name is not None: % if display_name is not UNDEFINED and display_name is not None:
<h1> ${display_name} </h1> <h2> ${display_name} </h2>
% endif % endif
<div id="video_${id}" class="video" data-streams="${streams}" data-caption-data-dir="${data_dir}"> <div id="video_${id}" class="video" data-streams="${streams}" data-caption-data-dir="${data_dir}" data-show-captions="${show_captions}">
<div class="tc-wrapper"> <div class="tc-wrapper">
<article class="video-wrapper"> <article class="video-wrapper">
<section class="video-player"> <section class="video-player">
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
{% with mathjax_mode='wiki' %} {% with mathjax_mode='wiki' %}
{% include "mathjax_include.html" %} {% include "mathjax_include.html" %}
{% endwith %} {% endwith %}
{% endaddtoblock %} {% endaddtoblock %}
{% endblock %} {% endblock %}
...@@ -69,6 +68,7 @@ ...@@ -69,6 +68,7 @@
{% endblock %} {% endblock %}
</div> </div>
</section> </section>
{% endblock %} {% endblock %}
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
{% trans "Go back" %} {% trans "Go back" %}
</a> </a>
</div> </div>
{% include "wiki/includes/cheatsheet.html" %}
</form> </form>
</article> </article>
......
...@@ -40,7 +40,10 @@ ...@@ -40,7 +40,10 @@
</a> </a>
</div> </div>
</div> </div>
{% include "wiki/includes/cheatsheet.html" %}
</form> </form>
{% endblock %} {% endblock %}
<div class="modal hide fade" id="cheatsheetModal">
<a href="#" class="close-btn">×</a>
<div id="cheatsheet-body" class="modal-body">
<div class="left-column">
<section>
<h2>Wiki Syntax Help</h2>
<p>This wiki uses <strong>Markdown</strong> for styling. There are several useful guides online. See any of the links below for in-depth details:</p>
<ul>
<li><a href="http://daringfireball.net/projects/markdown/basics" target="_blank">Markdown: Basics</a></li>
<li><a href="http://greg.vario.us/doc/markdown.txt" target="_blank">Quick Markdown Syntax Guide</a></li>
<li><a href="http://www.lowendtalk.com/discussion/6/miniature-markdown-guide" target="_blank">Miniature Markdown Guide</a></li>
</ul>
<p>To create a new wiki article, create a link to it. Clicking the link gives you the creation page.</p>
<pre>[Article Name](wiki:ArticleName)</pre>
</section>
<section>
<h3>edX Additions:</h3>
<pre>
circuit-schematic:</pre>
<pre>
$LaTeX Math Expression$</pre>
</section>
</div>
<div class="right-column">
<section>
<h3>Useful examples:</h3>
<pre>
http://wikipedia.org
[Wikipedia](http://wikipedia.org)
[edX Wiki](wiki:/edx/)</pre>
<pre>
Huge Header
===========</pre>
<pre>
Smaller Header
--------------</pre>
<pre>
*emphasis* or _emphasis_</pre>
<pre>
**strong** or __strong__</pre>
<pre>
- Unordered List
- Sub Item 1
- Sub Item 2</pre>
<pre>
1. Ordered
2. List</pre>
<pre>
> Quotes</pre>
</section>
</div>
</div>
</div>
</div>
<textarea {{ attrs }}>{{ content }}</textarea>
<p id="hint_id_content" class="help-block">
Markdown syntax is allowed. See the <a id="cheatsheetLink" href="#">cheatsheet</a> for help.
</p>
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.envs.aws")
# This application object is used by the development server
# as well as any WSGI server configured to use this file.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from django.conf import settings
from xmodule.modulestore.django import modulestore
for store_name in settings.MODULESTORE:
modulestore(store_name)
-e git://github.com/MITx/django-staticfiles.git@6d2504e5c8#egg=django-staticfiles -e git://github.com/MITx/django-staticfiles.git@6d2504e5c8#egg=django-staticfiles
-e git://github.com/MITx/django-pipeline.git#egg=django-pipeline -e git://github.com/MITx/django-pipeline.git#egg=django-pipeline
-e git://github.com/benjaoming/django-wiki.git@cd1c23e1#egg=django-wiki -e git://github.com/MITx/django-wiki.git@e2e84558#egg=django-wiki
-e git://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev -e git://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev
-e common/lib/capa -e common/lib/capa
-e common/lib/xmodule -e common/lib/xmodule
...@@ -46,4 +46,5 @@ django-sekizai<0.7 ...@@ -46,4 +46,5 @@ django-sekizai<0.7
django-mptt>=0.5.3 django-mptt>=0.5.3
sorl-thumbnail sorl-thumbnail
networkx networkx
pygraphviz
-r repo-requirements.txt -r repo-requirements.txt
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