Ejemplo n.º 1
0
    def post(self):
        data = _teacher_parser.parse_args()

        if TeacherModel.find_by_email(data['email']):
            return {"message": "User already registered"}, 400

        teacher = TeacherModel(**data)
        teacher.save_to_db()

        return {"message": "User created successfully"}, 201
    def mutate(self, info, name, department):
        q = Department.get_query(info)
        teacher_department = q.filter_by(id=department).first()
        new_teacher = TeacherModel(name=name, department=teacher_department)
        db_session.add(new_teacher)
        db_session.commit()

        return CreateTeacher(id=new_teacher.id,
                             name=new_teacher.name,
                             department=teacher_department)
Ejemplo n.º 3
0
 def post(self):
     claims = get_jwt_claims()
     if claims['type'] != 'admin':
         return {"message": "Not authorized."}, 401
     data = ChangePermission.parser.parse_args()
     teacher = TeacherModel.find_by_id(data['id'])
     if not teacher:
         return {"message": "Teacher not found"}, 404
     teacher.allowed = claims['allowed']
     teacher.save_to_db()
     return {"message": "Permission updated."}, 200
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def put(self, id):
        user = UserModel.find_by_id(get_jwt_identity())
        if not user:
            return {"message": "not authenticated"}, 401
        claims = get_jwt_claims()
        if not (claims['type'] == 'admin' or user.id == id or
                (claims['type'] == 'teacher' and user.allowed == True)):
            return {"message": "not authenticated"}, 401

        data = Teacher.parser.parse_args()
        teacher = TeacherModel.find_by_id(id)
        if not teacher:
            return {"message": "Teacher not found."}, 404
        if data['email'] is not None:
            teacher.email = data['email']
        if data['password'] is not None:
            teacher.password = data['password']
        if claims['type'] == 'admin' and data['allowed'] is not None:
            teacher.allowed = data['allowed']
        teacher.save_to_db()
        return {"message": "Teacher details updated"}, 200
Ejemplo n.º 6
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'}
Ejemplo n.º 7
0
 def get(self):
     return {'teachers': [x.json() for x in TeacherModel.find_all()]}
Ejemplo n.º 8
0
 def delete(self, id):
     teacher = TeacherModel.find_by_id(id)
     if not teacher:
         return {'messsage': 'Teacher not found'}, 404
     teacher.delete_from_db()
     return {'message': 'Teacher deleted.'}, 200
Ejemplo n.º 9
0
 def get(self, id):
     teacher = TeacherModel.find_by_id(id)
     if not teacher:
         return {"message": "Teacher not found"}, 404
     return teacher.json(), 200