示例#1
0
 def set_attribute(self, payload):
     cols = [
         'student_name', 'gender', 'aadhar', 'dob', 'class_std',
         'father_name', 'father_occupation', 'mother_name',
         'mother_occupation', 'contact', 'isactive', 'register_date',
         'modified_date', 'modified_by'
     ]
     for col in cols:
         if col in payload.keys():
             setattr(self, col, payload[col])
     if 'cluster_name' in payload.keys():
         cluster = ClusterModel.find_by_cluster_name(
             payload['cluster_name'])
         if not cluster:
             return {
                 "message": f"Cluster name not found for the student"
             }, 401
         self.cluster_id = cluster.id
     if 'kalika_kendra_name' in payload.keys():
         kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
             payload['kalika_kendra_name'])
         if not kalika_kendra:
             return {
                 "message": f"Kalika Kendra name not found for the student"
             }, 401
         self.kalika_kendra_id = cluster.id
示例#2
0
 def post(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _kalika_kendra_parser.parse_args()
     kalika_kendra_name = data["kalika_kendra_name"]
     if KalikaKendraModel.find_by_kalika_kendra_name(kalika_kendra_name):
         return {
             'message':
             f"A Kalika Kendra with name '{kalika_kendra_name}' already exists."
         }, 400
     cluster = ClusterModel.find_by_cluster_name(data['cluster_name'])
     if not cluster:
         return {
             "message": f"Cluster name not found for the Kalika Kendra"
         }, 401
     kalika_kendra = KalikaKendraModel(**data)
     try:
         kalika_kendra.save_to_db()
     except Exception as e:
         return {
             "message":
             f"An error occurred inserting the Kalika Kendra. Error: {repr(e)}"
         }, 500
     return kalika_kendra.json(), 201
示例#3
0
 def set_attribute(self, payload):
     cols = [
         'teacher_name', 'teacher_code', 'isactive', 'bank_account_no',
         'bank_name', 'ifsc', 'teacher_category', 'modified_date'
     ]
     for col in cols:
         if col in payload.keys():
             setattr(self, col, payload[col])
     if 'cluster_name' in payload.keys():
         cluster = ClusterModel.find_by_cluster_name(
             payload['cluster_name'])
         if not cluster:
             return {
                 "message": f"Cluster name not found for the teacher"
             }, 401
         self.cluster_id = cluster.id
     if 'kalika_kendra_name' in payload.keys():
         kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
             payload['kalika_kendra_name'])
         if not kalika_kendra:
             return {
                 "message": f"Kalika Kendra name not found for the teacher"
             }, 401
         self.kalika_kendra_id = cluster.id
     print(self.json())
示例#4
0
 def __init__(self, **kwargs):
     cols = [
         'teacher_name', 'teacher_code', 'isactive', 'bank_account_no',
         'bank_name', 'ifsc', 'teacher_category', 'creation_date',
         'modified_date'
     ]
     for col in cols:
         setattr(self, col, None)
     for col in kwargs.keys():
         if col in cols:
             setattr(self, col, kwargs[col])
     kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
         kwargs['kalika_kendra_name'])
     # print(kalika_kendra.json())
     if not kalika_kendra:
         return {
             "message": f"Kalika Kendra name not found for the teacher"
         }, 401
     cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name'])
     if not cluster:
         return {"message": f"Cluster name not found for the teacher"}, 401
     print(cluster.json())
     self.kalika_kendra_id = kalika_kendra.id
     self.cluster_id = cluster.id
     return None
示例#5
0
 def find_by_any(cls, **kwargs):
     cols = [
         'teacher_id', 'teacher_name', 'teacher_code', 'cluster_id',
         'kalika_kendra_id', 'cluster_name', 'kalika_kendra_name',
         'isactive', 'bank_account_no', 'bank_name', 'ifsc',
         'teacher_category'
     ]
     filter_str = 'cls.query'
     if 'bank_account_no' in kwargs.keys():
         filter_str = filter_str + '.filter_by(bank_account_no="' + str(
             kwargs['bank_account_no']) + '")'
     if 'bank_name' in kwargs.keys():
         filter_str = filter_str + '.filter_by(bank_name="' + str(
             kwargs['bank_name']) + '")'
     if 'ifsc' in kwargs.keys():
         filter_str = filter_str + '.filter_by(ifsc="' + str(
             kwargs['ifsc']) + '")'
     if 'teacher_category' in kwargs.keys():
         filter_str = filter_str + '.filter_by(teacher_category="' + str(
             kwargs['teacher_category']) + '")'
     if 'creation_date' in kwargs.keys():
         filter_str = filter_str + '.filter_by(creation_date="' + str(
             kwargs['creation_date']) + '")'
     if 'modified_date' in kwargs.keys():
         filter_str = filter_str + '.filter_by(modified_date="' + str(
             kwargs['modified_date']) + '")'
     if 'teacher_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(id="' + str(
             kwargs['teacher_id']) + '")'
     if 'teacher_name' in kwargs.keys():
         filter_str = filter_str + '.filter_by(teacher_name="' + str(
             kwargs['teacher_name']) + '")'
     if 'teacher_code' in kwargs.keys():
         filter_str = filter_str + '.filter_by(teacher_code="' + str(
             kwargs['teacher_code']) + '")'
     if 'cluster_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(cluster_id="' + str(
             kwargs['cluster_id']) + '")'
     if 'kalika_kendra_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str(
             kwargs['kalika_kendra_id']) + '")'
     if 'kalika_kendra_name' in kwargs.keys():
         kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
             kwargs['kalika_kendra_name'])
         if kalika_kendra:
             kalika_kendra_id = kalika_kendra.id
             filter_str = filter_str + '.filter_by(kalika_kendra_id="' \
                          + str(kalika_kendra_id) + '")'
     if 'cluster_name' in kwargs.keys():
         cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name'])
         if cluster:
             cluster_id = cluster.id
             filter_str = filter_str + '.filter_by(cluster_id="' \
                          + str(cluster_id) + '")'
     if 'isactive' in kwargs.keys():
         filter_str = filter_str + '.filter_by(isactive="' + str(
             kwargs['isactive']) + '")'
     filter_str = filter_str + '.all()'
     return eval(filter_str)
示例#6
0
 def __init__(self, kalika_kendra_name, cluster_name, isactive=1, isdeprecated=0):
     self.kalika_kendra_name = kalika_kendra_name
     cluster = ClusterModel.find_by_cluster_name(cluster_name)
     if not cluster:
         return {"message": f"Cluster name not found for the Kalika Kendra"}, 401
     self.cluster_id = cluster.id
     self.isactive = isactive
     self.isdeprecated = isdeprecated
示例#7
0
 def set_attribute(self, payload):
     cols = ['isactive', 'isdeprecated']
     for col in cols:
         if col in payload.keys():
             setattr(self, col, payload[col])
     if 'cluster_name' in payload.keys():
         cluster = ClusterModel.find_by_cluster_name(payload['cluster_name'])
         if not cluster:
             return {"message": f"Cluster name not found for the Kalika Kendra"}, 401
         self.cluster_id = cluster.id
示例#8
0
 def delete(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _cluster_parser.parse_args()
     cluster_name = data["cluster_name"]
     cluster = ClusterModel.find_by_cluster_name(cluster_name)
     if cluster:
         cluster.delete_from_db()
         return {'message': 'Cluster deleted.'}
     return {'message': 'Cluster not found.'}, 404
示例#9
0
 def get(self):
     data = request.args
     # data = _cluster_parser.parse_args()
     cluster_name = data["cluster_name"]
     claims = get_jwt_claims()
     if claims['is_admin']:
         cluster = ClusterModel.find_by_cluster_name(cluster_name)
         if cluster:
             return cluster.json()
         return {'message': 'Cluster not found'}, 404
     return {'message': 'User not authorized to view'}
示例#10
0
 def post(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _cluster_parser.parse_args()
     cluster_name = data["cluster_name"]
     if ClusterModel.find_by_cluster_name(cluster_name):
         return {'message': f"A cluster with name '{cluster_name}' already exists."}, 400
     cluster = ClusterModel(**data)
     try:
         cluster.save_to_db()
     except Exception as e:
         return {"message": f"An error occurred inserting the cluster. Error: {repr(e)}"}, 500
     return cluster.json(), 201
示例#11
0
 def put(self):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin privilege required.'}, 401
     data = _cluster_parser.parse_args()
     for key in data.keys():
         if str(data[key]).lower() in ('none', 'null', ''):
             data[key] = None
     cluster_name = data["cluster_name"]
     cluster = ClusterModel.find_by_cluster_name(cluster_name)
     if cluster:
         cluster.set_attribute(data)
     else:
         cluster = ClusterModel(**data)
     cluster.save_to_db()
     return cluster.json()
示例#12
0
 def find_by_any(cls, **kwargs):
     filter_str = 'cls.query'
     cols = ['isactive', 'isdeprecated', 'cluster_name', 'cluster_id']
     if 'cluster_id' in kwargs.keys():
         filter_str = filter_str +  '.filter_by(cluster_id="' + str(
             kwargs['cluster_id']) + '")'
     if 'cluster_name' in kwargs.keys():
         cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name'])
         if cluster:
             cluster_id = cluster.id
             filter_str = filter_str +  '.filter_by(cluster_id="' + str(cluster_id) + '")'
     if 'isactive' in kwargs.keys():
         filter_str = filter_str +  '.filter_by(isactive="' + str(
             kwargs['isactive']) + '")'
     if 'isdeprecated' in kwargs.keys():
         filter_str = filter_str +  '.filter_by(isdeprecated="' + str(
             kwargs['isdeprecated']) + '")'
     filter_str = filter_str + '.all()'
     return eval(filter_str)
示例#13
0
 def __init__(self, **kwargs):
     cols = [
         'student_name', 'gender', 'aadhar', 'dob', 'class_std',
         'father_name', 'father_occupation', 'mother_name',
         'mother_occupation', 'contact', 'isactive', 'register_date',
         'modified_date', 'modified_by', 'kalika_kendra_id', 'cluster_id'
     ]
     for col in cols:
         setattr(self, col, None)
     for col in kwargs.keys():
         if col in cols:
             setattr(self, col, kwargs[col])
     if kwargs.get('kalika_kendra_name'):
         kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
             kwargs['kalika_kendra_name'])
         if kalika_kendra:
             self.kalika_kendra_id = kalika_kendra.id
     if kwargs.get('cluster_name'):
         cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name'])
         if cluster:
             self.cluster_id = cluster.id
     return None
示例#14
0
 def find_by_cluster_name(cls, cluster_name):
     cluster = ClusterModel.find_by_cluster_name(cluster_name)
     if cluster:
         return cls.query.filter_by(cluster_id=cluster.id).first()
示例#15
0
 def find_by_student_by_any(cls, **kwargs):
     print(kwargs)
     filter_str = 'cls.query'
     if 'contact' in kwargs.keys():
         filter_str = filter_str + '.filter_by(contact="' + str(
             kwargs['contact']) + '")'
     if 'isactive' in kwargs.keys():
         filter_str = filter_str + '.filter_by(isactive="' + str(
             kwargs['isactive']) + '")'
     if 'register_date' in kwargs.keys():
         filter_str = filter_str + '.filter_by(register_date="' + str(
             kwargs['register_date']) + '")'
     if 'modified_date' in kwargs.keys():
         filter_str = filter_str + '.filter_by(modified_date="' + str(
             kwargs['modified_date']) + '")'
     if 'modified_by' in kwargs.keys():
         filter_str = filter_str + '.filter_by(modified_by="' + str(
             kwargs['modified_by']) + '")'
     if 'class_std' in kwargs.keys():
         filter_str = filter_str + '.filter_by(class_std="' + str(
             kwargs['class_std']) + '")'
     if 'kalika_kendra_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str(
             kwargs['kalika_kendra_id']) + '")'
     if 'cluster_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(cluster_id="' + str(
             kwargs['cluster_id']) + '")'
     if 'kalika_kendra_name' in kwargs.keys():
         kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name(
             kwargs["kalika_kendra_name"])
         print(kalika_kendra.json())
         if kalika_kendra:
             kalika_kendra_id = kalika_kendra.id
             filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str(
                 kalika_kendra_id) + '")'
     if 'cluster_name' in kwargs.keys():
         cluster = ClusterModel.find_by_cluster_name(kwargs["cluster_name"])
         if cluster:
             cluster_id = cluster.id
             filter_str = filter_str + '.filter_by(cluster_id="' + str(
                 kwargs['cluster_id']) + '")'
     if 'father_occupation' in kwargs.keys():
         filter_str = filter_str + '.filter_by(father_occupation="' + str(
             kwargs['father_occupation']) + '")'
     if 'mother_name' in kwargs.keys():
         filter_str = filter_str + '.filter_by(mother_name="' + str(
             kwargs['mother_name']) + '")'
     if 'mother_occupation' in kwargs.keys():
         filter_str = filter_str + '.filter_by(mother_occupation="' + str(
             kwargs['mother_occupation']) + '")'
     if 'student_id' in kwargs.keys():
         filter_str = filter_str + '.filter_by(student_id="' + str(
             kwargs['student_id']) + '")'
     if 'student_name' in kwargs.keys():
         filter_str = filter_str + '.filter_by(student_name="' + str(
             kwargs['student_name']) + '")'
     if 'gender' in kwargs.keys():
         filter_str = filter_str + '.filter_by(gender="' + str(
             kwargs['gender']) + '")'
     if 'aadhar' in kwargs.keys():
         filter_str = filter_str + '.filter_by(aadhar="' + str(
             kwargs['aadhar']) + '")'
     if 'dob' in kwargs.keys():
         filter_str = filter_str + '.filter_by(dob="' + str(
             kwargs['dob']) + '")'
     filter_str = filter_str + '.all()'
     return eval(filter_str)