Exemplo n.º 1
0
    def get(self, exam_date=None, page=None, per_page=None, subject_id=None):
        # in ra tất cả
        if exam_date is None:
            list = ExamModel.to_json(
                ExamModel.query.paginate(page, per_page, False).items)
            return {"list": list, "count": len(ExamModel.query.all())}, 200

        # in ra 1 cái chỉ định
        exam = ExamModel.find_by_exam_date_and_subject_id(
            exam_date, subject_id)
        if exam is None:
            return {"messages": err_404.format("exam")}, 404
        return ExamModel.to_json(exam), 200
Exemplo n.º 2
0
    def put(self, mark_id):
        data = Mark.parser.parse_args()
        mark = MarkModel.find_by_mark_id(mark_id)
        if mark is None:
            return {"messages": err_404.format("mark")}, 404

        # check khóa ngoại
        if UserModel.find_by_user_id(user_id=data["user_id"]) is None:
            return {"messages": err_404.format(data["user_id"])}
        if (ExamModel.find_by_exam_date_and_subject_id(
                exam_date=data["exam_date"], subject_id=data["subject_id"]) is
                None):
            return {
                "messages":
                "Không tìm thấy có môn bạn tìm vào ngày {0}".format(
                    data["exam_date"])
            }
        if SubjectModel.find_by_subject_id(
                subject_id=data["subject_id"]) is None:
            return {"messages": err_404.format(data["subject_id"])}

        if data["mark"]:
            mark.mark = data["mark"]
        if data["exam_id"]:
            mark.exam_id = data["exam_id"]
        if data["subject_id"]:
            mark.subject_id = data["subject_id"]
        if data["user_id"]:
            mark.user_id = data["user_id"]
        try:
            mark.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Exemplo n.º 3
0
    def post(self):
        data = Mark.parser.parse_args()
        if MarkModel.find(data["user_id"], data["exam_date"],
                          data["subject_id"]):
            return {"messages": "this row existed"}, 400

        if UserModel.find_by_user_id(data["user_id"]).job != 1:
            return {"messages": "Bạn chỉ gán điểm được cho học sinh"}, 400

        ## check khóa ngoại
        if UserModel.find_by_user_id(user_id=data["user_id"]) is None:
            return {"messages": err_404.format("user")}
        if ExamModel.find_by_exam_date(exam_date=data["exam_date"]) is None:
            return {"messages": err_404.format("exam")}
        if SubjectModel.find_by_subject_id(
                subject_id=data["subject_id"]) is None:
            return {"messages": err_404.format("subject")}

        mark = MarkModel(
            mark=data["mark"],
            user_id=data["user_id"],
            exam_date=data["exam_date"],
            subject_id=data["subject_id"],
        )
        try:
            mark.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Exemplo n.º 4
0
    def put(self, exam_date, subject_id):
        data = Exam.parser.parse_args()
        exam = ExamModel.find_by_exam_date_and_subject_id(
            exam_date, subject_id)
        if exam is None:
            return {"messages": err_404.format("exam")}, 404
        if data["exam_room"]:
            exam.exam_room = data["exam_room"]
        if data["exam_date"]:
            exam.exam_date = data["exam_date"]
        if data["exam_start_time"]:
            exam.exam_start_time = data["exam_start_time"]
        if data["exam_time"]:
            exam.exam_time = data["exam_time"]
        if data["subject_id"]:
            exam.subject_id = data["subject_id"]

        # check khóa ngoại
        if SubjectModel.find_by_subject_id(
                subject_id=data["subject_id"]) is None:
            return {"messages": err_404.format("subject")}, 404

        try:
            exam.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Exemplo n.º 5
0
def get(ma=None):
    if ma is None:
        list = []
        for exam in ExamModel.query.paginate(1, 15, False).items:
            list.append(exam.json())
        return list
    exam = ExamModel.find_by_id(ma)
    if exam is None:
        return {"messages": "không tìm thấy người dùng"}
    return exam.json()
Exemplo n.º 6
0
 def delete(self, exam_date, subject_id):
     exam = ExamModel.find_by_exam_date_and_subject_id(
         exam_date, subject_id)
     if exam is None:
         return {"messages": err_404.format("exam")}, 404
     try:
         exam.delete_from_db()
     except:
         return {"messages": err_500}, 500
     return {"messages": noti_201}
 def get(cls, user_id):
     list = Student_And_ClassModel.find_list_class_by_user_id(user_id)
     list_exam = []
     if (
         UserModel.find_by_user_id(g.user.user_id).job == 2
         or g.user.user_id == user_id
     ):
         for row in list:
             list_subject = Subject_And_ClassModel.find_by_class_id(
                 class_id=row.class_id
             )
             for subject in list_subject:
                 exam = ExamModel.find_by_subject_id(subject_id=subject.subject_id)
                 if exam[0].exam_date > datetime.datetime.now():
                     list_exam.append(exam)
                 elif exam[0].exam_date == datetime.datetime.now() and exam[
                     0
                 ].exam_start_time > datetime.time(datetime.now()):
                     list_exam.append(exam)
         print(list_exam)
         return {"lịch thi": ExamModel.to_json(list_exam)}
     return {"messages": "Không có quyền"}, 403
Exemplo n.º 8
0
    def post(self):
        data = Exam.parser.parse_args()
        if ExamModel.find_by_exam_date_and_subject_id(data["exam_date"],
                                                      data["subject_id"]):
            return {"messages": err_duplicate.format("exam")}, 400
        try:
            exam_date = datetime.datetime.strptime(data["exam_date"],
                                                   "%Y-%m-%d")
            exam_start_time = datetime.datetime.strptime(
                data["exam_start_time"], "%H-%M")
        except:
            return (
                {
                    "messages":
                    "start date or end date was not valid a date form. Please try again"
                },
                400,
            )

        # check date
        if exam_date > datetime.datetime.now():
            return {"messages": "exam date can't be the day in the past"}, 400

        # check khóa ngoại
        if SubjectModel.find_by_subject_id(
                subject_id=data["subject_id"]) is None:
            return {"messages": err_404.format("subject")}, 404

        exam = ExamModel(
            exam_room=data["exam_room"],
            exam_date=exam_date,
            exam_start_time=exam_start_time,
            exam_time=data["exam_time"],
            subject_id=data["subject_id"],
        )
        exam.save_to_db()
        try:
            exam.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201