当前位置: 首页>>代码示例>>Python>>正文


Python Task.to_dict方法代码示例

本文整理汇总了Python中task.models.Task.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Task.to_dict方法的具体用法?Python Task.to_dict怎么用?Python Task.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在task.models.Task的用法示例。


在下文中一共展示了Task.to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new

# 需要导入模块: from task.models import Task [as 别名]
# 或者: from task.models.Task import to_dict [as 别名]
def new(request):
    resp = {}
    if request.method != 'POST':
        resp['status'] = 1
        resp['message'] = 'Wrong http method!'
        return HttpResponse(json.dumps(resp), content_type = 'application/json')
    approximate_fplace = request.POST['approximate_fplace']
    detailed_fplace = request.POST['detailed_fplace']
    pto = request.POST['pto']
    code = request.POST['code']
    fetch_btime = request.POST['fetch_btime']
    fetch_etime = request.POST['fetch_etime']
    owner = request.POST['owner']
    give_time = request.POST['give_time']
    curtime = datetime.datetime.now()
    user = User.objects.filter(id = owner)
    if not user.exists():
        resp['status'] = 1
        resp['message'] = 'No such user'
        return HttpResponse(json.dumps(resp), content_type = 'application/json')
    elif len(user) > 1:
        resp['status'] = 2
        resp['message'] = 'Too many user found, impossible!'
        return HttpResponse(json.dumps(resp), content_type = 'application/json')

    if user[0].status == 0:
        resp['status'] = 3
        resp['message'] = 'Not authenticated yet!'
        return HttpResponse(json.dumps(resp), content_type='application/json')

    if user[0].bonus <= 0:
        resp['status'] = 4
        resp['message'] = 'You do not have enough bonus!'
        return HttpResponse(json.dumps(resp), content_type='application/json')

    task = Task(approximate_fplace = approximate_fplace, detailed_fplace = detailed_fplace,
                pto = pto, code = code, fetch_btime = datetime.datetime.strptime(fetch_btime, '%Y-%m-%d %H:%M:%S'),
                fetch_etime = datetime.datetime.strptime(fetch_etime, '%Y-%m-%d %H:%M:%S'), owner = user[0],
                give_time = datetime.datetime.strptime(give_time, '%Y-%m-%d %H:%M:%S'), build_time = curtime)
    task.save()
    if task.id is None:
        resp['status'] = 4
        resp['message'] = 'create task error'
        return HttpResponse(json.dumps(resp), content_type = 'application/json')
    else:
        user[0].bonus -= 1
        user[0].save()
        resp['status'] = 0
        resp['message'] = 'Success'
        info = task.to_dict()
        info['owner'] = task.owner.to_dict()
        resp['data'] = info
        return HttpResponse(json.dumps(resp), content_type = 'application/json')
开发者ID:wyxpku,项目名称:pkucourier,代码行数:55,代码来源:views.py


注:本文中的task.models.Task.to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。