def __init__(self, courseid, content, task_factory, hook_manager): super(WebAppCourse, self).__init__(courseid, content, task_factory, hook_manager) 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._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", "realname", "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._use_classrooms = self._content.get('use_classrooms', True) self._allow_unregister = self._content.get('allow_unregister', True) except: raise Exception("Course has an invalid description: " + self.get_id())
class WebAppTask(FrontendTask): """ A task that stores additional context information, specific to the web app """ def __init__(self, course, taskid, content, directory_path, task_problem_types=None): super(WebAppTask, self).__init__(course, taskid, content, directory_path, task_problem_types) # 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 }) def get_grading_weight(self): """ Get the relative weight of this task in the grading """ return self._weight def get_accessible_time(self): """ Get the accessible time of this task """ return self._accessible def is_visible_by_students(self): """ Returns true if the task is accessible by all students that are not administrator of the course """ return self.get_course().is_open_to_non_staff( ) and self._accessible.after_start() def get_deadline(self): """ Returns a string containing the deadline for this task """ if self._accessible.is_always_accessible(): return "No deadline" elif self._accessible.is_never_accessible(): return "It's too late" else: return self._accessible.get_end_date().strftime( "%d/%m/%Y %H:%M:%S") def is_group_task(self): """ Indicates if the task submission mode is per groups """ return self._groups def get_submission_limit(self): """ Returns the submission limits et for the task""" return self._submission_limit
class WebAppTask(FrontendTask): """ A task that stores additional context information, specific to the web app """ def __init__(self, course, taskid, content, directory_path, task_problem_types=None): super(WebAppTask, self).__init__(course, taskid, content, directory_path, task_problem_types) # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Order self._order = int(self._data.get('order', -1)) # Group task self._groups = bool(self._data.get("groups", False)) def get_order(self): """ Get the position of this task in the course """ return self._order def get_grading_weight(self): """ Get the relative weight of this task in the grading """ return self._weight def get_accessible_time(self): """ Get the accessible time of this task """ return self._accessible def is_visible_by_students(self): """ Returns true if the task is accessible by all students that are not administrator of the course """ return self.get_course().is_open_to_non_staff() and self._accessible.after_start() def get_deadline(self): """ Returns a string containing the deadline for this task """ if self._accessible.is_always_accessible(): return "No deadline" elif self._accessible.is_never_accessible(): return "It's too late" else: return self._accessible.get_end_date().strftime("%d/%m/%Y %H:%M:%S") def is_group_task(self): """ Indicates if the task submission mode is per groups """ return self._groups
def __init__(self, courseid, content, task_factory): super(WebAppCourse, self).__init__(courseid, content, task_factory) 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._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", "realname", "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) except: raise Exception("Course has an invalid description: " + self.get_id())
def __init__(self, course, taskid, content, directory_path, task_problem_types=None): super(WebAppTask, self).__init__(course, taskid, content, directory_path, task_problem_types) # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Order self._order = int(self._data.get('order', -1)) # Group task self._groups = bool(self._data.get("groups", False))
def __init__(self, course, taskid, content, directory_path, hook_manager, task_problem_types=None): super(WebAppTask, self).__init__(course, taskid, content, directory_path, hook_manager, task_problem_types) # 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})
def __init__(self, course, taskid, content, directory_path, task_problem_types=None): super(WebAppTask, self).__init__(course, taskid, content, directory_path, task_problem_types) # Grade weight self._weight = float(self._data.get("weight", 1.0)) # _accessible self._accessible = AccessibleTime(self._data.get("accessible", None)) # Order self._order = int(self._data.get('order', -1)) # Group task self._groups = bool(self._data.get("groups", False))
class WebAppCourse(FrontendCourse): """ A course with some modification for users """ def __init__(self, courseid, content, task_factory, hook_manager): super(WebAppCourse, self).__init__(courseid, content, task_factory, hook_manager) 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._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", "realname", "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._use_classrooms = self._content.get('use_classrooms', True) self._allow_unregister = self._content.get('allow_unregister', True) except: raise Exception("Course has an invalid description: " + self.get_id()) def get_staff(self): """ Returns a list containing the usernames of all the staff users """ return list(set(self.get_tutors() + self.get_admins())) def get_admins(self): """ Returns a list containing the usernames of the administrators of this course """ return self._admins def get_tutors(self): """ Returns a list containing the usernames of the tutors assigned to this course """ return self._tutors def is_open_to_non_staff(self): """ Returns true if the course is accessible by users that are not administrator of this course """ return self.get_accessibility().is_open() def is_registration_possible(self, username, realname, email): """ Returns true if users can register for this course """ return self.get_accessibility().is_open( ) and self._registration.is_open( ) and self.is_user_accepted_by_access_control(username, realname, email) def is_password_needed_for_registration(self): """ Returns true if a password is needed for registration """ return self._registration_password is not None def get_registration_password(self): """ Returns the password needed for registration (None if there is no password) """ return self._registration_password def get_accessibility(self, plugin_override=True): """ Return the AccessibleTime object associated with the accessibility of this course """ vals = self._hook_manager.call_hook('course_accessibility', course=self, default=self._accessible) return vals[0] if len(vals) and plugin_override else self._accessible def get_registration_accessibility(self): """ Return the AccessibleTime object associated with the registration """ return self._registration def get_tasks(self): return OrderedDict( sorted(list(Course.get_tasks(self).items()), key=lambda t: (t[1].get_order(), t[1].get_id()))) def get_access_control_method(self): """ Returns either None, "username", "realname", or "email", depending on the method used to verify that users can register to the course """ return self._registration_ac def get_access_control_list(self): """ Returns the list of all users allowed by the AC list """ return self._registration_ac_list def can_students_choose_group(self): """ Returns True if the students can choose their groups """ return self._groups_student_choice def use_classrooms(self): """ Returns True if classrooms are used """ return self._use_classrooms def is_user_accepted_by_access_control(self, username, realname, email): """ Returns True if the user is allowed by the ACL """ if self.get_access_control_method() is None: return True elif self.get_access_control_method() == "username": return username in self.get_access_control_list() elif self.get_access_control_method() == "realname": return realname in self.get_access_control_list() elif self.get_access_control_method() == "email": return email in self.get_access_control_list() return False def allow_unregister(self, plugin_override=True): """ Returns True if students can unregister from course """ vals = self._hook_manager.call_hook('course_allow_unregister', course=self, default=self._allow_unregister) return vals[0] if len( vals) and plugin_override else self._allow_unregister
class WebAppCourse(FrontendCourse): """ A course with some modification for users """ def __init__(self, courseid, content, task_factory): super(WebAppCourse, self).__init__(courseid, content, task_factory) 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._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", "realname", "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) except: raise Exception("Course has an invalid description: " + self.get_id()) def get_staff(self): """ Returns a list containing the usernames of all the staff users """ return list(set(self.get_tutors() + self.get_admins())) def get_admins(self): """ Returns a list containing the usernames of the administrators of this course """ return self._admins def get_tutors(self): """ Returns a list containing the usernames of the tutors assigned to this course """ return self._tutors def is_open_to_non_staff(self): """ Returns true if the course is accessible by users that are not administrator of this course """ return self._accessible.is_open() def is_registration_possible(self, username, realname, email): """ Returns true if users can register for this course """ return self._accessible.is_open() and self._registration.is_open() and self.is_user_accepted_by_access_control(username, realname, email) def is_password_needed_for_registration(self): """ Returns true if a password is needed for registration """ return self._registration_password is not None def get_registration_password(self): """ Returns the password needed for registration (None if there is no password) """ return self._registration_password def get_accessibility(self): """ Return the AccessibleTime object associated with the accessibility of this course """ return self._accessible def get_registration_accessibility(self): """ Return the AccessibleTime object associated with the registration """ return self._registration def get_tasks(self): return OrderedDict(sorted(Course.get_tasks(self).items(), key=lambda t: t[1].get_order())) def get_access_control_method(self): """ Returns either None, "username", "realname", or "email", depending on the method used to verify that users can register to the course """ return self._registration_ac def get_access_control_list(self): """ Returns the list of all users allowed by the AC list """ return self._registration_ac_list def can_students_choose_group(self): """ Returns True if the students can choose their groups """ return self._groups_student_choice def is_user_accepted_by_access_control(self, username, realname, email): """ Returns True if the user is allowed by the ACL """ if self.get_access_control_method() is None: return True elif self.get_access_control_method() == "username": return username in self.get_access_control_list() elif self.get_access_control_method() == "realname": return realname in self.get_access_control_list() elif self.get_access_control_method() == "email": return email in self.get_access_control_list() return False
def POST_AUTH(self, courseid): # pylint: disable=arguments-differ """ POST request """ course, _ = self.get_course_and_check_rights(courseid, allow_all_staff=False) errors = [] course_content = {} try: data = web.input() course_content = self.course_factory.get_course_descriptor_content( courseid) course_content['name'] = data['name'] if course_content['name'] == "": errors.append('Invalid name') course_content['admins'] = list( map(str.strip, data['admins'].split(','))) if not self.user_manager.user_is_superadmin( ) and self.user_manager.session_username( ) not in course_content['admins']: errors.append( 'You cannot remove yourself from the administrators of this course' ) course_content['tutors'] = list( map(str.strip, data['tutors'].split(','))) if len(course_content['tutors'] ) == 1 and course_content['tutors'][0].strip() == "": course_content['tutors'] = [] course_content['groups_student_choice'] = True if data[ "groups_student_choice"] == "true" else False if course_content.get('use_classrooms', True) != (data['use_classrooms'] == "true"): self.database.aggregations.delete_many( {"courseid": course.get_id()}) course_content['use_classrooms'] = True if data[ "use_classrooms"] == "true" else False if data["accessible"] == "custom": course_content['accessible'] = "{}/{}".format( data["accessible_start"], data["accessible_end"]) elif data["accessible"] == "true": course_content['accessible'] = True else: course_content['accessible'] = False try: AccessibleTime(course_content['accessible']) except: errors.append('Invalid accessibility dates') course_content['allow_unregister'] = True if data[ "allow_unregister"] == "true" else False if data["registration"] == "custom": course_content['registration'] = "{}/{}".format( data["registration_start"], data["registration_end"]) elif data["registration"] == "true": course_content['registration'] = True else: course_content['registration'] = False try: AccessibleTime(course_content['registration']) except: errors.append('Invalid registration dates') course_content['registration_password'] = data[ 'registration_password'] if course_content['registration_password'] == "": course_content['registration_password'] = None course_content['registration_ac'] = data['registration_ac'] if course_content['registration_ac'] not in [ "None", "username", "realname", "email" ]: errors.append('Invalid ACL value') if course_content['registration_ac'] == "None": course_content['registration_ac'] = None course_content['registration_ac_list'] = data[ 'registration_ac_list'].split("\n") except: errors.append('User returned an invalid form.') if len(errors) == 0: self.course_factory.update_course_descriptor_content( courseid, course_content) errors = None course, _ = self.get_course_and_check_rights( courseid, allow_all_staff=False ) # don't forget to reload the modified course return self.page(course, errors, errors is None)
def task_accessibility(course, _, default): contest_data = get_contest_data(course) if contest_data['enabled']: return AccessibleTime(contest_data['start'] + '/') else: return default
def POST(self, courseid): """ POST request """ course, _ = self.get_course_and_check_rights(courseid, allow_all_staff=False) errors = [] course_content = {} try: data = web.input() course_content = self.course_factory.get_course_descriptor_content( courseid) course_content['name'] = data['name'] if course_content['name'] == "": errors.append('Invalid name') course_content['admins'] = data['admins'].split(',') if self.user_manager.session_username( ) not in course_content['admins']: errors.append( 'You cannot remove yourself from the administrators of this course' ) course_content['tutors'] = data['tutors'].split(',') if len(course_content['tutors'] ) == 1 and course_content['tutors'][0].strip() == "": course_content['tutors'] = [] if data["groups_student_choice"] == "true": course_content['groups_student_choice'] = True else: course_content['groups_student_choice'] = False if data["accessible"] == "custom": course_content['accessible'] = "{}/{}".format( data["accessible_start"], data["accessible_end"]) elif data["accessible"] == "true": course_content['accessible'] = True else: course_content['accessible'] = False try: AccessibleTime(course_content['accessible']) except: errors.append('Invalid accessibility dates') if data["registration"] == "custom": course_content['registration'] = "{}/{}".format( data["registration_start"], data["registration_end"]) elif data["registration"] == "true": course_content['registration'] = True else: course_content['registration'] = False try: AccessibleTime(course_content['registration']) except: errors.append('Invalid registration dates') course_content['registration_password'] = data[ 'registration_password'] if course_content['registration_password'] == "": course_content['registration_password'] = None course_content['registration_ac'] = data['registration_ac'] if course_content['registration_ac'] not in [ "None", "username", "realname", "email" ]: errors.append('Invalid ACL value') if course_content['registration_ac'] == "None": course_content['registration_ac'] = None course_content['registration_ac_list'] = data[ 'registration_ac_list'].split("\n") except: errors.append('User returned an invalid form.') if len(errors) == 0: self.course_factory.update_course_descriptor_content( courseid, course_content) errors = None course, _ = self.get_course_and_check_rights( courseid, allow_all_staff=False ) # don't forget to reload the modified course return self.page(course, errors, errors is None)
def task_accessibility(course, task, default): # pylint: disable=unused-argument contest_data = get_contest_data(course) if contest_data['enabled']: return AccessibleTime(contest_data['start'] + '/') else: return default