def tests_to_dict(self): """ This method parses the tests cases information in a dictionary """ # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys). grader_test_cases = CourseEditTask.dict_from_prefix( "notebook_grader_test", self.task_data) or OrderedDict() # Remove the repeated information keys_to_remove = [ key for key, _ in self.task_data.items() if key.startswith("notebook_grader_test[") ] for key in keys_to_remove: del self.task_data[key] # Convert the key to int to get a correct sort process grader_test_cases = { int(key): val for key, val in grader_test_cases.items() } grader_test_cases = OrderedDict(sorted(grader_test_cases.items())) for index, test in grader_test_cases.items(): test["cases"] = { int(key): val for key, val in test["cases"].items() } test["cases"] = OrderedDict(sorted(test["cases"].items())) return grader_test_cases
def on_task_editor_submit(course, taskid, task_data, task_fs): task_data["code_preview_pairs"] = CourseEditTask.dict_from_prefix( "code_preview_pairs", task_data) available_languages = get_all_available_languages() task_files = CourseTaskFiles.get_task_filelist(course._task_factory, course.get_id(), taskid) task_files = { complete_name[1:] if complete_name.startswith("/") else complete_name for level, is_directory, name, complete_name in task_files } if "code_preview_pairs" in task_data and task_data["code_preview_pairs"]: for language, file in task_data["code_preview_pairs"].items(): if language not in available_languages: del task_data["code_preview_pairs"][language] if file not in task_files: del task_data["code_preview_pairs"][language] to_delete = [] for key in task_data: if "code_preview_pairs[" in key: to_delete.append(key) for key in to_delete: del task_data[key]
def on_task_editor_submit(course, taskid, task_data, task_fs): task_data['code_preview_pairs'] = CourseEditTask.dict_from_prefix( 'code_preview_pairs', task_data) to_delete = [] for key in task_data: if 'code_preview_pairs[' in key: to_delete.append(key) for key in to_delete: del task_data[key]
def on_task_submit(course, taskid, task_data, task_fs): task_data["task_hints"] = CourseEditTask.dict_from_prefix("task_hints", task_data) # Delete key for hint template if it exists if "KEY" in task_data["task_hints"].keys(): del task_data["task_hints"]["KEY"] # Delete duplicate items if they exists fields_to_delete = [] for key in task_data: if "task_hints[" in key: fields_to_delete.append(key) for key in fields_to_delete: del task_data[key] # Check the fields for each hint in task for hint_id in task_data["task_hints"]: if not task_data["task_hints"][hint_id].get("content", None): return json.dumps({"status": "error", "message": _("Some hints in task have empty content fields.")}) if not task_data["task_hints"][hint_id]["title"]: return json.dumps({"status": "error", "message": _("Some hints in task have empty title fields.")}) penalty = task_data["task_hints"][hint_id]["penalty"] try: if penalty and (float(penalty) < 0 or 100 < float(penalty)): return json.dumps( {"status": "error", "message": _("Penalty for hints must be between 0.0% and 100.0%.")}) elif not penalty: task_data["task_hints"][hint_id]["penalty"] = 0.0 except (ValueError, TypeError): return json.dumps({"status": "error", "message": _("Each hint penalty must be a float.")}) else: task_data["task_hints"][hint_id]["penalty"] = round(float(penalty), 1) # Add id for hints task_data["task_hints"] = set_hints_id(task_data["task_hints"]) task_data["task_hints"] = OrderedDict(sorted(task_data["task_hints"].items())) # Update users hints in task when saved user_hint_manager().update_unlocked_users_hints(taskid, task_data["task_hints"])
def tests_to_dict(self): """ This method parses the tests cases information in a dictionary """ # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys). grader_test_cases = CourseEditTask.dict_from_prefix( "grader_test_cases", self.task_data) or OrderedDict() # Remove the repeated information keys_to_remove = [ key for key, _ in self.task_data.items() if key.startswith("grader_test_cases[") ] for key in keys_to_remove: del self.task_data[key] return grader_test_cases
def tests_to_dict(self): """ This method parses the tests cases information in a dictionary """ # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys). grader_test_cases = CourseEditTask.dict_from_prefix( "grader_test_cases", self.task_data) or OrderedDict() # Remove the repeated information keys_to_remove = [ key for key, _ in self.task_data.items() if key.startswith("grader_test_cases[") ] for key in keys_to_remove: del self.task_data[key] # Order test cases to load them correctly grader_test_cases = OrderedDict( sorted(grader_test_cases.items(), key=lambda test: test[1]["input_file"])) return grader_test_cases
def init_flask_mapping(flask_app): flask_app.url_map.converters['cookieless'] = CookielessConverter flask_app.add_url_rule('/<cookieless:sessionid>', view_func=IndexPage.as_view('indexpage')) flask_app.add_url_rule('/<cookieless:sessionid>index', view_func=IndexPage.as_view('indexpage.alias')) flask_app.add_url_rule('/<cookieless:sessionid>signin', view_func=SignInPage.as_view('signinpage')) flask_app.add_url_rule('/<cookieless:sessionid>logout', view_func=LogOutPage.as_view('logoutpage')) flask_app.add_url_rule( '/<cookieless:sessionid>register', view_func=RegistrationPage.as_view('registrationpage')) flask_app.add_url_rule('/<cookieless:sessionid>queue', view_func=QueuePage.as_view('queuepage')) flask_app.add_url_rule( '/<cookieless:sessionid>register/<courseid>', view_func=CourseRegisterPage.as_view('courseregisterpage')) flask_app.add_url_rule( '/<cookieless:sessionid>marketplace', view_func=MarketplacePage.as_view('marketplacepage')) flask_app.add_url_rule( '/<cookieless:sessionid>marketplace/<courseid>', view_func=MarketplaceCoursePage.as_view('marketplacecoursepage')) flask_app.add_url_rule('/<cookieless:sessionid>course/<courseid>', view_func=CoursePage.as_view('coursepage')) flask_app.add_url_rule('/<cookieless:sessionid>course/<courseid>/<taskid>', view_func=TaskPage.as_view('taskpage')) flask_app.add_url_rule( '/<cookieless:sessionid>course/<courseid>/<taskid>/<path:path>', view_func=TaskPageStaticDownload.as_view('taskpagestaticdownload')) flask_app.add_url_rule('/<cookieless:sessionid>group/<courseid>', view_func=GroupPage.as_view('grouppage')) flask_app.add_url_rule( '/<cookieless:sessionid>auth/signin/<auth_id>', view_func=AuthenticationPage.as_view('authenticationpage')) flask_app.add_url_rule('/<cookieless:sessionid>auth/callback/<auth_id>', view_func=CallbackPage.as_view('callbackpage')) flask_app.add_url_rule('/<cookieless:sessionid>auth/share/<auth_id>', view_func=SharePage.as_view('sharepage')) flask_app.add_url_rule('/<cookieless:sessionid>pages/<pageid>', view_func=INGIniousStaticPage.as_view('staticpage')) flask_app.add_url_rule('/<cookieless:sessionid>courselist', view_func=CourseListPage.as_view('courselistpage')) flask_app.add_url_rule('/<cookieless:sessionid>mycourses', view_func=MyCoursesPage.as_view('mycoursespage')) flask_app.add_url_rule( '/<cookieless:sessionid>preferences', view_func=PrefRedirectPage.as_view('prefredirectpage')) flask_app.add_url_rule('/<cookieless:sessionid>preferences/bindings', view_func=BindingsPage.as_view('bindingspage')) flask_app.add_url_rule('/<cookieless:sessionid>preferences/delete', view_func=DeletePage.as_view('deletepage')) flask_app.add_url_rule('/<cookieless:sessionid>preferences/profile', view_func=ProfilePage.as_view('profilepage')) flask_app.add_url_rule('/<cookieless:sessionid>lti/task', view_func=LTITaskPage.as_view('ltitaskpage')) flask_app.add_url_rule('/<cookieless:sessionid>lti/<courseid>/<taskid>', view_func=LTILaunchPage.as_view( LTILaunchPage.endpoint)) flask_app.add_url_rule('/<cookieless:sessionid>lti/bind', view_func=LTIBindPage.as_view('ltibindpage')) flask_app.add_url_rule('/<cookieless:sessionid>lti/login', view_func=LTILoginPage.as_view('ltiloginpage')) flask_app.add_url_rule('/<cookieless:sessionid>lti/asset/<path:asset_url>', view_func=LTIAssetPage.as_view('ltiassetpage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>', view_func=CourseRedirectPage.as_view('courseredirect')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/settings', view_func=CourseSettingsPage.as_view('coursesettingspage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/students', view_func=CourseStudentListPage.as_view('coursestudentlistpage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/student/<username>', view_func=CourseStudentInfoPage.as_view('coursestudentinfopage')) flask_app.add_url_rule('/<cookieless:sessionid>submission/<submissionid>', view_func=SubmissionPage.as_view('submissionpage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/submissions', view_func=CourseSubmissionsPage.as_view('coursesubmissionspage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/tasks', view_func=CourseTaskListPage.as_view('coursetasklistpage')) flask_app.add_url_rule('/<cookieless:sessionid>admin/<courseid>/tags', view_func=CourseTagsPage.as_view('coursetagspage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/edit/audience/<audienceid>', view_func=CourseEditAudience.as_view('courseditaudience')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/edit/task/<taskid>', view_func=CourseEditTask.as_view('coursedittask')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/edit/task/<taskid>/files', view_func=CourseTaskFiles.as_view('coursetaskfiles')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/edit/task/<taskid>/dd_upload', view_func=CourseTaskFileUpload.as_view('coursetaskfileupload')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/danger', view_func=CourseDangerZonePage.as_view('coursedangerzonepage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/stats', view_func=CourseStatisticsPage.as_view('coursestatisticspage')) flask_app.add_url_rule( '/<cookieless:sessionid>admin/<courseid>/search_user/<request>', view_func=CourseAdminSearchUserPage.as_view( 'courseadminsearchuserpage')) flask_app.add_url_rule('/<cookieless:sessionid>api/v0/auth_methods', view_func=APIAuthMethods.as_view('apiauthmethods')) flask_app.add_url_rule( '/<cookieless:sessionid>api/v0/authentication', view_func=APIAuthentication.as_view('apiauthentication')) flask_app.add_url_rule('/<cookieless:sessionid>api/v0/courses', view_func=APICourses.as_view('apicourses.alias'), defaults={'courseid': None}) flask_app.add_url_rule('/<cookieless:sessionid>api/v0/courses/<courseid>', view_func=APICourses.as_view('apicourses')) flask_app.add_url_rule( '/<cookieless:sessionid>api/v0/courses/<courseid>/tasks', view_func=APITasks.as_view('apitasks.alias'), defaults={'taskid': None}) flask_app.add_url_rule( '/<cookieless:sessionid>api/v0/courses/<courseid>/tasks/<taskid>', view_func=APITasks.as_view('apitasks')) flask_app.add_url_rule( '/<cookieless:sessionid>api/v0/courses/<courseid>/tasks/<taskid>/submissions', view_func=APISubmissions.as_view('apisubmissions.alias')) flask_app.add_url_rule( '/<cookieless:sessionid>api/v0/courses/<courseid>/tasks/<taskid>/submissions/<submissionid>', view_func=APISubmissionSingle.as_view('apisubmissions'))