示例#1
0
 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)
示例#2
0
    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
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
 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()))
示例#12
0
 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()))
示例#13
0
 def delete(self, classroom_id):
     classroom = Classroom.find(id=classroom_id)
     classroom.delete()
     return classroom_schema.dump(loads(classroom.to_json()))
示例#14
0
 def get(self, classroom_id):
     return classroom_schema.dump(
         loads(Classroom.find(id=classroom_id).to_json()))
示例#15
0
 def get(self, classroom_id):
     return make_response_of_list(
         Classroom.find(id=classroom_id).students, exclude("password"))