本文整理汇总了Python中request.models.Request.status方法的典型用法代码示例。如果您正苦于以下问题:Python Request.status方法的具体用法?Python Request.status怎么用?Python Request.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.models.Request
的用法示例。
在下文中一共展示了Request.status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tool_detail
# 需要导入模块: from request.models import Request [as 别名]
# 或者: from request.models.Request import status [as 别名]
def tool_detail(request, id):
if not is_user_logged_in(session=request.session):
return redirect(reverse('sign_in'))
if 'is_shared_zone' not in request.session:
return redirect(reverse('shared_zone:index'))
if request.method == 'GET':
try:
tool = Tool.objects.get(id=id, enabled=1)
pickup_times = User.objects.filter(pk=tool.owner.id).values_list('pickup_days', 'pickup_times')
pickup_times = list(pickup_times)[0]
if pickup_times[0] is None or pickup_times[1] is None:
pickup_times = None
if tool.is_shared_from_home():
pickup_address = tool.owner.get_address()
else:
pickup_address = SharedZone.objects.get(zipcode=tool.owner.zipcode).address
may_leave_comment = False
if Request.objects.filter(borrower=request.session["cool_user"], tool=id, status=Request.RETURNED, may_leave_comment=True).count() > 0:
may_leave_comment = True
context = {
'pickup_address': pickup_address,
'tool': tool,
'borrow': True,
'pickup_times': pickup_times,
'id': id,
'may_leave_comment': may_leave_comment
}
if "format" in request.GET and request.GET["format"] == "json":
data = serializers.serialize("json", [tool])
if pickup_times:
pu_times = {
'days': pickup_times[0],
'hours': pickup_times[1],
}
else:
pu_times = None
response = {'statusCode': 200, 'message': 'OK', 'data': data, 'media': settings.MEDIA_URL, 'pickup_times': pu_times, 'pickup_address': pickup_address}
return JsonResponse(response)
except Tool.DoesNotExist:
context = {
"not_found": 'The item you requested does not exist',
'borrow': True,
'id': id
}
if "format" in request.GET and request.GET["format"] == "json":
response = {'statusCode': 404, 'message': 'The item you requested does not exist'}
return JsonResponse(response)
except Exception as e:
print(e)
if request.method == 'POST':
try:
tool = Tool.objects.get(pk=id, enabled=1)
borrower = User.objects.get(pk=request.session["cool_user"], enabled=1)
tool_request = Request(tool=tool, lender=tool.owner, borrower=borrower, zipcode=borrower.zipcode, shared_from=tool.shared_from)
success_message = "The tool has been requested successfully! Please wait for owner's approval."
if tool.shared_from == Tool.SHED:
tool_request.comment = "Borrowing request approved!"
success_message = "Borrowing request approved!"
tool_request.status = Request.APPROVED
tool.status = Tool.BORROWED
tool.save()
try:
request.session['notification_s'] += 1
except KeyError:
request.session['notification_s'] = 1
try:
optional = "Please return the tool as soon as you finish using it. Remind the shed coordinator to mark the tool as returned."
send_email('request_action.txt', 'request_action.html', {'tool_name': tool_request.tool.name, 'request_status': tool_request.get_status_choices(), 'message': tool_request.comment, 'optional': optional}, "Borrowing Request Information", tool_request.borrower.email)
except Exception as e:
print(e)
tool_request.save()
if tool_request.tool.shared_from == Tool.HOME:
try:
notification = Notification.objects.get(user=tool.owner)
except Notification.DoesNotExist:
notification = Notification(user=tool.owner)
notification.save()
notification.increment_received()
notification.save()
try:
send_email('borrowing_request.txt', 'borrowing_request.html', {'borrower': tool_request.borrower.__str__(), 'tool': tool_request.tool.name}, "Borrowing Request Information", tool_request.lender.email)
except Exception as e:
print(e)
context = {
'tool': tool,
'borrow': True,
'message': success_message,
'id': id
}
if "format" in request.POST and request.POST["format"] == "json":
response = {'statusCode': 200, 'message': success_message}
return JsonResponse(response)
except Tool.DoesNotExist:
context = {
"not_found": 'The item you requested does not exist',
'borrow': True,
'id': id
}
if "format" in request.POST and request.POST["format"] == "json":
#.........这里部分代码省略.........