Esempio n. 1
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
Esempio 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
    def put(self, class_id, subject_id):
        data = Subject_And_Class.parser.parse_args()
        row = Subject_And_ClassModel.find_row(class_id, subject_id)
        if row is None:
            return {"messages": err_404.format("row")}, 404
        else:
            if SubjectModel.find_by_subject_id(data["subject_id"]) is None:
                return {"messages": err_404.format("subject")}, 404
            if ClasssModel.find_by_class_id(data["class_id"]) is None:
                return {"messages": err_404.format("class")}, 404

            if datetime.datetime.now() > datetime.datetime.strptime(
                    data["exam_date"], "%Y-%m-%d"):
                return {"messages": "exam date you set is in the past"}, 400

            try:
                if data["class_id"]:
                    row.class_id = data["class_id"]
                if data["exam_date"]:
                    row.exam_date = datetime.datetime.strptime(
                        data["exam_date"], "%Y-%m-%d")
                if data["subject_id"]:
                    row.user_id = data["user_id"]
                row.save_to_db()
            except:
                return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Esempio n. 4
0
    def get(self, subject_id=None, page=None, per_page=None):
        if (
            request.args.get("page")
            and request.args.get("per_page")
            and request.args.get("username")
        ):
            page = int(request.args.get("page"))
            name = request.args.get("username")
            per_page = int(request.args.get("per_page"))
            list_subject = SubjectModel.find_list_by_name(name, page, per_page)
            if list_subject is None:
                return {"messages": err_404.format("list_subject")}, 404
            return (
                {
                    "list": SubjectModel.to_json(list_subject),
                    "count ": len(list_subject),
                },
                200,
            )

        if subject_id is None:
            list = []
            for subject in SubjectModel.query.paginate(page, per_page, False).items:
                list.append(subject.json())
            return {"list": list, "count": len(SubjectModel.query.all())}, 200

        subject = SubjectModel.find_by_subject_id(subject_id)
        if subject is None:
            return {"messages": err_404.format("subject")}, 404
        return subject.json(), 200
    def post(self):
        data = Subject_And_Class.parser.parse_args()
        if Subject_And_ClassModel.find_row(data["class_id"],
                                           data["subject_id"]):
            return {"messages": err_duplicate.format("class")}, 400

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

        if datetime.datetime.now() > datetime.datetime.strptime(
                data["exam_date"], "%Y-%m-%d"):
            return {"messages": "exam date you set is in the past"}, 400

        row = Subject_And_ClassModel(
            class_id=data["class_id"],
            subject_id=data["subject_id"],
            exam_date=datetime.datetime.strptime(data["exam_date"],
                                                 "%Y-%m-%d"),
        )
        try:
            row.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Esempio n. 6
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
Esempio n. 7
0
 def json(self):
     student = StudentModel.find_by_student_id(self.student_id)
     cluster = ClusterModel.find_by_cluster_id(student.cluster_id)
     kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_id(
         student.kalika_kendra_id)
     return {
         'result_id':
         self.id,
         'attempt_id':
         self.attempt_id,
         'student_id':
         self.student_id,
         'student_name':
         student.student_name if student else None,
         'cluster_id':
         cluster.id if cluster else None,
         'cluster_name':
         cluster.cluster_name if cluster else None,
         'kalika_kendra_id':
         kalika_kendra.id if kalika_kendra else None,
         'kalika_kendra_name':
         kalika_kendra.kalika_kendra_name if kalika_kendra else None,
         'subject_id':
         self.subject_id,
         'subject_name':
         SubjectModel.find_by_subject_id(self.subject_id).subject_name,
         'assessment_category_id':
         self.category_id,
         'assessment_category_name':
         AssessmentCategoryModel.find_by_category_id(
             self.category_id).category_name,
         'assessment_skill_id':
         self.skill_id,
         'assessment_skill_name':
         AssessmentSkillModel.find_by_skill_id(self.skill_id).skill_name
         if AssessmentSkillModel.find_by_skill_id(self.skill_id) else None,
         'assessment_period_id':
         self.period_id,
         'assessment_year':
         self.year,
         'assessment_month':
         self.month,
         'assessment_day':
         self.day,
         'assessment_session':
         self.session,
         'assessment_score':
         self.score,
         'assessment_full_score':
         self.full_score,
         'assessment_grade':
         self.grade,
         'creation_date':
         str(self.creation_date),
         'modified_date':
         str(self.modified_date),
         'modified_by':
         self.modified_by
     }
Esempio n. 8
0
 def delete(self, subject_id):
     subject = SubjectModel.find_by_subject_id(subject_id)
     if subject is None:
         return {"messages": err_404.format("subject")}, 404
     try:
         subject.delete_from_db()
     except:
         return {"messages": err_500}, 500
     return {"messages": noti_201}, 201
Esempio n. 9
0
 def json(self):
     return {'skill_id': self.id, 'skill_name': self.skill_name,
             'skill_code': self.skill_code,
             'subject_id': self.subject_id,
             'subject_name':
                 SubjectModel.find_by_subject_id(self.subject_id).subject_name,
             'category_id': self.category_id,
             'category_name': AssessmentCategoryModel.find_by_category_id(
                 self.category_id).category_name,
             'isactive': self.isactive}
Esempio n. 10
0
 def put(self, subject_id):
     data = Subject.parser.parse_args()
     subject = SubjectModel.find_by_subject_id(subject_id)
     if subject is None:
         return {"messages": err_404.format("subject")}, 404
     else:
         try:
             subject.name = data["name"]
             subject.save_to_db()
         except:
             return {"messages": err_500}, 500
     return {"messages": noti_201}
Esempio n. 11
0
 def get(self):
     data = request.args
     subject_id = data.get("subject_id")
     subject_name = data.get("subject_name")
     subject_code = data.get("subject_code")
     print(data)
     subjects = None
     if subject_name:
         subject = SubjectModel.find_by_subject_name(subject_name)
     elif subject_id:
         subject = SubjectModel.find_by_subject_id(subject_id)
     elif subject_code:
         subject = SubjectModel.find_by_subject_code(subject_code)
     if subject:
         return subject.json()
     return {'message': 'Subject not found'}, 404
Esempio n. 12
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
Esempio n. 13
0
 def json(self):
     return {'category_id': self.id, 'category_name': self.category_name,
             'category_code': self.category_code,
             'subject_id': self.subject_id,
             'subject_name': SubjectModel.find_by_subject_id(self.subject_id).subject_name,
             'isactive': self.isactive}