def __init__(self, courseid, content, template_content, course_fs, task_factory, hook_manager): super(WebAppTemplate, self).__init__(courseid, content, template_content, course_fs, task_factory, hook_manager) try: self._name = self._content['name'] except: raise Exception("Template has an invalid name: " + self.get_id()) if self._content.get('nofrontend', False): raise Exception("That template is not allowed to be displayed directly in the webapp") try: self._editors = self._content.get("editors", []) self._description = self._content.get('description', '') self._private = self._content.get("private", True) self._tags = {key: Tag(key, tag_dict, self.gettext) for key, tag_dict in self._content.get("tags", {}).items()} except: raise Exception("Template has an invalid YAML spec: " + self.get_id()) try: short_desc = self._template_content.get("short_description", "No description available.") self._short_description = short_desc[:250] if len(short_desc) > 250 else short_desc self._template_description = self._template_content.get("description", "No description available.") self._template_skills = self._template_content.get("skills", []) except: raise Exception("Template has an invalid description: " + self.get_id()) self.course_page = "template" self.admin_page = "edit_template" self.has_student = False
def __init__(self, course, taskid, content, task_fs, hook_manager, task_problem_types=None): # We load the descriptor of the task here to allow plugins to modify settings of the task before it is read by the Task constructor if not id_checker(taskid): raise Exception("Task with invalid id: " + course.get_id() + "/" + taskid) task_problem_types = task_problem_types or { "code": DisplayableCodeProblem, "code-file": DisplayableCodeFileProblem, "code-single-line": DisplayableCodeSingleLineProblem, "multiple-choice": DisplayableMultipleChoiceProblem, "match": DisplayableMatchProblem } super(WebAppTask, self).__init__(course, taskid, content, task_fs, hook_manager, task_problem_types) self._name = self._data.get('name', 'Task {}'.format(self.get_id())) self._context = self._data.get('context', "") # Authors if isinstance(self._data.get('author'), str): # verify if author is a string self._author = self._data['author'] else: self._author = "" # Submission storage self._stored_submissions = int(self._data.get("stored_submissions", 0)) # Default download self._evaluate = self._data.get("evaluate", "best") # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Group task self._groups = bool(self._data.get("groups", False)) # Submission limits self._submission_limit = self._data.get("submission_limit", { "amount": -1, "period": -1 }) # Tags self._tags = Tag.create_tags_from_dict(self._data.get("tags", {}))
def __init__(self, course, taskid, content, task_fs, translations_fs, hook_manager, task_problem_types): # We load the descriptor of the task here to allow plugins to modify settings of the task before it is read by the Task constructor if not id_checker(taskid): raise Exception("Task with invalid id: " + course.get_id() + "/" + taskid) super(WebAppTask, self).__init__(course, taskid, content, task_fs, translations_fs, hook_manager, task_problem_types) self._name = self._data.get('name', 'Task {}'.format(self.get_id())) self._context = self._data.get('context', "") # Authors if isinstance(self._data.get('author'), str): # verify if author is a string self._author = self._data['author'] else: self._author = "" # Submission storage self._stored_submissions = int(self._data.get("stored_submissions", 0)) # Default download self._evaluate = self._data.get("evaluate", "best") # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Group task self._groups = bool(self._data.get("groups", False)) # Submission limits self._submission_limit = self._data.get("submission_limit", { "amount": -1, "period": -1 }) # Input random self._input_random = int(self._data.get("input_random", 0)) # Regenerate input random self._regenerate_input_random = bool( self._data.get("regenerate_input_random", False)) # Tags self._tags = Tag.create_tags_from_dict(self._data.get("tags", {}))
def __init__(self, courseid, content, course_fs, task_factory, hook_manager): super(WebAppCourse, self).__init__(courseid, content, course_fs, task_factory, hook_manager) try: self._name = self._content['name'] except: raise Exception("Course has an invalid name: " + self.get_id()) if self._content.get('nofrontend', False): raise Exception("That course is not allowed to be displayed directly in the webapp") try: self._admins = self._content.get('admins', []) self._tutors = self._content.get('tutors', []) self._description = self._content.get('description', '') self._accessible = AccessibleTime(self._content.get("accessible", None)) self._registration = AccessibleTime(self._content.get("registration", None)) self._registration_password = self._content.get('registration_password', None) self._registration_ac = self._content.get('registration_ac', None) if self._registration_ac not in [None, "username", "binding", "email"]: raise Exception("Course has an invalid value for registration_ac: " + self.get_id()) self._registration_ac_list = self._content.get('registration_ac_list', []) self._groups_student_choice = self._content.get("groups_student_choice", False) self._allow_unregister = self._content.get('allow_unregister', True) self._allow_preview = self._content.get('allow_preview', False) self._is_lti = self._content.get('is_lti', False) self._lti_url = self._content.get('lti_url', '') self._lti_keys = self._content.get('lti_keys', {}) self._lti_send_back_grade = self._content.get('lti_send_back_grade', False) self._tags = {key: Tag(key, tag_dict, self.gettext) for key, tag_dict in self._content.get("tags", {}).items()} except: raise Exception("Course has an invalid YAML spec: " + self.get_id()) # Force some parameters if LTI is active if self.is_lti(): self._accessible = AccessibleTime(True) self._registration = AccessibleTime(False) self._registration_password = None self._registration_ac = None self._registration_ac_list = [] self._groups_student_choice = False self._allow_unregister = False else: self._lti_keys = {} self._lti_url = '' self._lti_send_back_grade = False self.course_page = "course" self.admin_page = "admin" self.has_student = True
def __init__(self, course, taskid, content, task_fs, translations_fs, hook_manager, task_problem_types): # We load the descriptor of the task here to allow plugins to modify settings of the task before it is read by the Task constructor if not id_checker(taskid): raise Exception("Task with invalid id: " + course.get_id() + "/" + taskid) super(WebAppTask, self).__init__(course, taskid, content, task_fs, translations_fs, hook_manager, task_problem_types) self._name = self._data.get('name', 'Task {}'.format(self.get_id())) self._context = self._data.get('context', "") # Authors if isinstance(self._data.get('author'), str): # verify if author is a string self._author = self._data['author'] else: self._author = "" # Submission storage self._stored_submissions = int(self._data.get("stored_submissions", 0)) # Default download self._evaluate = self._data.get("evaluate", "best") # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Group task self._groups = bool(self._data.get("groups", False)) # Submission limits self._submission_limit = self._data.get("submission_limit", {"amount": -1, "period": -1}) # Input random self._input_random = int(self._data.get("input_random", 0)) # Regenerate input random self._regenerate_input_random = bool(self._data.get("regenerate_input_random", False)) # Tags self._tags = Tag.create_tags_from_dict(self._data.get("tags", {}))
def __init__(self, courseid, content, course_fs, task_factory, plugin_manager, task_dispensers): self._id = courseid self._content = content self._fs = course_fs self._task_factory = task_factory self._plugin_manager = plugin_manager self._translations = {} translations_fs = self._fs.from_subfolder("$i18n") if translations_fs.exists(): for f in translations_fs.list(folders=False, files=True, recursive=False): lang = f[0:len(f) - 3] if translations_fs.exists(lang + ".mo"): self._translations[lang] = gettext.GNUTranslations(translations_fs.get_fd(lang + ".mo")) else: self._translations[lang] = gettext.NullTranslations() try: self._name = self._content['name'] except: raise Exception("Course has an invalid name: " + self.get_id()) if self._content.get('nofrontend', False): raise Exception("That course is not allowed to be displayed directly in the webapp") _migrate_from_v_0_6(content, self._task_factory.get_all_tasks(self)) try: self._admins = self._content.get('admins', []) self._tutors = self._content.get('tutors', []) self._description = self._content.get('description', '') self._accessible = AccessibleTime(self._content.get("accessible", None)) self._registration = AccessibleTime(self._content.get("registration", None)) self._registration_password = self._content.get('registration_password', None) self._registration_ac = self._content.get('registration_ac', None) if self._registration_ac not in [None, "username", "binding", "email"]: raise Exception("Course has an invalid value for registration_ac: " + self.get_id()) self._registration_ac_list = self._content.get('registration_ac_list', []) self._groups_student_choice = self._content.get("groups_student_choice", False) self._allow_unregister = self._content.get('allow_unregister', True) self._allow_preview = self._content.get('allow_preview', False) self._is_lti = self._content.get('is_lti', False) self._lti_url = self._content.get('lti_url', '') self._lti_keys = self._content.get('lti_keys', {}) self._lti_send_back_grade = self._content.get('lti_send_back_grade', False) self._tags = {key: Tag(key, tag_dict, self.gettext) for key, tag_dict in self._content.get("tags", {}).items()} task_dispenser_class = task_dispensers.get(self._content.get('task_dispenser', 'toc'), TableOfContents) # Here we use a lambda to encourage the task dispenser to pass by the task_factory to fetch course tasks # to avoid them to be cached along with the course object. Passing the task factory as argument # would require to pass the course too, and have a useless reference back. self._task_dispenser = task_dispenser_class(lambda: self._task_factory.get_all_tasks(self), self._content.get("dispenser_data", '')) except: raise Exception("Course has an invalid YAML spec: " + self.get_id()) # Force some parameters if LTI is active if self.is_lti(): self._accessible = AccessibleTime(True) self._registration = AccessibleTime(False) self._registration_password = None self._registration_ac = None self._registration_ac_list = [] self._groups_student_choice = False self._allow_unregister = False else: self._lti_keys = {} self._lti_url = '' self._lti_send_back_grade = False # Build the regex for the ACL, allowing for fast matching. Only used internally. self._registration_ac_regex = self._build_ac_regex(self._registration_ac_list)
def __init__(self, courseid, content, course_fs, task_factory, plugin_manager): self._id = courseid self._content = content self._fs = course_fs self._task_factory = task_factory self._plugin_manager = plugin_manager self._translations = {} translations_fs = self._fs.from_subfolder("$i18n") if translations_fs.exists(): for f in translations_fs.list(folders=False, files=True, recursive=False): lang = f[0:len(f) - 3] if translations_fs.exists(lang + ".mo"): self._translations[lang] = gettext.GNUTranslations( translations_fs.get_fd(lang + ".mo")) else: self._translations[lang] = gettext.NullTranslations() try: self._name = self._content['name'] except: raise Exception("Course has an invalid name: " + self.get_id()) if self._content.get('nofrontend', False): raise Exception( "That course is not allowed to be displayed directly in the webapp" ) try: self._admins = self._content.get('admins', []) self._tutors = self._content.get('tutors', []) self._description = self._content.get('description', '') self._accessible = AccessibleTime( self._content.get("accessible", None)) self._registration = AccessibleTime( self._content.get("registration", None)) self._registration_password = self._content.get( 'registration_password', None) self._registration_ac = self._content.get('registration_ac', None) if self._registration_ac not in [ None, "username", "binding", "email" ]: raise Exception( "Course has an invalid value for registration_ac: " + self.get_id()) self._registration_ac_list = self._content.get( 'registration_ac_list', []) self._groups_student_choice = self._content.get( "groups_student_choice", False) self._allow_unregister = self._content.get('allow_unregister', True) self._allow_preview = self._content.get('allow_preview', False) self._is_lti = self._content.get('is_lti', False) self._lti_url = self._content.get('lti_url', '') self._lti_keys = self._content.get('lti_keys', {}) self._lti_send_back_grade = self._content.get( 'lti_send_back_grade', False) self._tags = { key: Tag(key, tag_dict, self.gettext) for key, tag_dict in self._content.get("tags", {}).items() } if 'toc' in self._content: self._toc = SectionsList(self._content['toc']) else: tasks = self._task_factory.get_all_tasks(self) ordered_task_list = OrderedDict( sorted(list(tasks.items()), key=lambda t: (t[1].get_old_order(), t[1].get_id()))) indexed_task_list = { taskid: rank for rank, taskid in enumerate(ordered_task_list.keys()) } self._toc = SectionsList([{ "id": "tasks-list", "title": _("List of exercises"), "rank": 0, "tasks_list": indexed_task_list }]) except: raise Exception("Course has an invalid YAML spec: " + self.get_id()) # Force some parameters if LTI is active if self.is_lti(): self._accessible = AccessibleTime(True) self._registration = AccessibleTime(False) self._registration_password = None self._registration_ac = None self._registration_ac_list = [] self._groups_student_choice = False self._allow_unregister = False else: self._lti_keys = {} self._lti_url = '' self._lti_send_back_grade = False