Commit 11a112a0 by Victor Shnayder

Mid-cleanup.

- remove all the html-module-specific cruft
parent 72265d7f
...@@ -30,15 +30,17 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?) ...@@ -30,15 +30,17 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?)
def only_one(lst, default="", process=lambda x: x): def only_one(lst, default="", process=lambda x: x):
""" """
If lst is empty, returns default If lst is empty, returns default
If lst has a single element, applies process to that element and returns it
Otherwise, raises an exeception If lst has a single element, applies process to that element and returns it.
Otherwise, raises an exception.
""" """
if len(lst) == 0: if len(lst) == 0:
return default return default
elif len(lst) == 1: elif len(lst) == 1:
return process(lst[0]) return process(lst[0])
else: else:
raise Exception('Malformed XML') raise Exception('Malformed XML: expected at most one element in list.')
def parse_timedelta(time_str): def parse_timedelta(time_str):
...@@ -292,11 +294,11 @@ class CapaModule(XModule): ...@@ -292,11 +294,11 @@ class CapaModule(XModule):
# check button is context-specific. # check button is context-specific.
# Put a "Check" button if unlimited attempts or still some left # Put a "Check" button if unlimited attempts or still some left
if self.max_attempts is None or self.attempts < self.max_attempts-1: if self.max_attempts is None or self.attempts < self.max_attempts-1:
check_button = "Check" check_button = "Check"
else: else:
# Will be final check so let user know that # Will be final check so let user know that
check_button = "Final Check" check_button = "Final Check"
reset_button = True reset_button = True
save_button = True save_button = True
...@@ -527,11 +529,11 @@ class CapaModule(XModule): ...@@ -527,11 +529,11 @@ class CapaModule(XModule):
# Problem queued. Students must wait a specified waittime before they are allowed to submit # Problem queued. Students must wait a specified waittime before they are allowed to submit
if self.lcp.is_queued(): if self.lcp.is_queued():
current_time = datetime.datetime.now() current_time = datetime.datetime.now()
prev_submit_time = self.lcp.get_recentmost_queuetime() prev_submit_time = self.lcp.get_recentmost_queuetime()
waittime_between_requests = self.system.xqueue['waittime'] waittime_between_requests = self.system.xqueue['waittime']
if (current_time-prev_submit_time).total_seconds() < waittime_between_requests: if (current_time-prev_submit_time).total_seconds() < waittime_between_requests:
msg = 'You must wait at least %d seconds between submissions' % 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 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()
...@@ -678,10 +680,10 @@ class CapaDescriptor(RawDescriptor): ...@@ -678,10 +680,10 @@ class CapaDescriptor(RawDescriptor):
'problems/' + path[8:], 'problems/' + path[8:],
path[8:], path[8:],
] ]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(CapaDescriptor, self).__init__(*args, **kwargs) super(CapaDescriptor, self).__init__(*args, **kwargs)
weight_string = self.metadata.get('weight', None) weight_string = self.metadata.get('weight', None)
if weight_string: if weight_string:
self.weight = float(weight_string) self.weight = float(weight_string)
......
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