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


Python Task.cource方法代码示例

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


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

示例1: handle

# 需要导入模块: from tasks.models import Task [as 别名]
# 或者: from tasks.models.Task import cource [as 别名]
    def handle(self, **options):
        cource_id = options['cource_id']
        if cource_id:
            cource_id = int(cource_id)

        if not cource_id:
            raise Exception("--cource_id is required!")

        cource_src = Cource.objects.get(id=cource_id)
        cource_dst = Cource()

        cource_dst.__dict__ = copy.deepcopy(cource_src.__dict__)
        cource_dst.id = None
        cource_dst.name += " copy"
        cource_dst.save()

        for task_src in Task.objects.filter(cource=cource_src):
            if task_src.has_parent():
                continue

            print "Copy task {0}".format(task_src.title.encode("utf-8"))
            task_dst = Task()
            task_dst.__dict__ = copy.deepcopy(task_src.__dict__)
            task_dst.id = None
            task_dst.cource = cource_dst
            task_dst.save()

            for subtask_src in task_src.get_subtasks():
                print ">Copy subtask {0}".format(subtask_src.title.encode("utf-8"))
                subtask_dst = Task()

                subtask_dst.__dict__ = copy.deepcopy(subtask_src.__dict__)
                subtask_dst.id = None
                subtask_dst.parent_task = task_dst
                subtask_dst.cource = cource_dst
                subtask_dst.save()
开发者ID:gebetix,项目名称:anytask,代码行数:38,代码来源:cource_copy.py

示例2: add_task

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

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

    for key in ['cource_id', 'group_id', 'parent_id', 'task_title', 'task_text', 'max_score']:
        if key not in request.POST:
            return HttpResponseForbidden()

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

    try:
        cource_id = int(request.POST['cource_id'])
        task_title = request.POST['task_title'].strip()
        task_text = request.POST['task_text'].strip()
        max_score = int(request.POST['max_score'])

        group_id = request.POST['group_id']
        if not group_id or group_id == 'null':
            group_id = None
        else:
            group_id = int(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()

    cource = get_object_or_404(Cource, id = cource_id)
    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 cource.user_can_edit_cource(user):
        return HttpResponseForbidden()

    max_weight_query = Task.objects.filter(cource=cource)
    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.cource = cource
    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
    task.is_hidden = hidden_task
    task.updated_by = user
    task.save()

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


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