def decorator(*args, **kwargs): classroom = Classroom.find(id=kwargs["classroom_id"]) if not classroom: return { "msg": f"Classroom with id {kwargs['classroom_id']} not found" }, 404 return fn(*args, **kwargs)
def put(self, classroom_id): args = self.__parser.parse_args() try: classroom = Classroom.find(id=classroom_id) user = classroom.remove_teacher(email=args["email"]) if user: classroom.add_student(user) else: classroom.add_student(User.find(email=args["email"])) return make_response_of_list( Classroom.find(id=classroom_id).students, exclude("password")) except NotFound: return { "msg": f"User with email {args['email']} doesn't exist" }, 404 except EnrollmentExists as e: return {"msg": str(e)}, 400
def post(self, classroom_id): args = self.__parser.parse_args() if args["topic"]: args["topic"] = Topic.find(id=args["topic"]) else: del args["topic"] assignment = Assignment(**args).save() classroom = Classroom.find(id=classroom_id) classroom.add_assignment(assignment) return assignment_schema.dump(assignment)
def post(self, classroom_id): args = self.__parser.parse_args() if args["topic"]: args["topic"] = Topic.find(id=args["topic"]) else: del args["topic"] material = Material(**args).save() classroom = Classroom.find(id=classroom_id) classroom.add_material(material) return material_schema.dump(material)
def delete(self, classroom_id, student_id): try: classroom = Classroom.find(id=classroom_id) classroom.remove_student(id=student_id) return make_response_of_list(classroom.students, exclude("password")) except NotFound: return { "msg": f"Teacher with id {student_id} is not in this classroom" }, 404 except EnrollmentExists as e: return {"msg": str(e)}, 400
def delete(self, classroom_id, assignment_id): classroom = Classroom.find(id=classroom_id) assignment = Assignment.find(id=assignment_id) if not assignment: return { "msg": f"Assignment with id {classroom_id} doesn't exist" }, 404 classroom.remove_assignment(assignment) assignment.delete() return assignment_schema.dump(assignment)
def delete(self, classroom_id, material_id): classroom = Classroom.find(id=classroom_id) material = Material.find(id=material_id) if not material: return { "msg": f"Material with id {classroom_id} doesn't exist" }, 404 classroom.remove_material(material) material.delete() return material_schema.dump(material)
def decorator(*args, **kwargs): if User.find(id=current_user.id) not in Classroom.find( id=kwargs["classroom_id"]).students: return {"msg": "Only student can do this"}, 400 return fn(*args, **kwargs)
def decorator(*args, **kwargs): if User.find(id=current_user.id) not in Classroom.find( id=kwargs["classroom_id"]).teachers: return {"msg": "Student cannot edit the classroom"}, 400 return fn(*args, **kwargs)
def decorator(*args, **kwargs): if User.find(id=current_user.id) != Classroom.find( id=kwargs["classroom_id"]).creator: return {"msg": "Creator can only edit"}, 400 return fn(*args, **kwargs)
def put(self, classroom_id, topic_id): args = self.__parser.parse_args() topic = Topic.find(id=topic_id) topic.update(**args) return classroom_schema.dump( loads(Classroom.find(id=classroom_id).to_json()))
def post(self, classroom_id): args = self.__parser.parse_args() classroom = Classroom.find(id=classroom_id) classroom.update(add_to_set__topics=Topic(**args).save()) return classroom_schema.dump( loads(Classroom.find(id=classroom_id).to_json()))
def delete(self, classroom_id): classroom = Classroom.find(id=classroom_id) classroom.delete() return classroom_schema.dump(loads(classroom.to_json()))
def get(self, classroom_id): return classroom_schema.dump( loads(Classroom.find(id=classroom_id).to_json()))
def get(self, classroom_id): return make_response_of_list( Classroom.find(id=classroom_id).students, exclude("password"))