def post(self, course_id): data = parser.parse_args() data['course_id'] = course_id quiz = QuizModel(**data) try: quiz.save() except: return {"message": "An error occurred while inserting Quiz."}, 500 update_steps_number(course_id) return quiz.json(), 201
def delete(self, quiz_id): quiz = QuizModel.find_by_id(quiz_id) if quiz: quiz.delete_from_db() return {'message': 'Quiz deleted'} return {'message': 'Quiz not found'}
def get(self, course_id, quiz_id): quiz = QuizModel.find_by_id(quiz_id) if quiz is None: return {"message": "No quiz found."}, 404 return quiz.json(), 200
def get(self, course_id): quizzes = QuizModel.find_by_course(course_id) if quizzes is None: return {"message": "No quizzes found for this course."}, 404 return [quiz.json() for quiz in quizzes], 200
def post(self): # parse_args() return only arguments added by add_argument as Namespace # Any missing added argument will stop and return help message to the browser data = Quiz.parser.parse_args() # Save data into Quiz table quiz = QuizModel(data["quiz_name"], data["theme_id"]) try: quiz.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 # Save data into Question table questions = data["questions"] for q in questions: question = QuestionModel(quiz.quiz_id, q["question_category"], q["questiontype_id"], q["question_statement"], q["question_correct_entries"], q["question_wrong_entries"]) try: question.save_to_db() except: return { "message": "An error occurred inserting the question." }, 500 # Save data into Question table answers = q["answers"] for a in answers: answer = AnswerModel(question.question_id, a["answer_is_correct"], a["answer_statement"]) try: answer.save_to_db() except: return { "message": "An error occurred inserting the answer." }, 500 return quiz.json(), 201
def put(self, quiz_id): data = Quiz.parser.parse_args() quiz = QuizModel.find_by_id(quiz_id) if quiz is None: # Create a new quiz if it does not exist in the database quiz = QuizModel(**data) else: # Update the quiz if it exists in the database quiz.quiz_name = data['quiz_name'] quiz.theme_id = data['theme_id'] quiz.quiz_update = datetime.now() quiz.save_to_db() return quiz.json()
def delete(self): request_data = QuizModel.parser.parse_args() quiz = QuizModel.find_by_id(request_data['quiz_id']) if quiz: quiz.delete_from_database() return { 'message': 'Quiz with ID {} deleted.'.format(request_data['quiz_id']) }, 200
def delete(self, course_id, quiz_id): quiz = QuizModel.find_by_id(quiz_id) if quiz is None: return {"message": "No quiz found."}, 404 try: quiz.delete() except: return {"message": "An error occurred while deleting Quiz."}, 500 update_steps_number(course_id) return {"message": "Quiz deleted."}, 200
def get(self): request_data = Quiz.parser.parse_args() try: quiz = QuizModel.find_by_id(request_data['quiz_id']) except: return { 'message': 'An error occurred while reading the quiz ID from the database' }, 500 if quiz: return quiz.json() return { 'message': 'Quiz with the ID {} not found'.format(request_data['quiz_id']) }, 404
def put(self, course_id, quiz_id): data = parser.parse_args() data['course_id'] = course_id quiz = QuizModel.find_by_id(quiz_id) if quiz is None: new_quiz = QuizModel(**data) try: new_quiz.save() return new_quiz.json(), 201 except: return { "message": "An error occurred while inserting Quiz." }, 500 try: quiz.update(**data) except: return {"message": "An error occurred while updating Quiz."}, 500 return quiz.json(), 200
def get(self, quiz_id): quiz = QuizModel.find_by_id(quiz_id) if quiz: return quiz.json() return {'message': 'Quiz not found'}, 404
def delete(self): QuizModel.delete_all() return {'message': 'All quizes deleted'}
def get(self): return {'quizes': QuizModel.query_all()}
def test_db(): from models.user import UserModel, RoleModel student = RoleModel('student') instructor = RoleModel('instructor') db.session.add_all([student, instructor]) db.session.commit() bart = UserModel('bart', 'bart', 'bart', 'student', firstname=None, lastname=None, picture=None) lisa = UserModel('lisa', 'lisa', 'lisa', 'student', firstname=None, lastname=None, picture=None) millhouse = UserModel('millhouse', 'millhouse', 'millhouse', 'student', firstname=None, lastname=None, picture=None) edna = UserModel('edna', 'edna', 'edna', 'instructor', firstname=None, lastname=None, picture=None) simour = UserModel('simour', 'simour', 'simour', 'instructor', firstname=None, lastname=None, picture=None) db.session.add_all([bart, lisa, millhouse, edna, simour]) db.session.commit() print('::: test roles and users ::: ok') ################### print('students') for student in student.users: print('>>> {}'.format(student.username)) print('instructors') for instructor in instructor.users: print('>>> {}'.format(instructor.username)) ################### from models.course import CourseModel from models.category import CategoryModel maths = CategoryModel('maths', fr_label=None, en_label=None, picture=None) english = CategoryModel('english', fr_label=None, en_label=None, picture=None) db.session.add_all([maths, english]) db.session.commit() math_course = CourseModel('mathematics', 'basic operations', simour.id, maths.id, picture=None) english_course = CourseModel('english', 'grammar', edna.id, english.id, picture=None) db.session.add_all([math_course, english_course]) db.session.commit() math_course.register_student(bart.id) math_course.register_student(lisa.id) english_course.register_student(lisa.id) english_course.register_student(millhouse.id) db.session.commit() print('::: test categories and courses ::: ok') ################### print('students enrolled in math') for student in math_course.students: print('>>> {}'.format(student.username)) print('author of math_course') print('>>> {}'.format(math_course.author.username)) print('edna published courses') for course in edna.published_courses: print('>>> {} - {}'.format(course.title, course.category.name)) ################### from models.chapter import ChapterModel from models.quiz import QuizModel from models.question import QuestionModel from models.answer import AnswerModel chapter1 = ChapterModel('adds', '2 + 2 = 4', 1, math_course.id) chapter2 = ChapterModel('subs', '2 - 2 = 0', 2, math_course.id) db.session.add_all([chapter1, chapter2]) db.session.commit() quiz1 = QuizModel('first grade', 1, math_course.id) quiz2 = QuizModel('second grade', 2, math_course.id) db.session.add(quiz1) db.session.add(quiz2) db.session.commit() question1 = QuestionModel('1 + 1?', 1, 2, quiz1.id) db.session.add(question1) db.session.commit() answer1 = AnswerModel('0', 1, question1.id) db.session.add(answer1) answer2 = AnswerModel('2', 2, question1.id) db.session.add(answer2) question2 = QuestionModel('3 - 1?', 2, 1, quiz1.id) db.session.add(question2) answer3 = AnswerModel('2', 1, question2.id) db.session.add(answer3) answer4 = AnswerModel('4', 2, question2.id) db.session.add(answer4) db.session.commit() print('::: test chapters and quizzes and questions and answers ::: ok') ################### print('chapters in math_course') for chapter in math_course.chapters: print('>>> {}'.format(chapter.title)) print('quizzes in math_course') for quiz in math_course.quizzes: print('>>> {}'.format(quiz.title)) print('questions in quiz1') for question in quiz1.questions: print('>>> {}'.format(question.question)) print('answers in question1') for answer in question1.answers: print('>>> {}'.format(answer.answer)) print('for question1 the good answer is number {}'.format( question1.good_answer)) current_question = question1.question good_answer = AnswerModel.query.filter_by( number=question1.good_answer).first() print('question: {} | response: {}'.format(current_question, good_answer.answer)) ################### from models.comment import CommentModel from models.rating import RatingModel comment1 = CommentModel('hay caramba', 'hay caramba', math_course.id, bart.id) comment2 = CommentModel('retention', 'retention', math_course.id, simour.id) comment3 = CommentModel('eat my short', 'eat my short', math_course.id, bart.id) db.session.add_all([comment1, comment2, comment3]) db.session.commit() rate1 = RatingModel(5, english_course.id, lisa.id) rate2 = RatingModel(3, english_course.id, millhouse.id) db.session.add_all([rate1, rate2]) db.session.commit() print('::: test comments and ratings ::: ok') ################### print('comments in math_course') for comment in math_course.comments: print('>>> {} by {}'.format(comment.title, comment.author.username)) print('ratings in english_course') for rate in english_course.ratings: print('>>> {}/5 by {}'.format(rate.rate, rate.author.username)) ################### from models.badge import BadgeModel from models.score import ScoreModel score = ScoreModel(2, 2, lisa.id, quiz1.id) db.session.add(score) db.session.commit() badge = BadgeModel('honor', math_course.id, lisa.id) db.session.add(badge) db.session.commit() print('::: test scores and badges ::: ok') ################### print('badges earned by lisa') for badge in lisa.badges: print('>>> {}'.format(badge.name)) print('scores in quiz1') for score in quiz1.scores: print('>>> {} by {}'.format(score.score, score.student.username))
def insert_test_data(): # these are queries used only for inserting test data, this should not be needed once the form to make quizzes is implemented # Topic 1 - Child Protection Policy TopicModel(1, 1, 'Child Protection Policy', 100).save_to_database() # Test 1 TestModel(1, 1, 1, 30, 1, 0, 15, None, 'This test will cover the introduction to Child Protection Policy.', 1, 1).save_to_database() # Quiz 1 QuizModel(1, 1, 1, 10, 0, 'multiple_choice', 'What should be avoided except in emergencies?', None, 'Question 1', 'To complete this quiz please select an answer and then click next. You can, however, come to the question later and change your answer.').save_to_database() AnswerModel(1, 1, 'Spending time alone with children away from others', 1, None, 0).save_to_database() AnswerModel(2, 1, 'Making sport fun and enjoyable', 0, None, 0).save_to_database() AnswerModel(3, 1, 'Promoting fair play', 0, None, 0).save_to_database() # Quiz 2 QuizModel(2, 1, 2, 10, 0, 'multiple_choice', 'Choose the most appropriate from the following options that best describes the aim of the Child Protection Policy:', None, 'Question 2', 'To complete this quiz please select an answer and then click next').save_to_database() AnswerModel(4, 2, 'Children should be safely protected with appropriate gear, so that we can minimize injuries to happen', 0, None, 0).save_to_database() AnswerModel(5, 2, 'Make sure that every young person can integrate with each other, in a safe and positive environment', 0, None, 0).save_to_database() AnswerModel(6, 2, 'Promoting good practice by providing young people with appropriate safety and protection, whilst in care of Slum Soccer', 1, None, 0).save_to_database() # Quiz 3 - Info Page QuizModel(3, 1, 3, 0, 0, 'info', 'Any suspicion that a child has been abused by either a member of staff or a volunteer should be reported to the Slum Soccer Child Protection Officer, who will take such steps as considered necessary to ensure the safety of the child in question and any other child who may be at risk. The Slum Soccer Child Protection Officer will refer the allegation to the social services department who may involve the police. The parents or carers of the child will be contacted as soon as possible following advice from the social services department. The Slum Soccer Child Protection Officer should also notify the relevant Sport Governing Body officer who in turn will inform the Sport Governing Body Child Protection Officer who will deal with any media enquiries. If the Slum Soccer Child Protection Officer is the subject of the suspicion/allegation, the report must be made to the appropriate Manager or in his/her absence the Sport Governing Body Child Protection Officer who will refer the allegation to Social Services. ', 'cps.jpg', 'Reporting concerns about suspected abuse ', 'Read carefully the text and when you are ensure you understand everything, click next. You won t be able to return to this page when you leave it, so read carefully.').save_to_database() # Quiz 4 QuizModel(4, 1, 4, 10, 0, 'multiple_choice', 'If there is suspicion that a child has been abused by either a member of staff or a volunteer, what is the order of people/roles to be appointed and the steps as considered necessary to be undertaken?', None, 'Question 4', 'To complete this quiz please select an answer and then click next').save_to_database() AnswerModel(10, 4, 'It should be reported to the appropriate Manager who will refer to the Slum Soccer Child Protection Officer who will contact the police or any social services department', 0, None, 0).save_to_database() AnswerModel(11, 4, 'It should be reported to the Slum Soccer Child Protection Officer, who will refer to the social services department. He should also notify the relevant Sport Governing body office',1, None, 0).save_to_database() AnswerModel(12, 4, 'It should be reported to the police that after their investigations, will contact the Slum Soccer Child Protection Officer, who will inform the Sport Governing Body Child Protection Officer', 0, None, 0).save_to_database() # Test 2 TestModel(2, 1, 1, 40, 2, 0, 20, None, 'This test tests you on the aim of the Child Protection Policy. You have only one attempt for this test.', 0, 1).save_to_database() # Quiz 1 - Info Page QuizModel(5, 2, 1, 0, 0, 'info', 'Slum Soccer has a duty of care to safeguard all children involved in Slum Soccer from harm. All children have a right to protection, and the needs of disabled children and others who may be particularly vulnerable must be taken into account. Slum Soccer will ensure the safety and protection of all children involved in Slum Soccer through adherence to the Child Protection guidelines adopted by Slum Soccer. A child is defined as a person under the age of 18.', None, 'Aim of the Child Protection Policy', 'After leaving this page you won t be able to return. Read carefully.').save_to_database() # Quiz 2 QuizModel(6, 2, 2, 10, 0, 'multiple_choice', 'What children does Slum Soccer ensures safety and protection to?', None, 'Question 1', 'Select your answer and click on continue...').save_to_database() AnswerModel(13, 6, 'All children around the globe', 0, None, 0).save_to_database() AnswerModel(14, 6, 'All children involved in Slum Soccer', 1, None, 0).save_to_database() AnswerModel(16, 6, 'All children involved in Slum Soccer who have a signature from their parents', 0, None, 0).save_to_database() # Quiz 3 QuizModel(7, 2, 3, 10, 0, 'multiple_choice', 'What is the correct statement from the choices bellow?', None, 'Question 2', 'Select one answer from the answers provided. Only one of them is correct. When you feel ready click continue to continue with the test.').save_to_database() AnswerModel(17, 7, 'A child is defined as a person between 5 and 18 years of age.', 0, None, 0).save_to_database() AnswerModel(18, 7, 'Disabled children don t need to be taken into account as all children should be treated equally.', 0, None, 0).save_to_database() AnswerModel(19, 7, 'Slum Soccer has a duty of care to safeguard all children involved in Slum Soccer from Slum Soccer enemies.', 0, None, 0).save_to_database() AnswerModel(20, 7, 'Adherance to the Child Protection guidelines ensures the safety and protection of children in Slum Soccer.', 1, None, 0).save_to_database() # Quiz 4 - Info Page QuizModel(8, 2, 4, 0, 0, 'info', 'The aim of the Slum Soccer Child Protection Policy is to promote good practice by: Firstly, providing children and young people with appropriate safety and protection whilst in the care of Slum Soccer. Sceondly, allow all staff/volunteers to make informed and confident responses to specific child protection issues.', None, 'Policy Aims', 'After leaving this page you won t be able to return. Read carefully.').save_to_database() # Quiz 5 QuizModel(9, 2, 5, 10, 0, 'multiple_choice', 'What is the aim of Slum Soccer Child Protectiion Policy?', None, 'Question 3', 'Select one answer from the answers bellow. Only one of them answers the question correctly. When you feel ready click continue.').save_to_database() AnswerModel(21, 9, 'Spread the awaraness of endangerment of human children.', 0, None, 0).save_to_database() AnswerModel(22, 9, 'Promote good practice.', 1, None, 0).save_to_database() AnswerModel(23, 9, 'Advertise Slum Soccer practices.', 0, None, 0).save_to_database() # Quiz 6 QuizModel(10, 2, 6, 10, 0, 'multiple_choice', 'What doesn t belong among the aims of the Slum Soccer Child Protection Policy?', None, 'Question 4', 'Only one of them answers is incorrect. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(24, 10, 'Allow all staff /volunteers to make informed and confident responses to specific child protection issues.', 0, None, 0).save_to_database() AnswerModel(25, 10, 'Providing children and young people with appropriate safety and protection whilst in the care of Slum Soccer.', 0, None, 0).save_to_database() AnswerModel(26, 10, 'Find the most gifted children withing the Slum Soccer and train them to join Slum Soccer Professional Children League.', 1, None, 0).save_to_database() # Test 3 - empty an locked TestModel(3, 1, 0, 50, 3, 0, 25, None, 'This test might looked locked as of now. It is because it is locked and you cannot access it right now.', 1, 1).save_to_database() # Test 4 - empty an locked TestModel(4, 1, 0, 50, 4, 0, 25, None, 'Can t you believe this? This is locked too. What a nightmare... Maybe you should work harder to unlock it. Or maybe this is just an empty test to show how an unlocked test looks like, since it s quite difficult to create a new test.', 0, 1).save_to_database() # Topic 2 - Another Topic TopicModel(2, 1, 'Another Topic', 120).save_to_database() # Test 1 TestModel(5, 2, 1, 50, 1, 0, 25, None, 'This is a practice test teaching you about colours. IT s not official so you can take it as often as you wish.', 1, 0).save_to_database() # Quiz 1 - Info page QuizModel(11, 5, 1, 0, 0, 'info', 'The ability of the human eye to distinguish colors is based upon the varying sensitivity of different cells in the retina to light of different wavelengths. Humans are trichromatic—the retina contains three types of color receptor cells, or cones. One quiz_type, relatively distinct from the other two, is most responsive to light that is perceived as blue or blue-violet, with wavelengths around 450 nm; cones of this quiz_type are sometimes called short-wavelength cones or S cones (or misleadingly, blue cones). The other two types are closely related genetically and chemically: middle-wavelength cones, M cones, or green cones are most sensitive to light perceived as green, with wavelengths around 540 nm, while the long-wavelength cones, L cones, or red cones, are most sensitive to light that is perceived as greenish yellow, with wavelengths around 570 nm. Light, no matter how complex its composition of wavelengths, is reduced to three color components by the eye. Each cone quiz_type adheres to the principle of univariance, which is that each cone s output is determined by the amount of light that falls on it over all wavelengths. For each location in the visual field, the three types of cones yield three signals based on the extent to which each is stimulated. These amounts of stimulation are sometimes called tristimulus values. The response curve as a function of wavelength varies for each quiz_type of cone. Because the curves overlap, some tristimulus values do not occur for any incoming light combination. For example, it is not possible to stimulate only the mid-wavelength so-called green cones; the other cones will inevitably be stimulated to some degree at the same time. The set of all possible tristimulus values determines the human color space. It has been estimated that humans can distinguish roughly 10 million different colors. The other quiz_type of light-sensitive cell in the eye, the rod, has a different response curve. In normal situations, when light is bright enough to strongly stimulate the cones, rods play virtually no role in vision at all.[12] On the other hand, in dim light, the cones are understimulated leaving only the signal from the rods, resulting in a colorless response. Furthermore, the rods are barely sensitive to light in the red range. In certain conditions of intermediate illumination, the rod response and a weak cone response can together result in color discriminations not accounted for by cone responses alone. These effects, combined, are summarized also in the Kruithof curve, that describes the change of color perception and pleasingness of light as function of temperature and intensity. SOURCE: https://en.wikipedia.org/wiki/Color', 'eye.jpg', 'Colours in the eye', 'This is an info page... read carefully. PICTURE SOURCE: https://en.wikipedia.org/wiki/Human_eye').save_to_database() # Quiz 2 QuizModel(12, 5, 2, 10, 0, 'multiple_choice', 'What is the opposite colour of blue?', None, 'Question 1', 'Only one of them answers is correct. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(27, 12, 'Red', 0, None, 0).save_to_database() AnswerModel(28, 12, 'Yellow', 1, None, 0).save_to_database() AnswerModel(29, 12, 'Purple', 0, None, 0).save_to_database() # Quiz 3 QuizModel(13, 5, 3, 10, 0, 'multiple_choice', 'What colour is on the picture?', 'red.jpg', 'Question 2', 'Only one of them answers is correct. Select your answer and when you feel ready click continue. PICTURE SOURCE: https://colourlex.com/project/chrome-red/').save_to_database() AnswerModel(30, 13, 'Red', 1, None, 0).save_to_database() AnswerModel(31, 13, 'Blue', 0, None, 0).save_to_database() # Quiz 4 QuizModel(14, 5, 4, 10, 0, 'multiple_choice', 'What color reflects all colours?', None, 'Question 3', 'Only one of them answers is correct. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(32, 14, 'Yellow', 0, None, 0).save_to_database() AnswerModel(33, 14, 'Red', 0, None, 0).save_to_database() AnswerModel(34, 14, 'Black', 0, None, 0).save_to_database() AnswerModel(35, 14, 'White', 1, None, 0).save_to_database() AnswerModel(36, 14, 'Green', 0, None, 0).save_to_database() # Quiz 5 - Info page QuizModel(15, 5, 5, 0, 0, 'info', 'While the mechanisms of color vision at the level of the retina are well-described in terms of tristimulus values, color processing after that point is organized differently. A dominant theory of color vision proposes that color information is transmitted out of the eye by three opponent processes, or opponent channels, each constructed from the raw output of the cones: a red–green channel, a blue–yellow channel, and a black–white luminance channel. This theory has been supported by neurobiology, and accounts for the structure of our subjective color experience. Specifically, it explains why humans cannot perceive a reddish green or yellowish blue, and it predicts the color wheel: it is the collection of colors for which at least one of the two color channels measures a value at one of its extremes. The exact nature of color perception beyond the processing already described, and indeed the status of color as a feature of the perceived world or rather as a feature of our perception of the world—a quiz_type of qualia—is a matter of complex and continuing philosophical dispute. https://en.wikipedia.org/wiki/Color', 'brain.jpg', 'Colour in the brain', 'This information should be read carefully. You might not be able to see this page again. PICTURE SOURCE: https://slate.com/technology/2016/03/how-big-is-the-brain-who-knows-even-our-best-efforts-to-calculate-its-capacity-are-flawed-and-meaningless.html').save_to_database() # Quiz 6 QuizModel(16, 5, 6, 10, 0, 'multiple_choice', 'How many hemispheres does human brain have?', None, 'Question 4', 'Only one of them answers is correct. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(37, 16, 'Two', 1, None, 0).save_to_database() AnswerModel(38, 16, 'None', 0, None, 0).save_to_database() # Quiz 7 QuizModel(17, 5, 7, 10, 0, 'multiple_choice', 'Do all animals see the same colours?', None, 'Question 5', 'Only one of them answers is correct. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(39, 17, 'No', 1, None, 0).save_to_database() AnswerModel(40, 17, 'Yes', 0, None, 0).save_to_database() # Test 2 TestModel(6, 2, 1, 20, 2, 0, 10, None, 'Koalas.. just koalas', 1, 1).save_to_database() # Quiz 1 - Info page QuizModel(18, 6, 1, 0, 0, 'info', 'This is a video about koalas, watch it.', 'https://www.youtube.com/embed/oI3ADcDH0Uc', 'Koalas', 'Watch it carefully and as many times as you want. However when you leave this page you cannot return. VIDEO SOURCE: https://www.youtube.com/watch?v=oI3ADcDH0Uc').save_to_database() # Quiz 2 QuizModel(19, 6, 2, 10, 0, 'multiple_choice', 'How many species of Eucalypt do koalas prefer?', None, 'Question 1', 'Only one of them answers is correct. Select your answer and when you feel ready click continue.').save_to_database() AnswerModel(41, 19, '3', 0, None, 0).save_to_database() AnswerModel(42, 19, '30', 1, None, 0).save_to_database() AnswerModel(43, 19, '65', 0, None, 0).save_to_database() AnswerModel(44, 19, '6', 0, None, 0).save_to_database() AnswerModel(45, 19, '650', 0, None, 0).save_to_database() # Quiz 3 QuizModel(20, 6, 3, 10, 0, 'multiple_choice', 'How many hours a day do koalas sleep?', 'https://www.youtube.com/embed/NnRcxHreJFM', 'Question 2', 'Only one of them answers is correct. Select your answer and when you feel ready click continue. VIDEO SOURCE: https://www.youtube.com/watch?v=NnRcxHreJFM').save_to_database() AnswerModel(46, 20, 'They can sleep for days.', 0, None, 0).save_to_database() AnswerModel(47, 20, 'Around 12 hours a day', 0, None, 0).save_to_database() AnswerModel(48, 20, 'Up to 20 hours a day.', 0, None, 0).save_to_database() AnswerModel(49, 20, 'Up to 22 hours a day.', 1, None, 0).save_to_database() # Test 3 - locked and empty TestModel(7, 2, 0, 20, 3, 0, 10, None, 'Just another empty test that you cannot see being empty.', 1, 1).save_to_database() # Test 4 - locked and empty TestModel(8, 2, 0, 20, 4, 0, 10, None, 'Empty as well...', 0, 0).save_to_database() # Test 5 - locked and empty TestModel(9, 2, 0, 20, 5, 0, 10, None, 'Nothing to see here', 0, 1).save_to_database() # Test 6 - locked and empty TestModel(10, 2, 0, 20, 6, 0, 10, None, 'Empty, lonely just incomplete...', 1, 0).save_to_database() # FA 1 - not started FormativeAssessmentModel(1, 2, 1, 1, 40, 0, None, 20, 'Write an essay of 2000 words comparing the life of koalas in captivity and in wilderness. You can gain maximum of 40 credits. For passing the module you need 20 credits. IMG SOURCE: https://en.wikipedia.org/wiki/Koala', 'Compare the life of koalas in captivity and in wilderness', 'koala.png', '1/6/2021', None, 0).save_to_database() # FA 2 - answered FormativeAssessmentModel(2, 2, 1, 2, 20, 0, 'my_colour_essay.docx', 10, 'Write an essay of 1500 words about the colour perception through a human eye. You can gain maximum of 20 credits. For passing the module you need 10 credits.', 'Colours through the eye', None, '20/4/2021', None, 0).save_to_database() # FA 3 - reviewed FormativeAssessmentModel(3, 2, 1, 3, 30, 16, 'self_reflection.docx', 15, 'Write a self reflection about your progress and improvements during this topic. It can be maximum 1000 words. You can gain maximum of 30 credits. For passing the module you need 15 credits. VIDEO SOURCE: https://www.youtube.com/watch?v=avHRLqVPYwg', 'Self reflection', 'https://www.youtube.com/embed/avHRLqVPYwg', '1/3/2021', 'Good job. But there is a lack of detail in the progress section. Be more specific about how you have improved.', 1). save_to_database() # Topic 3 - Yet One More Topic Here TopicModel(3, 0, 'Yet One More Topic Here', 250).save_to_database() # Test 1 - locked and empty TestModel(11, 3, 0, 100, 1, 0, 50, None, 'Very small locked test', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(12, 3, 0, 100, 2, 0, 50, None, 'Sad test full of emptyness.', 1, 1).save_to_database() # Test 3 - locked and empty TestModel(13, 3, 0, 100, 3, 0, 50, None, 'The secrets you shall never see.', 1, 1).save_to_database() # Test 4 - locked and empty TestModel(14, 3, 0, 100, 4, 0, 50, None, 'Empty too...', 0, 0).save_to_database() # Test 5 - locked and empty TestModel(15, 3, 0, 100, 5, 0, 50, None, 'I was once unlocked I have hread..', 0, 1).save_to_database() # Topic 4 - Topic TopicModel(4, 0, 'Topic', 60).save_to_database() # Test 1 - locked and empty TestModel(16, 4, 0, 50, 1, 0, 25, None, 'Nothin..', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(17, 4, 0, 50, 2, 0, 25, None, 'Empty', 1, 1).save_to_database() # FA 1 FormativeAssessmentModel(4, 4, 1, 1, 20, 0, None, 10, 'Write an essay of 2000 words. You can gain maximum of 40 credits. For passing the module you need 20 credits.', 'Some title', None, '5/6/2021', None, 0).save_to_database() # FA 2 FormativeAssessmentModel(5, 4, 1, 2, 20, 0, None, 10, 'Write an essay of 5000 words. You can gain maximum of 40 credits. For passing the module you need 20 credits.', 'Some title 2', None, '17/6/2021', None, 0).save_to_database() # Topic 5 - Topicnic TopicModel(5, 0, 'Topicnic', 12).save_to_database() # Test 1 - locked and empty TestModel(18, 5, 0, 5, 1, 0, 3, None, 'Locked test', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(19, 5, 0, 5, 2, 0, 3, None, 'Test of emptyness.', 1, 1).save_to_database() # Test 3 - locked and empty TestModel(20, 5, 0, 5, 3, 0, 3, None, 'The secrets...', 1, 1).save_to_database() # Test 4 - locked and empty TestModel(21, 5, 0, 5, 4, 0, 3, None, 'Empty2', 0, 0).save_to_database() # Topic 6 - Topic of all the topics TopicModel(6, 0, 'Topic of all the topics', 5).save_to_database() # Test 1 - locked and empty TestModel(22, 6, 0, 10, 1, 0, 5, None, 'ONLY ONE TEST BUT IT S HARD', 1, 0).save_to_database() # Topic 7 - Topic as well TopicModel(7, 0, 'Topic as well', 500).save_to_database() # Test 1 - locked and empty TestModel(23, 7, 0, 333, 1, 0, 150, None, 'Smallest Test', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(24, 7, 0, 333, 2, 0, 200, None, 'Smaller Test', 1, 1).save_to_database() # Test 3 - locked and empty TestModel(25, 7, 0, 334, 3, 0, 250, None, 'Small Test', 1, 1).save_to_database() # Topic 8 - Incomplete topic TopicModel(8, 0, 'Incomplete topic', 25).save_to_database() # Test 1 - locked and empty TestModel(26, 8, 0, 10, 1, 0, 5, None, 'Very small locked test', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(27, 8, 0, 10, 2, 0, 5, None, 'VERY LOCKED.', 1, 1).save_to_database() # Test 3 - locked and empty TestModel(28, 8, 0, 10, 3, 0, 5, None, 'Nothing to see here in this world.', 1, 1).save_to_database() # Test 4 - locked and empty TestModel(29, 8, 0, 10, 4, 0, 5, None, 'Sorry, empty', 0, 0).save_to_database() # Test 5 - locked and empty TestModel(30, 8, 0, 10, 5, 0, 5, None, 'I am empty', 0, 1).save_to_database() # FA 1 FormativeAssessmentModel(6, 8, 1, 1, 20, 0, None, 10, 'Write an essay of 5000 words. You can gain maximum of 40 credits. For passing the module you need 20 credits.', 'Some great title', None, '30/6/2021', None, 0).save_to_database() # Topic 9 - Very old topic TopicModel(9, 0, 'Very old topic', 75).save_to_database() # Test 1 - locked and empty TestModel(31, 9, 0,70, 1, 0, 35, None, 'I am first but locked.', 1, 0).save_to_database() # Test 2 - locked and empty TestModel(32, 9, 0, 70, 2, 0, 35, None, 'I am second but locked.', 1, 1).save_to_database()
def put(self): request_data = Quiz.parser.parse_args() quiz = QuizModel.find_by_id(request_data['quiz_id']) try: if not quiz: quiz = QuizModel(**request_data) else: # if 'quiz' is defined, this means there's an existing record under this ID, so update it with the values we have if request_data['quiz_id'] != None: quiz.quiz_id = request_data['quiz_id'] if request_data['test_id'] != None: quiz.test_id = request_data['test_id'] if request_data['order_num'] != None: quiz.order_num = request_data['order_num'] if request_data['credit_value'] != None: quiz.credit_value = request_data['credit_value'] if request_data['gained_credit'] != None: quiz.gained_credit = request_data['gained_credit'] if request_data['quiz_type'] != None: quiz.quiz_type = request_data['quiz_type'] if request_data['text_body'] != None: quiz.text_body = request_data['text_body'] if request_data['path_to_attachment'] != None: quiz.path_to_attachment = request_data[ 'path_to_attachment'] if request_data['title'] != None: quiz.title = request_data['title'] if request_data['instructions'] != None: quiz.instructions = request_data['instructions'] except: return { 'message': 'An error occurred while reading the quiz ID from the database' }, 500 try: quiz.save_to_database() return quiz.json() except: return { 'message': 'An error occurred while updating the quiz in the database' }, 500