예제 #1
0
파일: base.py 프로젝트: clickwork/clickwork
def next_task(guts):
    """Get the next task for a user, and redirect.
    
    It is possible this belongs with the task views.

    # TODO: Testing
    
    The input request should have a logged in user. The result
    should be:
     * If the user has nothing to do, redirect to the home page.
     * If the user has a pending review, redirect to that review's page.
     * If the user has a task in an auto-review project to look at,
       redirect to that page.
     * If the user either has a WorkInProgress or there is a task
       available for them to work on, a redirect to that task's page.
     * If a WorkInProgress exists, the .start_time property of the
       WIP should be updated to the current time.
     * If no WIP exists, one should be created with the next available
       task and the current logged in user.
    """
    review = Review.objects.filter(response__user=guts.user, complete=False)
    if review.count():
        return ViewResponse(main.views.task.next_review)

    auto_review_pending = AutoReview.objects.filter(user=guts.user,
                                                    start_time__isnull=False,
                                                    end_time__isnull=True)
    if auto_review_pending.exists():
        return ViewResponse(main.views.task.task_view,
                            auto_review_pending[0].task.id)
    new_auto_reviews = AutoReview.objects.filter(
        user=guts.user, task__project__priority__gte=0,
        start_time__isnull=True, end_time__isnull=True).order_by("-task__project__priority")
    if new_auto_reviews.exists():
        auto_review = new_auto_reviews[0]
        auto_review.start_time = datetime.datetime.now()
        auto_review.full_clean()
        auto_review.save()
        return ViewResponse(main.views.task.task_view,
                            auto_review.task.id)

    wip = None
    wips = WorkInProgress.objects.filter(user=guts.user)
    if wips.count():
        wip = wips[0]
        wip.start_time = datetime.datetime.now()
        wip.full_clean()
        wip.save()
    else:
        task = Task.objects.next_for(guts.user)
        if task:
            wip = WorkInProgress(user=guts.user, task=task)
            wip.full_clean()
            wip.save()
    if wip:
        return ViewResponse(main.views.task.task_view, wip.task.id)
    else:
        return ViewResponse(home)
예제 #2
0
파일: task.py 프로젝트: clickwork/clickwork
def unmerge(get, guts, task_id):
    """Given a task that has already been merged, undo the merge, give
    the user a WIP for re-merging it, and redirect to the page for
    handling that WIP.  This operation may not be supported for all
    project types, and may only be executed by a superuser."""
    if guts.user.is_superuser:
        if not get:
            task = get_object_or_404(Task, pk=task_id)
            project_type = get_project_type(task.project)
            task = project_type.cast(task)
            task.handle_unmerge()
            wip = WorkInProgress(user=guts.user, task=task)
            wip.full_clean()
            wip.save()
        return ViewResponse(task_view, task_id)
    else:
        return ForbiddenResponse("Only superusers may perform this operation.")
예제 #3
0
def next_task(guts):
    """Get the next task for a user, and redirect.
    
    It is possible this belongs with the task views.

    # TODO: Testing
    
    The input request should have a logged in user. The result
    should be:
     * If the user has nothing to do, redirect to the home page.
     * If the user has a pending review, redirect to that review's page.
     * If the user has a task in an auto-review project to look at,
       redirect to that page.
     * If the user either has a WorkInProgress or there is a task
       available for them to work on, a redirect to that task's page.
     * If a WorkInProgress exists, the .start_time property of the
       WIP should be updated to the current time.
     * If no WIP exists, one should be created with the next available
       task and the current logged in user.
    """
    review = Review.objects.filter(response__user=guts.user, complete=False)
    if review.count():
        return ViewResponse('main:next-review')

    auto_review_pending = AutoReview.objects.filter(user=guts.user,
                                                    start_time__isnull=False,
                                                    end_time__isnull=True)
    if auto_review_pending.exists():
        return ViewResponse('main:view-task', auto_review_pending[0].task.id)
    new_auto_reviews = AutoReview.objects.filter(
        user=guts.user,
        task__project__priority__gte=0,
        start_time__isnull=True,
        end_time__isnull=True,
    ).order_by("-task__project__priority")
    if new_auto_reviews.exists():
        auto_review = new_auto_reviews[0]
        auto_review.start_time = timezone.now()
        auto_review.full_clean()
        auto_review.save()
        return ViewResponse('main:view-task', auto_review.task.id)

    wip = None
    wips = WorkInProgress.objects.filter(user=guts.user)
    if wips.count():
        wip = wips[0]
        wip.start_time = timezone.now()
        wip.full_clean()
        wip.save()
    else:
        task = Task.objects.next_for(guts.user)
        if task:
            wip = WorkInProgress(user=guts.user, task=task)
            wip.full_clean()
            wip.save()
    if wip:
        return ViewResponse('main:view-task', wip.task.id)
    else:
        return ViewResponse('main:home')
예제 #4
0
def unmerge(get, guts, task_id):
    """Given a task that has already been merged, undo the merge, give
    the user a WIP for re-merging it, and redirect to the page for
    handling that WIP.  This operation may not be supported for all
    project types, and may only be executed by a superuser."""
    if guts.user.is_superuser:
        if not get:
            task = get_object_or_404(Task, pk=task_id)
            project_type = get_project_type(task.project)
            task = project_type.cast(task)
            task.handle_unmerge()
            wip = WorkInProgress(user=guts.user, task=task)
            wip.full_clean()
            wip.save()
        return ViewResponse('main:view-task', task_id)
    else:
        return ForbiddenResponse("Only superusers may perform this operation.")