def GET(self, *test_data):
        '''
            Retrieve and display the pairs of modules that have
            at least 1 student who has taken module A
            prior to taking module B
        '''
        is_testing = (len(test_data) > 0)
        if is_testing:
            module_A = test_data[0]
            module_B = test_data[1]
            target_ay_sem = test_data[2]
        else:
            if not session.validate_session():
                raise web.seeother('/login')
            input_data = model.validate_input(web.input(), ["moduleAandB", "aysem"],
                                              aysem_specific=False, attr_required=False)

            target_ay_sem = None
            try:
                target_ay_sem = input_data.aysem
                module_A = input_data.moduleA
                module_B = input_data.moduleB
            except AttributeError:
                module_pairs = None
                if target_ay_sem is not None:
                    module_pairs = model.get_modA_taken_prior_to_modB(target_ay_sem)

                # Get a list of all AY-Sems (for users to select)
                all_ay_sems = model.get_all_ay_sems()

                return RENDER.modulesTakenPriorToOthers("all_pairs", module_pairs, all_ay_sems,
                                                        None, None, None, None, target_ay_sem, None)


        student_counts = \
                         model.get_number_of_students_who_took_modA_prior_to_modB(module_A.upper(),
                                                                                  module_B.upper(),
                                                                                  target_ay_sem)
        module_B_students = \
                            model.get_number_of_students_taking_module_in_ay_sem(module_B.upper(),
                                                                                 target_ay_sem)

        student_prior_count = 0
        for count in student_counts:
            count = count[1]
            student_prior_count += count

        if is_testing:
            return [student_counts, student_prior_count, module_B_students]
        else:
            return RENDER.modulesTakenPriorToOthers("specific_pair", None, None, student_counts,
                                                    student_prior_count, module_A.upper(),
                                                    module_B.upper(), target_ay_sem,
                                                    module_B_students)
    def GET(self):
        '''
            Retrieve and render all the info of a module mounting
        '''
        if not session.validate_session():
            raise web.seeother('/login')

        input_data = model.validate_input(web.input(), ["code", "aysem"])
        module_code = input_data.code
        ay_sem = input_data.aysem

        # Get module's name, description, MC and status
        module_info = model.get_module(module_code)

        # Get mounting status, quota and number of students taking
        self.load_mounting_info(module_code, ay_sem)
        student_count = model.get_number_of_students_taking_module_in_ay_sem(
            module_code, ay_sem)

        # Check if the selected AY-Sem is in the current AY
        # (To determine whether to display the 'Edit Specific Info' button)
        is_future_ay = not self.is_current_ay

        # Check if module is starred
        is_starred = model.is_module_starred(module_code,
                                             web.cookies().get('user'))

        # Get the year of study and focus area distriubtions of students taking the module
        # (To be rendered as charts)
        self.load_focus_areas()
        self.load_student_enrollments(module_code, ay_sem)

        all_ay_sems = model.get_all_ay_sems()
        all_future_ay_sems = model.get_all_future_ay_sems()

        return RENDER.individualModuleInfo(
            module_info, all_ay_sems, all_future_ay_sems, is_future_ay, ay_sem,
            self.mounting_status, self.quota, student_count, is_starred,
            self.focus_areas, self.focus_area_acronyms,
            self.student_year_counts, self.focus_area_counts)
    def GET(self):
        '''
            Renders the modules page if users requested
            for the page through the GET method.
        '''
        if not session.validate_session():
            raise web.seeother('/login')

        input_data = model.validate_input(web.input(), ["aysem"],
                                          aysem_specific=False,
                                          attr_required=False)
        try:
            target_ay_sem = input_data.aysem
        except AttributeError:
            target_ay_sem = model.get_current_ay_sem()

        lst_of_mods = model.get_all_mods_taken_together(aysem=target_ay_sem)
        # Get a list of all AY-Sems (for users to select)
        all_ay_sems = model.get_all_ay_sems()

        return RENDER.overlappingModules(lst_of_mods, all_ay_sems,
                                         target_ay_sem)
Esempio n. 4
0
    def GET(self):
        '''
            Retrieve and render all the info of a module
        '''
        if not session.validate_session():
            raise web.seeother('/login')

        input_data = model.validate_input(web.input(), ["code"])
        module_code = input_data.code

        # Get module's name, description, MC and status
        module_info = model.get_module(module_code)

        # Get mounting status, quota and number of students taking
        self.load_fixed_mounting_plan(module_code)
        self.load_tenta_mounting_plan(module_code)
        number_of_student_planning = model.get_number_students_planning(
            module_code)

        # Get module's prereqs and preclusions
        prereq_string = model.get_prerequisite_as_string(module_code)
        preclude_string = model.get_preclusion_as_string(module_code)

        # Check if module is starred
        is_starred = model.is_module_starred(module_code,
                                             web.cookies().get('user'))

        all_ay_sems = model.get_all_ay_sems()
        all_future_ay_sems = model.get_all_future_ay_sems()
        target_ay_sem = None

        #get html of overlapping modules template
        return RENDER.viewModule(module_info, all_ay_sems, all_future_ay_sems,
                                 target_ay_sem, self.fixed_mounting_plan,
                                 self.tenta_mounting_plan,
                                 number_of_student_planning, is_starred,
                                 prereq_string, preclude_string)
 def __init__(self):
     self.CURRENT_SEM = model.get_current_ay_sem()
     self.AVAILABLE_AY_SEM = model.get_all_ay_sems()
class ModuleSpecificSize(object):
    '''
        This class contains the implementations of the GET
        requests.
    '''
    all_ay_sems = model.get_all_ay_sems()

    def is_a_number(self, given_input):
        '''
            Returns true if given_input is a number (int),
            returns false otherwise.
        '''
        try:
            given_input = int(given_input)
            return True
        except ValueError:
            return False

    def is_valid_range(self, low_range, high_range):
        '''
            Returns true if given low and high ranges are valid.
            i.e. both are numbers (int), low <= high, low >= 0 and high <= 999
            Returns false otherwise.
        '''
        if not self.is_a_number(low_range) or not self.is_a_number(high_range):
            return False

        # Convert from unicode to integer
        low_range = int(low_range)
        high_range = int(high_range)

        return low_range <= high_range and low_range >= 0 and high_range <= 999

    def GET(self):
        '''
            Renders the list of modules with specific class size page if users
            requested for the page through the GET method.
        '''
        if not session.validate_session():
            raise web.seeother('/login')

        input_data = model.validate_input(web.input(), ["aysem"],
                                          aysem_specific=False,
                                          attr_required=False)
        try:
            # Search request by user
            ay_sem_of_interest = input_data.aysem
            lower_range_class_size = input_data.lowerClassSize
            higher_range_class_size = input_data.higherClassSize
        except AttributeError:
            # Loading the page without sufficient data (first time load page)
            current_aysem = model.get_current_ay_sem()
            return RENDER.moduleSpecificSize(self.all_ay_sems, None,
                                             current_aysem, None, None)

        if not self.is_valid_range(lower_range_class_size,
                                   higher_range_class_size):
            return Outcome().POST("mods-specific-size-range", False, None)
        else:
            # All inputs are valid
            # Convert unicode to int
            lower_range = int(lower_range_class_size)
            higher_range = int(higher_range_class_size)

            list_of_mods = \
                model.get_mod_specified_class_size(ay_sem_of_interest, lower_range,
                                                   higher_range)

            return RENDER.moduleSpecificSize(self.all_ay_sems, list_of_mods,
                                             ay_sem_of_interest, lower_range,
                                             higher_range)

    def POST(self):
        '''
            called from search with form
        '''
        # Input data will have valid inputs as function is called from submit button
        input_data = model.validate_input(web.input(), ["aysem"])
        try:
            ay_sem_of_interest = input_data.aysem
            lower_range_class_size = input_data.lowerClassSize
            higher_range_class_size = input_data.higherClassSize
        except AttributeError:
            error = RENDER.notfound(
                'Please do not tamper with our html forms. Thank you! ;)')
            raise web.notfound(error)

        webpage_to_redirect = "/moduleSpecificSize?aysem=" + ay_sem_of_interest + \
                              "&lowerClassSize=" + lower_range_class_size + \
                              "&higherClassSize=" + higher_range_class_size

        raise web.seeother(webpage_to_redirect)
Esempio n. 7
0
    def GET(self, *test_data):
        '''
            Renders the oversubscribed modules page if users requested
            for the page through the GET method.
        '''
        if test_data:
            target_ay_sem = test_data[0]
        else:
            if not session.validate_session():
                raise web.seeother('/login')

            input_data = model.validate_input(web.input(), ["aysem"],
                                              aysem_specific=False,
                                              attr_required=False)
            try:
                target_ay_sem = input_data.aysem
            except AttributeError:
                target_ay_sem = model.get_current_ay_sem()

        all_ay_sems = model.get_all_ay_sems()

        #list_of_oversub_mod = model.get_oversub_mod()
        list_of_oversub_mod = []

        current_ay = model.get_current_ay()
        if target_ay_sem[0:8] == current_ay:

            fixed_mounting_handler = Fixed()
            fixed_mounting_handler.GET(to_render=False, logged_in=True)
            full_mounting_plan = fixed_mounting_handler.full_mounting_plan

            if target_ay_sem[9:15] == "Sem 1":
                for subplan in full_mounting_plan:
                    module_code = subplan[0]
                    module_name = subplan[1]
                    sem1_quota = subplan[4]
                    sem1_num_students = subplan[6]
                    if ((sem1_quota != '?' and sem1_quota != '-') \
                        and sem1_num_students > sem1_quota) \
                        or ((sem1_quota == '?' or sem1_quota == '-') and sem1_num_students > 0):
                        if sem1_quota == '?' or sem1_quota == '-':
                            oversub_amount = sem1_num_students
                        else:
                            oversub_amount = sem1_num_students - sem1_quota
                        list_of_oversub_mod.append(
                            (module_code, module_name, target_ay_sem,
                             sem1_quota, sem1_num_students, oversub_amount))

            else:
                for subplan in full_mounting_plan:
                    module_code = subplan[0]
                    module_name = subplan[1]
                    sem2_quota = subplan[5]
                    sem2_num_students = subplan[7]
                    if ((sem2_quota != '?' and sem2_quota != '-') \
                        and sem2_num_students > sem2_quota) \
                        or ((sem2_quota == '?' or sem2_quota == '-') and sem2_num_students > 0):
                        if sem2_quota == '?' or sem2_quota == '-':
                            oversub_amount = sem2_num_students
                        else:
                            oversub_amount = sem2_num_students - sem2_quota
                        list_of_oversub_mod.append(
                            (module_code, module_name, target_ay_sem,
                             sem2_quota, sem2_num_students, oversub_amount))

        else:
            tenta_mounting_handler = Tentative()
            tenta_mounting_handler.GET(to_render=False, logged_in=True)
            full_mounting_plan = tenta_mounting_handler.full_mounting_plan

            if target_ay_sem[9:15] == "Sem 1":
                for subplan in full_mounting_plan:
                    module_code = subplan[0]
                    module_name = subplan[1]
                    sem1_quota = subplan[4]
                    sem1_num_students = subplan[6]
                    if ((sem1_quota != '?' and sem1_quota != '-') \
                        and sem1_num_students > sem1_quota) \
                        or ((sem1_quota == '?' or sem1_quota == '-') and sem1_num_students > 0):
                        if sem1_quota == '?' or sem1_quota == '-':
                            oversub_amount = sem1_num_students
                        else:
                            oversub_amount = sem1_num_students - sem1_quota
                        list_of_oversub_mod.append(
                            (module_code, module_name, target_ay_sem,
                             sem1_quota, sem1_num_students, oversub_amount))

            else:
                for subplan in full_mounting_plan:
                    module_code = subplan[0]
                    module_name = subplan[1]
                    sem2_quota = subplan[5]
                    sem2_num_students = subplan[7]
                    if ((sem2_quota != '?' and sem2_quota != '-') \
                        and sem2_num_students > sem2_quota) \
                        or ((sem2_quota == '?' or sem2_quota == '-') and sem2_num_students > 0):
                        if sem2_quota == '?' or sem2_quota == '-':
                            oversub_amount = sem2_num_students
                        else:
                            oversub_amount = sem2_num_students - sem2_quota
                        list_of_oversub_mod.append(
                            (module_code, module_name, target_ay_sem,
                             sem2_quota, sem2_num_students, oversub_amount))

        if not test_data:
            return RENDER.oversubscribedModules(list_of_oversub_mod,
                                                all_ay_sems, target_ay_sem)
        else:
            return list_of_oversub_mod