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


Python Task.result_dir方法代码示例

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


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

示例1: task_new

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import result_dir [as 别名]
def task_new(request):

  user = request.user

  dataset_id = request.GET.get('dataset_id', '')
  program_id = request.GET.get('model_id', '')

  try:
    dataset_id = int(dataset_id)
    program_id = int(program_id)
  except ValueError:
    raise Http404();

  if request.method == 'POST':
    query_dataset = (Q(id=dataset_id))
    dataset = Dataset.objects.filter(query_dataset)[0]

    query_program = (Q(id=program_id))
    program = Program.objects.filter(query_program)[0]
    if request.POST["options"] == "":
      task_options = ""
    else:
      if program_id == 1:
        task_options = "-t " + request.POST["options"]
      else:
        task_options = "-l " + request.POST["options"]

    create_date = datetime.datetime.now()
    access = request.POST["access"]

    new_task = Task(owner = user, data = dataset, program = program, options = task_options, create_date = create_date, progress = "waiting", result_dir = "", access = access)

    new_task.save()
    program.task_num += 1
    program.save()

    new_task_id = new_task.id
    #result_dir = os.path.join(settings.USR_RESULT_ROOT, str(new_task_id))
    #if not os.path.exists(result_dir):
    #  os.makedirs(result_dir)
    new_task.result_dir = str(new_task_id)
    new_task.save()

    # return render_to_response("task/success.html", RequestContext(request, {'user': user, 'new_task': new_task}))
    return HttpResponseRedirect("/tasks/%s/" % new_task.id)
  else:
    dataset = Dataset.objects.filter(Q(id=dataset_id))
    program = Program.objects.filter(Q(id=program_id))
    if len(dataset) == 0 or len(program) == 0:
      notice="Couldn't find the dataset(ID="+str(dataset_id)+")or model(ID="+str(program_id)+")"
      return render_to_response('task/error.html', RequestContext(request, {'notice': notice}))

    dataset = dataset[0]
    program = program[0]
    dataset_name = dataset.name
    program_name = program.name

    return render_to_response('task/new.html', RequestContext(request, {'dataset_id': dataset_id, 'program_id': program_id, 'dataset_name': dataset_name, 'program_name': program_name}))
开发者ID:TPNguyen,项目名称:bigdata,代码行数:60,代码来源:views.py

示例2: task_submit

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import result_dir [as 别名]
def task_submit(request):

  user = request.user

  if user.is_authenticated():

    dataset_list = Dataset.objects.filter(Q(owner__id=user.id) | Q(access="public")).order_by('id')
    program_list = Program.objects.all()

    if request.method == 'POST':

      data_id = request.POST.get('data', 0)
      program_id = request.POST.get('program', 0)
      print data_id, program_id

      if data_id and program_id:

        query_dataset = (Q(id=data_id))
        dataset = Dataset.objects.filter(query_dataset)[0]

        query_program = (Q(id=program_id))
        program = Program.objects.filter(query_program)[0]
        task_options = request.POST["options_"+str(program_id)]

        create_date = datetime.datetime.now()
        access = request.POST["access"]

        new_task = Task(owner = user, data = dataset, program = program, options = task_options, create_date = create_date, progress = "waiting", result_dir = "", access = access)

        new_task.save()
        new_task_id = new_task.id
        #result_dir = os.path.join(settings.USR_RESULT_ROOT, str(new_task_id))
        #if not os.path.exists(result_dir):
        #  os.makedirs(result_dir)
        new_task.result_dir = str(new_task_id) # relative path
        new_task.save()

        return render_to_response("task/success.html", RequestContext(request, {'user': user, 'new_task': new_task}))
      else:
        if not data_id:
          notice = "Please select a dataset."
        else:
          notice = "Please select a model."
        return render_to_response("task/submit.html", RequestContext(request, {'user': user, 'dataset_list': dataset_list, 'program_list': program_list, 'notice': notice}))

    else:
      return render_to_response("task/submit.html", RequestContext(request, {'user': user, 'dataset_list': dataset_list, 'program_list': program_list}))

  else:
    notice = "You should be logged in to submit a new task."
    return render_to_response('task/submit.html', RequestContext(request, {'notice': notice}))
开发者ID:TPNguyen,项目名称:bigdata,代码行数:53,代码来源:views.py


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