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


Python Task.group方法代码示例

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


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

示例1: add_task

# 需要导入模块: from tasks.models import Task [as 别名]
# 或者: from tasks.models.Task import group [as 别名]
def add_task(request):
    user = request.user

    if not request.method == 'POST':
        return HttpResponseForbidden()

    hidden_task = False
    if 'hidden_task' in request.POST:
        hidden_task = True

    try:
        course_id = int(request.POST['course_id'])
        task_title = request.POST['task_title'].strip()
        task_text = request.POST['task_text'].strip()
        max_score = int(request.POST['max_score'])
        course = get_object_or_404(Course, id = course_id)
        if course.contest_integrated:
            contest_id = int(request.POST['contest_id'])
            problem_id = request.POST['problem_id'].strip()

        task_group_id = request.POST['task_group_id']
        group_id = request.POST['group_id']
        if task_group_id == "":
            group_id = None
        else:
            group_id = int(task_group_id)

        parent_id = request.POST['parent_id']
        if not parent_id or parent_id == 'null':
            parent_id = None
        else:
            parent_id = int(parent_id)

    except ValueError: #not int
        return HttpResponseForbidden()

    group = None
    if group_id is not None:
        group = get_object_or_404(Group, id = group_id)
    parent = None
    if parent_id is not None:
        parent = get_object_or_404(Task, id = parent_id)

    if not course.user_can_edit_course(user):
        return HttpResponseForbidden()

    max_weight_query = Task.objects.filter(course=course)
    if group:
        max_weight_query = max_weight_query.filter(group=group)
    if parent:
        max_weight_query = max_weight_query.filter(parent_task=parent)

    tasks = max_weight_query.aggregate(Max('weight'))
    _, max_weight = tasks.items()[0]
    if max_weight is None:
        max_weight = 0
    max_weight += 1

    task = Task()
    task.course = course
    task.group = group
    task.parent_task = parent
    task.weight = max_weight
    task.title = task_title
    task.task_text = task_text
    task.score_max = max_score
    if course.contest_integrated:
        task.contest_id = contest_id
        task.problem_id = problem_id
    task.is_hidden = hidden_task
    task.updated_by = user
    task.save()

    return HttpResponse("OK")
开发者ID:BooleT37,项目名称:anytask,代码行数:76,代码来源:views.py

示例2: pinax_handle_uploaded_file

# 需要导入模块: from tasks.models import Task [as 别名]
# 或者: from tasks.models.Task import group [as 别名]
def pinax_handle_uploaded_file(file, user_id):
    user_object = User.objects.get(pk=user_id)
    csv_reader = csv.DictReader(file, fieldnames=['date','start','end','duration','project','task'])
    line_data = []
    for line in csv_reader:
        line_data.append(line)

    total_time = 0
    val = {}
    pickles = {'projects': [], 'tasks': [], 'slices': []}
    for line in line_data[1:]:
        begin = datetime.strptime('T'.join((line['date'], line['start'])), '%Y-%m-%dT%H:%M')
        end = datetime.strptime('T'.join((line['date'], line['end'])), '%Y-%m-%dT%H:%M')
        total_time += int(line['duration'])
        if not val.has_key(line['project']):
            project_set = Project.objects.filter(name=line['project'], member_users=user_id)
            if  project_set:
                if len(project_set) > 1:
                    project, project_created_msg, project_created_bool = create_pinax_project(user_object, line)
                else:
                    project = project_set[0]
                    project_created_msg = _('Found project, and will add tasks and timeslices to the existing project.')
                    project_created_bool = False
            else:
                project_set = Project.objects.filter(name=line['project'])
                if project_set:
                    if len(project_set) >1:
                        project, project_created_msg, project_created_bool = create_pinax_project(user_object, line)
                    else:
                        project = project_set[0]
                        project_created_msg = _('Found project will add tasks and timeslices to the existing project.')
                        project_created_bool = False
                else:
                    project, project_created_msg, project_created_bool = create_pinax_project(user_object, line)
            val[line['project']] = {'created': project_created_bool, 'message': project_created_msg, 'project_object': project, 'tasks': {}}
            pickles['projects'].append(project)

        if not val[line['project']]['tasks'].has_key(line['task']):
            if val[line['project']]['created']:
                task = Task()
                task.summary = line['task']
                task.creator = user_object
                task.group = val[line['project']]['project_object']
                task.created = line['date']
                task_created_bool = True
            else:
                task_set = Task.objects.filter(summary=line['task'], creator=user_object, object_id=project.id)
                if not task_set or len(task_set) > 1:
                    task = Task()
                    task.summary = line['task']
                    task.creator = user_object
                    task.group = val[line['project']]['project_object']
                    task.created = line['date']
                    task_created_bool = True
                else:
                    task = task_set[0]
                    task_created_bool = False
            val[line['project']]['tasks'][line['task']]={'created': task_created_bool, 'task_object': task, 'slices': []}
            pickles['tasks'].append(task)

        if val[line['project']]['tasks'][line['task']]['created']:
            tslice = TimeSlice()
            tslice.begin = begin
            tslice.duration = int(line['duration'])
            tslice.task = val[line['project']]['tasks'][line['task']]['task_object']
            tslice.user = user_object
            slice_created_bool = True
        else:
            slice_set = TimeSlice.objects.filter(begin=begin, duration=int(line['duration']), task=task, user=user_object)
            if slice_set:
                tslice = slice_set[0]
                slice_created_bool = False
            else:
                tslice = TimeSlice()
                tslice.begin = begin
                tslice.duration = int(line['duration'])
                tslice.task = val[line['project']]['tasks'][line['task']]['task_object']
                tslice.user = user_object
                slice_created_bool = True
        val[line['project']]['tasks'][line['task']]['slices'].append(tslice)
        pickles['slices'].append(tslice)

    total_time = str(int(total_time/3600.0))+'h'

    # Okay, now we have processed the data, lets write it to a couple of files.
    import_data = DataImport.objects.create(user=user_object)
    file_name = hashlib.sha1(user_object.username + str(time.time())).hexdigest()
    import_data.complete_data.save(file_name, ContentFile(pickle.dumps(pickles)))
    import_data.partial_data.save(file_name, ContentFile(pickle.dumps(line_data[1:11])))
    import_data.save()

    return import_data.id
开发者ID:areski,项目名称:djime,代码行数:94,代码来源:importer.py


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