def get(self, id):
     department = departmentModel.find_by_id(id)
     if department:
         if department.Status == True:
             return department.json()
         else:
             return {"message": "no record found"}, 404
     else:
         return {"message": "no record found"}, 404
    def delete(self, id):
        department = departmentModel.find_by_id(id)
        if department:
            if department.Status == True:
                user_data_del = departmentModel.update_by_status(id)
                data = {"message": "record deleted", "id": department.id}
                return (data)
            else:
                return (' no record found'), 404

        else:
            return ("no record   found"), 404
Exemple #3
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
    def put(self, id):
        data = department.parser.parse_args()

        Department = departmentModel.find_by_id(id)

        if Department and Department.Status == True:

            Department.name = data['name']
            Department.save_to_db()

        else:
            return ("no record found"), 404

        return {
            "message": "department updated successfully ",
            'id': Department.id
        }, 201
Exemple #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