Esempio n. 1
0
    def get_list_student():
        result = list()
        param = request.args

        ten = param.get("ten")
        ma_sv = param.get("masv")
        lop = param.get("lop")
        trang_thai = param.get("trang_thai")
        gvhd = param.get("gvhd")
        page = param.get("page", 1)
        per_page = param.get("per_page", 10)

        page = 0

        paging = {
            "page": page,
            "per_page": per_page,
        }
        students = StudentModel.get_all_student()

        for student in students:
            data = {
                "masv": student.MaSV,
                "ten": student.Ten,
                "lop": "12312312",
                "hom_thu": "",
                "trang_thai": student.TrangThai,
                "gvhd": student.MaGVHD,
                "detai": "De tai"
            }
            result.append(data)
        return jsonify({
            "message": "Tạo ghi chú thành công!",
            "data": result,
            "paging": paging,
            "code": 200
        }), 200
Esempio n. 2
0
    def get_list_student():
        result = list()
        param = request.args

        ten = param.get("ten")
        ma_sv = param.get("masv")
        lop = param.get("lop")
        trang_thai = param.get("trang_thai")
        gvhd = param.get("gvhd")
        page = param.get("page", 1)
        per_page = param.get("per_page", 10)

        where = ""

        if ten:
            if not where:
                where = "( StudentModel.Ten.contains(ten) )"
            else:
                where += " & ( StudentModel.Ten.contains(ten) )"

        if ma_sv:
            if not where:
                where = "( StudentModel.MaSV.contains(ma_sv) )"
            else:
                where += " & ( StudentModel.MaSV.contains(ma_sv) )"

        if gvhd:
            if not where:
                where = "( StudentModel.MaGVHD.contains(gvhd) )"
            else:
                where += " & ( StudentModel.MaGVHD.contains(gvhd) )"
        result = list()
        paging = dict()
        if where:
            where = eval(where)

        tong = StudentModel.count_student_by_where(where)
        if tong == 0:
            return jsonify({
                "messgae": "request thành công!",
                "data": result,
                "code": 200
            }), 200
        if page == -1:
            students = StudentModel.get_all_student(where=where, is_full=True)
        else:
            paging = StudentController.generate_paging(page=page,
                                                       per_page=per_page,
                                                       sum_page=tong)
            skip = per_page * (page - 1)
            limit = per_page
            students = StudentModel.get_all_student(where=where,
                                                    skip=skip,
                                                    limit=limit)

        for student in students:
            detai = ""
            if student.IDDeTai:
                project = ProjectModel.get_project_by_id(
                    project_id=int(student.IDDeTai))
                if project:
                    detai = project.Ten
            data = {
                "id": student.id,
                "masv": student.MaSV,
                "ten": student.Ten,
                "lop": "12312312",
                "hom_thu": "",
                "trang_thai":
                student.TrangThai if not student.IDDeTai else "DaChon",
                "gvhd": student.MaGVHD,
                "detai": detai,
                "cap": student.Cap
            }
            result.append(data)
        return jsonify({
            "message": "Tạo ghi chú thành công!",
            "data": result,
            "paging": paging,
            "code": 200
        }), 200