Example #1
0
def choose_next_task():
    """ Calculate the next task to work on.

        Starting at the top of the tree, we choose the top-level task to work
        on, based on the default strategy stored in our preferences. If the
        selected task has children, we then repeat the process for the child
        task, using the selected task's strategy, continuing until we reach a
        task with no children, which is the task to work on next.

        Upon completion, we return the Task object to work on next, or None if
        there are no task objects that we can work on.
    """
    parent   = None
    strategy = preferences.get_int("TOP_LEVEL_STRATEGY",
                                   Task.STRATEGY_PROPORTIONAL)

    while True:
        task = _calc_next_task_for_parent(parent, strategy)
        if task == None:
            return None

        if task.children.filter(status=Task.STATUS_ACTIVE).exists():
            # This task has at least one active child -> choose the task from
            # among this task's children.
            parent   = task
            strategy = task.strategy
            continue
        else:
            # We've reached a leaf node task -> this is the one to work on.
            return task
Example #2
0
def prefs(request):
    """ Respond to the "/prefs" URL.

        This is the main view for the "prefs" mode.
    """
    if request.method == "GET":
        # We're displaying the form for the first time.  Set up our defaults.

        err_msg  = None
        strategy = preferences.get_int("TOP_LEVEL_STRATEGY")

    elif request.method == "POST":
        # Get the entered form values.

        if request.POST.get("cancel") != None:
            # The user cancelled -> return to the main page.
            return HttpResponseRedirect("/")

        err_msg = None # initially.

        strategy = request.POST.get("strategy")
        if strategy == None:
            err_msg = "You must select a strategy."

        if err_msg == None:
            preferences.set_int("TOP_LEVEL_STRATEGY", strategy)
        return HttpResponseRedirect("/")

    # If we get here, display the preferences form.

    return render(request, "prefs.html",
                  {'strategy_choices' : Task.STRATEGY_CHOICES,
                   'err_msg'          : err_msg,
                   'strategy'         : strategy})