def post(self):
        # parse the arguments
        args = api.payload
        args['gender'] = app.config['GENDER'](args['gender'])
        mobile_number = args['mobile_number']
        enrollment_key = args['enrollment_key']

        # check the validity of enrollment key
        result, enrollment = check_enrollment_key(enrollment_key)

        # student record shall be updated only when the key is not used and valid
        if result['valid'] and result['reason'] == 'NOT_USED':

            # updating student data
            student_id = enrollment.student_id
            student = Student.query.filter_by(id=student_id).first()
            student.update_data(args, [mobile_number])

            student.change_stage('PDS')

            return {'success': True, 'enrollment_key_status': result['reason']}

        # when the key is used but somehow student went to the this route instead of test
        elif result['valid'] and result['reason'] == 'ALREADY_IN_USED':
            return {'success': True, 'enrollment_key_status': result['reason']}

        # when the key is not valid
        return {
            'success': False,
            'enrollment_key_status': result['reason'],
        }
    def post(self):
        args = api.payload

        # check the enrollment key
        enrollment_key = args.get('enrollment_key')
        result, enrollment = check_enrollment_key(enrollment_key)

        # if enrollment doesn't exist or expired
        if not result['valid']:
            return {'error': True, 'enrollment_key_valid': False}

        # Check if only valid question IDs are there
        questions_attempt = args.get('questions_attempt')
        wrong_question_ids = check_question_ids(enrollment, questions_attempt)
        if wrong_question_ids:
            return {
                'error': True,
                'enrollment_key_valid': True,
                'invalid_question_ids': wrong_question_ids
            }

        # Create attempts in the DB
        QuestionAttempts.create_attempts(questions_attempt, enrollment)
        enrollment.end_test()
        enrollment.calculate_test_score()

        return {'success': True, 'enrollment_key_valid': True}
Exemplo n.º 3
0
    def post(self):

        args = self.post_parser.parse_args()
        args['gender'] = app.config['GENDER'](args['gender'])
        # Enrollment Key
        mobile_number = args['mobile_number']
        enrollment_key = args['enrollment_key']

        # check the validity of enrollment key
        result, enrollment = check_enrollment_key(enrollment_key)
        # student record shall be updated only when the key is not used
        if result['valid'] and result['reason'] == 'NOT_USED':
            # updating student data
            student_id = enrollment.student_id

            student = Student.query.filter_by(id=student_id).first()
            student.update_data(args)

            # creating student contact record
            student_contact = StudentContact.create(contact=mobile_number,
                                                    student_id=student_id)
            return {'success': True, 'enrollment_key_status': result['reason']}
        # when the key is used but somehow student went to the this route instead of test
        elif result['valid'] and result['reason'] == 'ALREADY_IN_USED':
            return {'success': True, 'enrollment_key_status': result['reason']}
        # when the key is not valid
        return {
            'success': False,
            'enrollment_key_status': result['reason'],
        }
Exemplo n.º 4
0
    def post(self):

        args = api.payload

        # check the enrollment key
        enrollment_key = args.get('enrollment_key')
        result, enrollment = check_enrollment_key(enrollment_key)

        # if enrollment doesn't exist or expired
        if not result['valid']:
            return {'error': True, 'enrollment_key_valid': False}
        #add questions to db
        questions_attempted = args.get('question_attempted')
        # is_question_ids_correct = check_question_ids(questions_attempted)
        wrong_question_ids = check_question_ids(questions_attempted,
                                                enrollment)

        if wrong_question_ids:
            return {
                'error': True,
                'enrollment_key_valid': True,
                'invalid_question_ids': wrong_question_ids
            }

        QuestionAttempts.create_attempts(questions_attempted, enrollment)
        enrollment.end_test()

        return {'success': True}
    def post(self):

        args = api.payload
        enrollment_key = args.get('enrollment_key')

        result, enrollment = check_enrollment_key(enrollment_key)

        # if the enrollment_key does't exist
        if result['reason'] == 'DOES_NOT_EXIST':
            return {'error': True, 'message': "KEY_DOESN'T_EXIST"}

        # update the data of the student
        student = enrollment.student
        student.update_data(args)

        student.change_stage('ETA')

        return {'success': True}
Exemplo n.º 6
0
    def post(self):

        args = api.payload
        enrollment_key = args.get('enrollment_key')

        result, enrollment = check_enrollment_key(enrollment_key)

        # if the enrollment_key does't exist
        if not result['valid'] and result['reason'] == 'DOES_NOT_EXIST':
            return {'error': True, 'message': "KEY_DOESN'T_EXIST"}
        # if the key is expired it means has given examination and can fill the more details
        if not result['valid'] and result['reason'] == 'EXPIRED':
            student_id = enrollment.student_id
            student = Student.query.get(student_id)
            student.update_data(args)
            return {'success': True, 'message': "UPDATED_DATA"}

        # when the key is not used to give any test
        return {'error': True, 'message': "KEY_IS_NOT_USED"}
Exemplo n.º 7
0
    def get(self):
        args = self.get_parser.parse_args()

        # check the enrollment key
        enrollment_key = args.get('enrollment_key')
        result, enrollment = check_enrollment_key(enrollment_key)

        # if enrollment doesn't exist or expired
        if not result['valid']:
            return {'error': True, 'enrollment_key_validation': False}

        elif result['valid'] and result['reason'] == 'ALREADY_IN_USED':
            questions = enrollment.extract_question_from_set()
        else:
            # start the test and send the questions generated randomly
            enrollment.start_test()
            question_set, questions = QuestionSet.create_new_set()
            enrollment.question_set_id = question_set.id
            db.session.add(enrollment)
            db.session.commit()

        return {'questions': questions}
    def get(self):
        args = self.get_parser.parse_args()

        # check the enrollment key
        enrollment_key = args.get('enrollment_key')
        result, enrollment = check_enrollment_key(enrollment_key)

        # if enrollment doesn't exist or expired
        if not result['valid']:
            return {'error': True, 'enrollment_key_validation': False}

        # if `ALREADY_IN_USED` means a question set associated with the ID has
        # already been generated. Then just get that set and return it.
        elif result['valid'] and result['reason'] == 'ALREADY_IN_USED':
            question_set = enrollment.question_set
            questions = question_set.get_questions()

        # otherwise if the enrolment key has never been used then a new question
        # set needs to be created and served.
        else:
            # start the test and send the questions generated randomly
            question_set, questions = enrollment.get_question_set()

        return {'data': questions, 'enrollment_key_validation': True}
    def get(self):
        args = self.get_parser.parse_args()
        enrollment_key = args.get('enrollment_key', None)

        result, enrollment = check_enrollment_key(enrollment_key)
        return result