Exemplo n.º 1
0
 def get(self):
     args = allParser.getParser.parse_args()
     verify_result = verify_token(args["token"])
     if not verify_result:
         return make_result(code=Code.ERROR,msg="token失效")
     args.pop('token')
     if args["type"] == "all":
         data = dbclient.list_all(table)
         length = len(data)
         data = pagenation(data,args["page"] - 1,args["limit"])
         if data:
             response = make_result(data,Code.SUCCESS,count=length)
         elif data == False:
             response = make_result(code=Code.ERROR,msg='获取数据失败')
         return response
     else:
         data = []
         if args['name']:
             data = dbclient.list_one(table,{"name":args['name']})
             data = data[0]
         elif args['id']:
             data = dbclient.list_one(table,{"id":args['id']})
             data = data[0]
         if not data:
             return make_result(data,Code.ERROR,msg='查找数据失败')
         return make_result(data,Code.SUCCESS)
Exemplo n.º 2
0
 def get(self):
     args = allParser.getUserParser.parse_args()
     verify_result = verify_token(args["token"])
     if not verify_result:
         return make_result(code=Code.ERROR, msg="token错误")
     args.pop('token')
     if args['type'] == 'all':
         m_result = dbclient.list_all(table)
         if not m_result:
             return make_result(code=Code.ERROR, msg="查询错误")
         for index, i in enumerate(m_result):
             m_result[index] = {
                 "id": i["id"],
                 "username": i["username"],
                 "name": i['name'],
                 "phone": i['phone'],
                 "role": i['role'],
                 "class": i["class"]
             }
         length = len(m_result)
         m_result = pagenation(m_result, args["page"] - 1, args["limit"])
         response = make_result(m_result, code=Code.SUCCESS, count=length)
     else:
         if args['username']:
             m_result = dbclient.list_one(table,
                                          {"username": args["username"]})
             if len(m_result) == 0:
                 return make_result(code=Code.ERROR, msg="没有该用户")
             m_result = m_result[0]
             m_result.pop('endtime')
             m_result.pop('token')
             response = make_result(m_result, code=Code.SUCCESS)
         elif args['id']:
             m_result = dbclient.list_one(table, {"id": args["id"]})
             m_result = m_result[0]
             if not m_result:
                 return make_result(code=Code.ERROR, msg="没有该用户")
             m_result.pop('endtime')
             m_result.pop('token')
             response = make_result(m_result, code=Code.SUCCESS)
     return response