Пример #1
0
 def delete(self, id):
     designation = designationModel.find_by_id(id)
     if designation:
         if designation.Status == True:
             designation.update_by_status(id)
             data = {"message": "record deleted", "id": designation.id}
             return (data)
         else:
             return {'message': 'designation not found.'}, 404
     else:
         return {"message": "no record found"}, 404
Пример #2
0
 def get(self, id):
     # token = request.headers.get('Authorization')
     # split_token = token.split("Bearer ")[1]
     # data = userModel.find_by_token(split_token)
     # if data and data.accesstoken == split_token:
     designation = designationModel.find_by_id(id)
     if designation:
         if designation.Status == True:
             return designation.json()
         else:
             return {'message': 'designation not found'}, 404
     else:
         return ("designation not found"), 404
Пример #3
0
    def put(self, id):
        data = designation.parser.parse_args()

        Designation = designationModel.find_by_id(id)

        if Designation and Designation.Status == True:

            Designation.name = data['name']
            Designation.save_to_db()
        else:
            return {"message": "no record found"}, 404

        return {
            "message": "designation updated successfully ",
            'id': Designation.id
        }, 201
Пример #4
0
    def get(self, id):
        user = userModel.find_by_id(id)
        # print(user)
        if user and user.Status == True:
            depart = user.department_id
            design = user.designation_id
            depart_data = departmentModel.find_by_id(depart)
            design_data = designationModel.find_by_id(design)
            if depart_data and design_data:
                res_depart = depart_data.json()
                res_design = design_data.json()
                user.department_id = res_depart
                user.designation_id = res_design
                return user.json()

        else:
            return {"message": "no record found"}, 404
Пример #5
0
    def get(self):
        args = request.args
        if "page" in args and args.get("page") != '':
            page = int(args.get('page'))
            page = int(page - 1)
        else:
            page = 1
        if "per_page" in args and args.get("per_page") != '':
            per_page = int(args.get('per_page'))
        else:
            per_page = apps.config["PER_PAGE"]
        if "flag" in args and args.get("flag") == "active" or args.get(
                "flag") == '':
            data = list(
                map(
                    lambda x: x.json(),
                    userModel.query.filter_by(Status=True).order_by(
                        userModel.id.desc())))
            if data:
                # print(data)
                for i in data:
                    depart = i['department_id']
                    design = i['designation_id']
                    # print(depart)
                    dept_data = departmentModel.find_by_id(i['department_id'])
                    design_data = designationModel.find_by_id(
                        i['designation_id'])
                    # print(dept_data)

                    if dept_data and design_data:
                        res_depart = dept_data.json()
                        # print(res_de)
                        res_design = design_data.json()
                        # print(res_design)
                        i['department_id'] = res_depart
                        i['designation_id'] = res_design
                my_list = [
                    data[i:i + per_page]
                    for i in range(0, len(data), per_page)
                ][page]
                if page != -1:
                    print("sarath")
                    length = len(data)
                    p = length / per_page
                    page_number = math.ceil(p)
                    return {"data": my_list, "maximum page=": page_number}
                else:
                    return {"message": "page starts from 1"}
            else:
                return {"message": "no record found"}, 404
            # if args.get("status") ==''and args.get("status")=="active":
            #     print("sarathssssssssssssssssssss")

        elif "flag" in args and args.get("flag") == "inactive":
            data = list(
                map(
                    lambda x: x.json(),
                    userModel.query.filter_by(Status=False).order_by(
                        userModel.id.desc())))
            if data:
                # print(data)
                for i in data:
                    depart = i['department_id']
                    design = i['designation_id']
                    # print(depart)
                    dept_data = departmentModel.find_by_id(i['department_id'])
                    design_data = designationModel.find_by_id(
                        i['designation_id'])
                    # print(dept_data)

                    if dept_data and design_data:
                        res_depart = dept_data.json()
                        # print(res_de)
                        res_design = design_data.json()
                        # print(res_design)
                        i['department_id'] = res_depart
                        i['designation_id'] = res_design
                my_list = [
                    data[i:i + per_page]
                    for i in range(0, len(data), per_page)
                ][page]
                if page != -1:
                    print("sarath")
                    length = len(data)
                    p = length / per_page
                    page_number = math.ceil(p)
                    return {"data": my_list, "maximum page=": page_number}
                else:
                    return {"message": "page starts from 1"}
            else:
                return {"message": "no record found"}, 404