Commit e8501c3d by kimth

Student must wait XQUEUE_WAITTIME_BETWEEN_REQUESTS between queueing submissions

parent 42050c40
...@@ -29,6 +29,7 @@ from xml.sax.saxutils import unescape ...@@ -29,6 +29,7 @@ from xml.sax.saxutils import unescape
import calc import calc
from correctmap import CorrectMap from correctmap import CorrectMap
from datetime import datetime
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
...@@ -204,6 +205,21 @@ class LoncapaProblem(object): ...@@ -204,6 +205,21 @@ class LoncapaProblem(object):
''' '''
return any([self.correct_map.is_queued(answer_id) for answer_id in self.correct_map]) return any([self.correct_map.is_queued(answer_id) for answer_id in self.correct_map])
def get_recentmost_queuetime(self):
'''
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
queuetimes = [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,'%Y%m%d%H%M%S') for qt in queuetimes]
return max(queuetimes)
def grade_answers(self, answers): def grade_answers(self, answers):
''' '''
Grade student responses. Called by capa_module.check_problem. Grade student responses. Called by capa_module.check_problem.
......
...@@ -7,7 +7,8 @@ import traceback ...@@ -7,7 +7,8 @@ import traceback
import re import re
import sys import sys
from datetime import timedelta from datetime import datetime, timedelta
from django.conf import settings
from lxml import etree from lxml import etree
from pkg_resources import resource_string from pkg_resources import resource_string
...@@ -462,11 +463,13 @@ class CapaModule(XModule): ...@@ -462,11 +463,13 @@ 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. Student should not be able to submit # Problem queued. Students must wait XQUEUE_WAITTIME_BETWEEN_REQUESTS
'''
if self.lcp.is_queued(): if self.lcp.is_queued():
return {'success': False, 'html': 'Already queued'} current_time = datetime.now()
''' prev_submit_time = self.lcp.get_recentmost_queuetime()
if (current_time-prev_submit_time).total_seconds() < settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS:
msg = 'You must wait %d seconds between queueing requests' % settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS
return {'success': msg, 'html': ''}
try: try:
old_state = self.lcp.get_state() old_state = self.lcp.get_state()
......
...@@ -63,6 +63,7 @@ XQUEUE_INTERFACE = { ...@@ -63,6 +63,7 @@ XQUEUE_INTERFACE = {
}, },
"basic_auth": ('anant', 'agarwal'), "basic_auth": ('anant', 'agarwal'),
} }
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
# Make the keyedcache startup warnings go away # Make the keyedcache startup warnings go away
CACHE_TIMEOUT = 0 CACHE_TIMEOUT = 0
......
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