本文整理汇总了Python中response.Response.success方法的典型用法代码示例。如果您正苦于以下问题:Python Response.success方法的具体用法?Python Response.success怎么用?Python Response.success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类response.Response
的用法示例。
在下文中一共展示了Response.success方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toast
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def toast():
uid = request.args.get('uid')
body = request.args.get('body')
toast = Toast(uid, body, datetime.now(), 0, 0)
db.session.add(toast)
db.session.commit()
return jsonify(Response.success(msg="吐槽成功"))
示例2: list_toasts
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def list_toasts():
page = int(request.args.get('page'))
uid = int(request.args.get('uid'))
paginate = Toast.query.order_by(Toast.creation_time.desc()).paginate(page, ITEMS_PER_PAGE, False)
toast_list = paginate.items
res = []
for item in toast_list:
item_res = {
"toast_id":item.id,
"body":item.body,
"time":item.creation_time.strftime("%Y-%m-%d %H:%M:%S"),
"trumpet_count":item.trumpet_count,
"shit_count":item.shit_count,
"trumpet":0,
"shit":0
}
toast_operation_list = ToastOperation.query.filter_by(uid=uid).filter_by(toast_id=item.id).all()
for operation in toast_operation_list:
if operation.type == 0:
item_res['shit'] = 1
if operation.type == 1:
item_res['trumpet'] = 1
res.append(item_res)
return jsonify(Response.success(msg="拉取成功", data=res))
示例3: shit
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def shit():
toast_id = int(request.args.get('toastId'))
uid = int(request.args.get('uid'))
shit_operation = ToastOperation(uid, toast_id, SHIT_OPERATION, datetime.now())
db.session.add(shit_operation)
db.session.commit()
# 让记录+1
toast = Toast.query.get(toast_id)
if toast is not None:
toast.shit_count += 1
db.session.commit()
else:
return jsonify(Response.fail(msg="找不到这条toast"))
return jsonify(Response.success(msg="shit成功"))
示例4: insertInfo
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def insertInfo():
name = request.args.get('name')
phone = request.args.get('phone')
position = request.args.get('position')
if phone is None or len(phone.strip())<1 or not phone.isdigit():
return jsonify(Response.fail(msg="信息有误"))
items = Scanner.query.filter_by(phone=phone).all()
if len(items)>0:
return jsonify(Response.fail(msg="该手机号已录入,请更换手机号"))
else:
scanner = Scanner(name, phone, position)
db.session.add(scanner)
db.session.commit()
return jsonify(Response.success(msg="插入成功", data=scanner.id))
示例5: getToast
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def getToast():
toast_id = int(request.args.get('toastId'))
item = Toast.query.get(toast_id)
if item is not None:
res = {
"toast_id":item.id,
"body":item.body,
"time":item.creation_time.strftime("%Y-%m-%d %H:%M:%S"),
"trumpet_count":item.trumpet_count,
"shit_count":item.shit_count
}
return jsonify(Response.success(msg="拉取成功", data=res))
else:
return jsonify(Response.fail(msg="找不到这条toast"))
示例6: verify
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def verify():
info = request.args.get('info')
if info is None or len(info.strip())<1:
return jsonify(Response.fail(msg="信息有误,验证失败"))
else:
infoSegs = info.strip().split('-');
if(len(infoSegs) == 2):
item = Scanner.query.get(infoSegs[0])
if item is None or cmp(item.phone, infoSegs[1])!=0:
return jsonify(Response.fail(msg="信息有误,验证失败"))
if item.valid == 0:
return jsonify(Response.fail(msg="该二维码已被验证,不可重复验证"))
item.valid = 0
db.session.commit()
res = {'name':item.name, 'phone':item.phone, 'position':item.position}
return jsonify(Response.success(msg="验证通过", data=res))
return jsonify(Response.fail(msg="信息有误,验证失败"))
示例7: add_user
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def add_user():
user = ToastUser(datetime.now())
db.session.add(user)
db.session.commit()
return jsonify(Response.success(msg="插入成功", data=user.id))
示例8: make_request
# 需要导入模块: from response import Response [as 别名]
# 或者: from response.Response import success [as 别名]
def make_request(url, **kwargs):
""" Makes a POST, GET or HEAD request to the passed URL with the passed arguments,
available arguments are:
Argument..........Type..........Description
method............string........Can be either get, post or head, decides
which type of request is made. Default GET.
data..............dict..........The data to send when using a POST request.
allow_redir.......bool..........Whether or not the request follows redirects,
default False.
headers...........dict..........Additional header information for the request,
by default a User-Agent and accepted language
is set, to see the full headers access
'use_requests.default_headers'.
is_json...........bool..........Whether or not the response contains json data,
this comes in handy when using APIs or the like,
default False.
timeout...........int...........The amount of time the request will wait until
completion, default 10 seconds.
The return value of this method is of type dict, it contains:
Key...........Type..........Description
success.......bool..........Whether or not the request was successfull.
status_code...int...........The status code of the made request.
error_msg.....string........Only exists when the request failed.
source........string/json...The source code of a website or json data when
the 'is_json' bool was set. This key is missing
when the request failed.
headers.......dict..........The returned headers of the server, this is a
case in-sensitive dictionary. This key is missing
when the request failed.
"""
args = {"method": "get", "data": None, "headers": default_headers, "timeout": 5,
"allow_redir": False, "is_json": False}
args.update(kwargs)
try: # Prepare the request
if args["method"].lower() not in ("get", "post", "head"):
args["method"] = "get"
session = requests.Session()
req = requests.Request(args["method"], url, args["headers"],
data=args["data"])
prepared = req.prepare()
# Make the request
req = session.send(prepared, allow_redirects=args["allow_redir"],
timeout=args["timeout"], verify=False)
# Start populating the response object
response = Response(url)
response.status_code = req.status_code
if(req.status_code not in (200, 301, 302, 307)):
raise requests.exceptions.RequestException("Status code was not OK")
except(requests.exceptions.RequestException) as e:
response.error_msg = e.message
else:
response.success = True
response.headers = req.headers
response.source = req.content
# Act upon the is_json argument
if(args["is_json"]):
response.source = req.json()
return response