コード例 #1
0
ファイル: teacher.py プロジェクト: udraar/Abhyudaya
 def put(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _teacher_parser.parse_args()
     for key in data.keys():
         if str(data[key]).lower() in ('none', 'null', ''):
             data[key] = None
     teacher_id = data.get("teacher_id")
     teacher_name = data.get("teacher_name")
     teacher_code = data.get("teacher_code")
     if teacher_id:
         teacher = TeacherModel.find_by_teacher_id(teacher_id)
     elif teacher_code:
         teacher = TeacherModel.find_by_teacher_code(teacher_code)
     elif teacher_name:
         teacher = TeacherModel.find_by_teacher_name(teacher_name)
     else:
         return {"message": "Missing teacher key fields"}, 404
     try:
         data['modified_date'] = datetime.now()
         if teacher:
             teacher.set_attribute(data)
         else:
             teacher = TeacherModel(**data)
         teacher.save_to_db()
         return teacher.json()
     except Exception as ex:
         return {"message": f"Error updating teacher data. {repr(ex)}"}, 403
コード例 #2
0
    def get(self):
        data = request.args
        print(data)
        data = data.to_dict(flat=False)
        claims = get_jwt_claims()

        student_kalika_kendra_name = None
        student_kalika_kendra_id = None
        student_cluster_name = None
        student_cluster_id = None

        if not claims['is_admin']:
            user_email = claims['email']
            if claims['teacher_code']:
                teacher = TeacherModel.find_by_teacher_code(
                    claims['teacher_code'])
                student_kalika_kendra_id = teacher.kalika_kendra_id
                print(student_kalika_kendra_id)
            else:
                return {
                    'message': 'User do not have permission. Contact admin.'
                }, 401

        student_id = data.get("student_id")
        student_name = data.get("student_name")
        student_aadhar = data.get("aadhar")

        print(data)
        if student_id:
            student = StudentModel.find_by_student_id(student_id)
        if student_aadhar:
            student = StudentModel.find_by_student_aadhar(student_aadhar)
        if student_name:
            student = StudentModel.find_by_student_name(student_name)
        if student:
            print(student.kalika_kendra_id)
            if claims['is_admin'] or (str(student.kalika_kendra_id).__eq__(
                    str(student_kalika_kendra_id))):
                return student.json()
            else:
                return {
                    'message':
                    'User not authorized to view other Kalika Kendra data.'
                }, 401
        else:
            return {"message": "Student not found"}, 404
コード例 #3
0
ファイル: teacher.py プロジェクト: udraar/Abhyudaya
 def get(self):
     data = request.args
     teacher_id = data.get("teacher_id")
     teacher_name = data.get("teacher_name")
     teacher_code = data.get("teacher_code")
     
     if teacher_id:
         teacher = TeacherModel.find_by_teacher_id(teacher_id)
     if teacher_code:
         teacher = TeacherModel.find_by_teacher_code(teacher_code)
     if teacher_name:
         teacher = TeacherModel.find_by_teacher_name(teacher_name)
         
     if teacher:
         return teacher.json()
     else:
         return {"message": "Teacher not found"}, 404
コード例 #4
0
ファイル: teacher.py プロジェクト: udraar/Abhyudaya
 def delete(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _teacher_parser.parse_args()
     teacher_id = data.get("teacher_id")
     teacher_name = data.get("teacher_name")
     teacher_code = data.get("teacher_code")
     if teacher_id:
         teacher = TeacherModel.find_by_teacher_id(teacher_id)
     elif teacher_code:
         teacher = TeacherModel.find_by_teacher_code(teacher_code)
     else:
         return {"message": "Missing teacher key fields"}, 404
     if teacher:
         teacher.delete_from_db()
         return {'message': 'Teacher deleted.'}
     return {'message': 'Teacher not found.'}, 404
コード例 #5
0
 def get(self):
     data = dict(request.args)
     print(data)
     claims = get_jwt_claims()
     if not claims['is_admin']:
         if not claims['teacher_code']:
             return {
                 'message':
                 'User not a teacher. Unauthorized to view student data.'
             }, 401
         else:
             teacher = TeacherModel.find_by_teacher_code(
                 claims['teacher_code'])
             student_kalika_kendra_id = teacher.kalika_kendra_id
             student_kalika_kendra_name = KalikaKendraModel.find_by_kalika_kendra_id(
                 student_kalika_kendra_id).kalika_kendra_name
         if data.get("kalika_kendra_id"):
             if data.get("kalika_kendra_id") != student_kalika_kendra_id:
                 return {
                     'message':
                     'User not authorized to view other Kalika Kendra data.'
                 }, 401
         elif data.get("kalika_kendra_name"):
             if data.get(
                     "kalika_kendra_name") != student_kalika_kendra_name:
                 return {
                     'message':
                     'User not authorized to view other Kalika Kendra data.'
                 }, 401
         else:
             data["kalika_kendra_id"] = student_kalika_kendra_id
     students = StudentModel.find_by_student_by_any(**data)
     if students:
         resp = []
         for student in students:
             resp.append(student.json())
         return resp
     else:
         return {'message': 'Students not found'}