def setup_exam(page, elem, dummy_uid): vlam = elem.attrib['title'] vlam_info = parse_vlam(vlam) exam_name = vlam_info['name'] if 'name' not in vlam_info or 'start' not in vlam_info or 'duration' not in vlam_info: print(vlam_info) print("not a valid exam") return else: now = time.time() start_time_tuple = time.strptime(vlam_info['start'],'%Y-%m-%d_%X') start_time = time.mktime(start_time_tuple) #print time.strftime('%Y-%m-%d %X', time.localtime(now)) now_str = time.strftime('%Y-%m-%d %X', time.localtime(now)) start_str = time.strftime('%Y-%m-%d %X', time.localtime(start_time)) if now < start_time: elem.text = """It is %s. The exam is not started. It will start at %s""" % (now_str, start_str) # the following test should not be needed in production code # as the exam would not have yet been created. However, we should # keep it as it is useful for testing - editing the html page, # changing time to see if the exam is allowed to take place or not. if page.username in exams: if exam_name in exams[page.username]: del exams[page.username][exam_name] return elif now > start_time + 60 * int(vlam_info['duration'][:-1]): elem.text = """Sorry, the time to complete the exam is over. It was started at %s and lasted %s minutes.""" % ( time.strftime('%Y-%m-%d %X',start_time_tuple), vlam_info['duration'][:-1]) if page.username in exams: if exam_name in exams[page.username]: del exams[page.username][exam_name] return # record the exam name which is in progress if page.username not in exams: exams[page.username] = {} if exam_name not in exams[page.username]: exams[page.username][exam_name] = {} exams[page.username][exam_name]['problems'] = [] elem.text = "The Exam %s, started at %s (Duration: %s minutes.)\n" % ( exam_name, time.strftime('%Y-%m-%d %X',start_time_tuple), vlam_info['duration'][:-1]) elem.text += "It is currently %s." % now_str
def setup_exam(page, elem, dummy_uid): vlam = elem.attrib['title'] vlam_info = parse_vlam(vlam) exam_name = vlam_info['name'] if 'name' not in vlam_info or 'start' not in vlam_info or 'duration' not in vlam_info: print(vlam_info) print("not a valid exam") return else: now = time.time() start_time_tuple = time.strptime(vlam_info['start'], '%Y-%m-%d_%X') start_time = time.mktime(start_time_tuple) #print time.strftime('%Y-%m-%d %X', time.localtime(now)) now_str = time.strftime('%Y-%m-%d %X', time.localtime(now)) start_str = time.strftime('%Y-%m-%d %X', time.localtime(start_time)) if now < start_time: elem.text = """It is %s. The exam is not started. It will start at %s""" % (now_str, start_str) # the following test should not be needed in production code # as the exam would not have yet been created. However, we should # keep it as it is useful for testing - editing the html page, # changing time to see if the exam is allowed to take place or not. if page.username in exams: if exam_name in exams[page.username]: del exams[page.username][exam_name] return elif now > start_time + 60 * int(vlam_info['duration'][:-1]): elem.text = """Sorry, the time to complete the exam is over. It was started at %s and lasted %s minutes.""" % (time.strftime( '%Y-%m-%d %X', start_time_tuple), vlam_info['duration'][:-1]) if page.username in exams: if exam_name in exams[page.username]: del exams[page.username][exam_name] return # record the exam name which is in progress if page.username not in exams: exams[page.username] = {} if exam_name not in exams[page.username]: exams[page.username][exam_name] = {} exams[page.username][exam_name]['problems'] = [] elem.text = "The Exam %s, started at %s (Duration: %s minutes.)\n" % ( exam_name, time.strftime( '%Y-%m-%d %X', start_time_tuple), vlam_info['duration'][:-1]) elem.text += "It is currently %s." % now_str
def doctest_widget_callback(page, elem, uid): """Handles embedding suitable code into the page in order to display and run doctests""" vlam = elem.attrib["title"] log_id = extract_log_id(vlam) vlam_info = parse_vlam(vlam) limit_time = vlam_info.get("time", None) exam_name = vlam_info.get("exam_name", None) # We check to see if an exam name has been defined (in exam_mode.py). # This is only defined when a test has started. if exam_name: if page.username not in exams: elem.clear() return elif exam_name not in exams[page.username]: elem.clear() return else: exams[page.username][exam_name]['problems'].append(uid) if log_id: t = 'doctest' config[page.username]['logging_uids'][uid] = (log_id, t) # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, to make # thus making the source easier to read. if 'display' not in config[page.username]['page_security_level'](page.url): if not page.includes("doctest_included") : page.add_include("doctest_included") page.add_js_code(doctest_jscode) # next, we style the code, also extracting it in a useful form ... elem.attrib['title'] = "pycon" doctestcode, show_vlam = plugin['services'].style(page, elem, None, vlam) # remove trailing white spaces, which may mess the expected output... doctestcode_lines = doctestcode.split('\n') for i in range(len(doctestcode_lines)): doctestcode_lines[i] = doctestcode_lines[i].rstrip() doctestcode = '\n'.join(doctestcode_lines) elem.attrib['title'] = vlam if log_id: config[page.username]['log'][log_id] = [tostring(elem)] # which we store doctests[uid] = doctestcode wrap_in_div(elem, uid, vlam, "doctest", show_vlam) if config[page.username]['popups']: # insert popup helper img = Element("img", src="/images/help.png", style="height:32px;", title = "cluetip Hello %s! "%page.username + "This is a doctest.; click for more", rel = "/docs/popups/doctest.html") elem.append(img) plugin['services'].insert_cluetip(page, img, uid) # call the insert_editor_subwidget service to insert an editor: plugin['services'].insert_editor_subwidget(page, elem, uid) #some spacing: SubElement(elem, "br") # the actual button used for code execution: btn = SubElement(elem, "button") btn.attrib["id"] = "run_doctest_btn_" + uid btn.text = _("Run Doctest") btn.attrib["onclick"] = "exec_doctest('%s')" % uid if "analyzer_score" in vlam: plugin['services'].add_scoring(page, btn, uid) if "analyzer_report" in vlam: plugin['services'].insert_analyzer_button(page, elem, uid) SubElement(elem, "br") if limit_time: page.add_js_code("window.addEventListener('load', function(e){count_down('%s', get_doctest_time('%s'));}, false);" %(uid, uid)) # finally, an output subwidget: plugin['services'].insert_io_subwidget(page, elem, uid)