예제 #1
0
    def post(self):
        # get the POST data
        students_obj_args = STUDENT_PARSER.parse_args()
        if StudentsModel.find_student_by_adm(students_obj_args['student_adm']):
            # duplicate student was found in database
            # return an error message to client
            response_obj = {
                'status': 'failed',
                'message': 'The student has already been registered'
            }
            return make_response(jsonify(response_obj), 202)

        # validation passed, proceeding with registration"""
        new_student = StudentsModel(
            students_obj_args['student_adm'],
            students_obj_args['first_name'],
            students_obj_args['last_name'],
            students_obj_args['project_code'],
            False  # by default, the student is unallocated ( boolean column )
        )
        new_student.add_student()
        db.session.commit()
        # student has been successfully saved to the database
        # respond with a success message
        response_obj = {
            'status':
            'success',
            'message':
            '{} {} has been saved to database'.format(
                students_obj_args['first_name'],
                students_obj_args['last_name'])
        }

        return make_response(jsonify(response_obj), 200)
예제 #2
0
    def post(self):
        # this defines the file upload method of registration
        # get the csv data and convert into a multidimensional array
        students_data = helpers.csv_to_json()
        for student in students_data:
            try:
                # create student objects from Students model
                new_student = StudentsModel(student[0], student[1], student[2],
                                            student[3], False)
                # queue students data for commit
                new_student.add_student()
            except IntegrityError:
                # Duplicate data was encountered
                # Roll back all queued data and return an error
                # prompt for a fresh upload of csv file
                db.session.rollback()
                response_obj = {
                    'status':
                    'failed',
                    'message':
                    'A duplicate entry was found; {}, Please remove duplicate and upload again'
                    .format(student[0])
                }
                return make_response(jsonify(response_obj))

        # All data was successfully stored in cache
        # commit flushed data and respond with a success message
        db.session.commit()
        response_obj = {
            'status': 'success',
            'message': 'Students were successfully added'
        }

        return make_response(jsonify(response_obj), 200)
예제 #3
0
 def get(self):
     """count details in dashboard"""
     no_of_supervisors = SupervisorsModel.count_supervisors()
     no_of_unallocated_students = StudentsModel.count_unallocated_students()
     no_of_diploma_students = StudentsModel.count_diploma_students()
     no_of_degree_students = StudentsModel.count_degree_students()
     response_obj = {
         "supervisors_count": no_of_supervisors,
         "unallocated_students_count": no_of_unallocated_students,
         "diploma_students_count": no_of_diploma_students,
         "degree_students_count": no_of_degree_students
     }
     return make_response(jsonify(response_obj), 200)
예제 #4
0
    def get(self):
        # get all students and lecturers with course as common factor
        students_db_rows = StudentsModel.fetch_all_unallocated_students()
        student_data = [{
            "name":
            "{} {}".format(student.first_name, student.last_name),
            "adm":
            student.student_adm,
            "course":
            "degree" if student.projects.degree else "diploma"
        } for student in students_db_rows]

        supervisors_db_rows = SupervisorsModel.fetch_all_supervisors()
        supervisors_data = [{
            "name":
            "{} {}".format(supervisor.first_name, supervisor.last_name),
            "supervisor_id":
            supervisor.supervisor_id,
            "course":
            helpers.determine_supervisor_course(supervisor.degree,
                                                supervisor.diploma),
            "allocations_count":
            AllocationsModel.count_allocations(supervisor.supervisor_id)
        } for supervisor in supervisors_db_rows]

        response_obj = {
            "students": student_data,
            "supervisors": supervisors_data
        }

        return make_response(jsonify(response_obj), 200)
예제 #5
0
    def post(self):
        """
        save allocations to database
        """
        # get the allocation details from request
        allocation_details = ALLOCATIONS_PARSER.parse_args()
        # get associated student data
        student_db_details = StudentsModel.find_student_by_adm(
            allocation_details['student_adm'])

        # get associated project data
        project_db_details = ProjectsModel.fetch_project_by_code(
            student_db_details.project_code)
        no_of_trimesters = int(project_db_details.trimesters)
        curr_month = int(helpers.date_today_month())
        due_date = helpers.find_due_date(no_of_trimesters, curr_month)
        full_date_registered = helpers.date_today()

        new_allocation = AllocationsModel(allocation_details['allocation_id'],
                                          allocation_details['supervisor_id'],
                                          allocation_details['student_adm'],
                                          project_db_details.project_code,
                                          full_date_registered, due_date)
        new_allocation.save_allocation()

        # allocation successfully saved, update student's allocated status to True
        student_db_details.allocated = True
        student_db_details.update_student()

        response_obj = {
            'status': 'success',
            'message': 'Allocation has been successfully made'
        }
        return make_response(jsonify(response_obj), 200)
예제 #6
0
    def delete(self, supervisor_id):
        """delete supervisor from database based on supervisor_id"""
        supervisor_db_details = SupervisorsModel.find_supervisor_by_id(
            supervisor_id)

        if supervisor_db_details:
            # get all associated students in the allocations table
            allocation_rows = AllocationsModel.fetch_allocation_by_supervisor_id(
                supervisor_id)
            for row in allocation_rows:
                students_row = StudentsModel.find_student_by_adm(
                    row.student_adm)
                # update student allocation status to false
                students_row.allocated = False
                students_row.update_student()

            supervisor_db_details.remove_supervisor()
            response_obj = {
                'status': 'success',
                'message': 'Supervisor was successfully deleted!'
            }
            return make_response(jsonify(response_obj), 200)

        response_obj = {
            'status': 'failed',
            'message': 'Supervisor was not found!'
        }
        return make_response(jsonify(response_obj), 404)
예제 #7
0
    def get(self):
        """Get the students associated with the supervisor"""
        supervisor_id = get_jwt_identity()
        allocation_rows = AllocationsModel.fetch_allocation_by_supervisor_id(
            supervisor_id)
        students_data = []
        for row in allocation_rows:
            student_row = StudentsModel.find_student_by_adm(row.student_adm)
            students_data.append({
                "student_name":
                "{} {}".format(student_row.first_name, student_row.last_name),
                "project_code":
                student_row.project_code,
                "allocation_id":
                row.allocation_id,
                "date_registered":
                row.date_registered,
                "due_date":
                row.due_date
            })

        if len(students_data) > 0:
            return make_response(jsonify(students_data), 200)

        response_obj = {'status': 'failed', 'message': 'no data found'}
        return make_response(jsonify(response_obj), 404)
예제 #8
0
    def delete(self, student_adm):
        """student deletion resource"""
        """delete student from database based on emp_no"""
        student_db_details = StudentsModel.find_student_by_adm(student_adm)

        if student_db_details:
            student_db_details.remove_student()
            response_obj = {'status': 'success', 'message': 'Student deleted!'}
            return make_response(jsonify(response_obj), 200)

        response_obj = {
            'status': 'failed',
            'message': 'Student was not found!'
        }
        return make_response(jsonify(response_obj), 404)
예제 #9
0
    def get(self, student_adm=None):
        if student_adm is None:
            students_details = StudentsModel.fetch_all_unallocated_students()
            if students_details:
                unallocated_students = [{
                    'student_adm':
                    student.student_adm,
                    'name':
                    "{} {}".format(student.first_name, student.last_name),
                    'project_code':
                    student.project_code,
                } for student in students_details]
                # student table is not empty
                # respond with student data
                return make_response(jsonify(unallocated_students), 200)

            # students not found in the database
            response_obj = {
                'status': 'failed',
                'message': 'No students in the database'
            }
            return make_response(jsonify(response_obj), 404)
예제 #10
0
    def post(self):
        """
        mark project as completed
        archive the allocation and delete the associated data
        :return:
        """
        allocation_detail = ARCHIVES_PARSER.parse_args()
        allocation_db_row = AllocationsModel.fetch_allocation_by_id(
            allocation_detail['allocation_id'])
        if allocation_db_row:
            # get the associated student and supervisor row
            student_db_details = StudentsModel.find_student_by_adm(
                allocation_db_row.student_adm)
            supervisor_db_details = SupervisorsModel.find_supervisor_by_id(
                allocation_db_row.supervisor_id)
            # store the archive details
            new_archive = ArchivesModel(
                allocation_detail['archive_id'], allocation_db_row.student_adm,
                "{} {}".format(student_db_details.first_name,
                               student_db_details.last_name),
                "{} {}".format(supervisor_db_details.first_name,
                               supervisor_db_details.last_name),
                allocation_db_row.project_code,
                allocation_db_row.date_registered, allocation_db_row.due_date)
            new_archive.add_archive()
            # archive details stored, proceed to delete the all associated data (student, allocation, progress)
            allocation_db_row.remove_allocation()
            student_db_details.remove_student()
            response_obj = {
                'status': 'success',
                'message': 'archive was successfully made'
            }
            return make_response(jsonify(response_obj), 200)

        # archive process completed, return error message
        response_obj = {'status': 'failed', 'message': 'An error occured'}
        return make_response(jsonify(response_obj), 404)
예제 #11
0
    def put(self):
        student_obj_args = STUDENT_PARSER.parse_args()
        student_db_details = StudentsModel.find_student_by_adm(
            student_obj_args['student_adm'])
        if student_db_details:
            student_db_details.first_name = student_obj_args['first_name']
            student_db_details.last_name = student_obj_args['last_name']
            student_db_details.project_code = student_obj_args['project_code']
            student_db_details.update_student()
            response_obj = {
                'status':
                'success',
                'message':
                "{} {}'s details updated".format(
                    student_obj_args['first_name'],
                    student_obj_args['last_name'])
            }
            return make_response(jsonify(response_obj), 200)

        response_obj = {  # student was not found, respond with an error message
            'status': 'failed',
            'message': 'The student was not found'
        }
        return make_response(jsonify(response_obj), 404)