Esempio n. 1
0
    def login():
        try:
            request_data = request.data
            request_data = json.loads(request_data)
        except:
            return jsonify({
                "message": "Không thể lấy dữ liệu!",
                "code": 412
            }), 412
        username = request_data.get("username")
        password = request_data.get("password")

        password_md5 = generate_md5_by_str(password)

        user_data = UserModel.find_username_password(username=username,
                                                     password=password_md5)
        if not user_data:
            return jsonify({
                "message": "Không tìm thấy thông tin tài khoản!",
                "code": 413
            }), 413
        ma = None
        if user_data.Quyen == "giaovien":
            ma = TeacherModel.get_magvhd_by_id(int(user_data.LienKet))
        data = {
            "username": username,
            "permission": user_data.Quyen,
            "lienket": user_data.LienKet,
            "iddetai": "",
            "id_gvhd": "",
            "ma": ma
        }
        if user_data.Quyen == "sinhvien":
            student_data = StudentModel.get_student_by_id(
                student_id=user_data.LienKet)
            if student_data:
                data["ma"] = student_data.MaSV
                if student_data.IDDeTai:
                    data["iddetai"] = student_data.IDDeTai
                if student_data.MaGVHD:
                    teacher_id = TeacherModel.get_id_by_ma(student_data.MaGVHD)
                    if teacher_id:
                        data["id_gvhd"] = teacher_id
                check = int(user_data.LienKet)
                i = check // 3 if check >= 6 else check if check < 3 else check - 3
                if int(i) == 0:
                    data["start_time_do_an"] = "01/05/2021"
                if int(i) == 1:
                    data["start_time_do_an"] = "19/03/2021"
                if int(i) == 2:
                    data["start_time_do_an"] = "25/12/2020"

        return jsonify({
            "message": "Đăng nhập thành công!",
            "data": data,
            "code": 200
        }), 200
Esempio n. 2
0
    def get_report_by_week(teacher_id, week):
        try:
            args = request.args
        except:
            return jsonify({
                "message": "Không thể lấy dữ liệu!",
                "code": 412
            }), 412
        results = list()
        report_weekly = ReportWeeklyModel.get_report_by_week(week=week)
        for report_week in report_weekly:
            ma_gv = TeacherModel.get_magvhd_by_id(teacher_id=teacher_id)
            sinhvien = StudentModel.get_student_by_id(report_week.IDSinhVien)
            if not ma_gv or sinhvien.MaGVHD != ma_gv:
                continue
            data = {
                "tuan":
                week,
                "masv":
                sinhvien.MaSV,
                "ten":
                sinhvien.Ten,
                "hinhanh":
                Topic.HOST + "/download/image/" + str(report_week.id) + "/" +
                str(report_week.IDSinhVien) if report_week.HinhAnh else "",
                "file":
                Topic.HOST + "/download/file/" + str(report_week.id) + "/" +
                str(report_week.IDSinhVien) if report_week.File else "",
                # "ghichu": report_week.GhiChu,
                "diem":
                report_week.Diem
            }
            if week in ["8", "16"]:
                try:
                    points = ReportModel.get_report_id_sinh_vien(
                        report_week.IDSinhVien)
                except:
                    points = None
                point = ""
                if points:
                    if week == "8":
                        point = points.DiemLan1
                    if week == "16":
                        point = points.DiemLan2
                    data["diem"] = point
                if data.get("diem") and float(data.get("diem")) > 5:
                    data["duyet"] = True

            results.append(data)
        return jsonify({
            "message": "request thành công!",
            "data": results,
            "code": 200
        }), 200
Esempio n. 3
0
 def get_report_by_week(week):
     results = list()
     report_weekly = ReportWeeklyModel.get_report_by_week(week=week)
     for report_week in report_weekly:
         sinhvien = StudentModel.get_student_by_id(report_week.IDSinhVien)
         data = {
             "tuan": week,
             "masv": sinhvien.MaSV,
             "ten": sinhvien.Ten,
             "hinhanh": Topic.HOST + "/download/image/" + str(report_week.id) + "/" + str(report_week.IDSinhVien) if report_week.HinhAnh else "",
             "file": Topic.HOST + "/download/file/" + str(report_week.id) + "/" + str(report_week.IDSinhVien) if report_week.File else "",
             "ghichu": report_week.GhiChu,
         }
         results.append(data)
     return jsonify({"message": "request thành công!", "data": results, "code": 200}), 200
Esempio n. 4
0
    def login():
        try:
            request_data = request.data
            request_data = json.loads(request_data)
        except:
            return jsonify({
                "message": "Không thể lấy dữ liệu!",
                "code": 412
            }), 412
        username = request_data.get("username")
        password = request_data.get("password")

        password_md5 = generate_md5_by_str(password)

        user_data = UserModel.find_username_password(username=username,
                                                     password=password_md5)
        if not user_data:
            return jsonify({
                "message": "Không tìm thấy thông tin tài khoản!",
                "code": 413
            }), 413
        data = {
            "username": username,
            "permission": user_data.Quyen,
            "lienket": user_data.LienKet,
            "iddetai": "",
            "id_gvhd": "",
        }
        if user_data.Quyen == "sinhvien":
            student_data = StudentModel.get_student_by_id(
                student_id=user_data.LienKet)
            if student_data:
                if student_data.IDDeTai:
                    data["iddetai"] = student_data.IDDeTai
                if student_data.MaGVHD:
                    teacher_id = TeacherModel.get_id_by_ma(student_data.MaGVHD)
                    if teacher_id:
                        data["id_gvhd"] = teacher_id
        return jsonify({
            "message": "Đăng nhập thành công!",
            "data": data,
            "code": 200
        }), 200