Example #1
0
def linkTasksToGoal(request, goal, profile):
    # Create the form and calculate the choices
    form = forms.GoalTaskLinkForm()
    taskList = Task.all().ancestor(profile).filter('Unit =', goal.Unit)
    form.TaskList.choices = [(t.key().id(), t.Name) for t in taskList]
    taskLinks = TaskLink.all().ancestor(goal)
    selectedTasks = set([link.Task.key().id() for link in taskLinks])

    if request.method == 'POST' and form.validate():
        for value, label, selected in form.TaskList.iter_choices():
            task = Task.get_by_id(value, profile)
            if value in selectedTasks:
                if not selected:
                    # Delete the task link
                    oldLink = TaskLink.all().ancestor(goal).filter('Task =', task).get()
                    if oldLink:
                        oldLink.delete()
            else:
                if selected:
                    # Create the task link
                    newLink = TaskLink(parent = goal, Task = task)
                    newLink.put()

        return redirect(url_for('goal', id = goal.key().id()))
    else:
        form.TaskList.data = selectedTasks

    return render_template("views/goal_link.html", goal = goal, form = form)
Example #2
0
def goal(id = None, action = None):
    profile = getCurrentProfile()
    if id is not None:
        # Make the action name lowercase
        action = SafeLower(action)
        thisGoal = Goal.get_by_id(int(id), profile)
        if action is None:
            links = TaskLink.all().ancestor(thisGoal)
            statsDict = LoadObjectStats(thisGoal, datetime.now())
            statsDict["goal"] = thisGoal
            statsDict["linkedTasks"] = [link.Task for link in links]
            statsDict["recentEntries"] = GoalEntry.all().ancestor(profile).fetch(5)
            return render_template('views/goal_view.html', **statsDict)
        elif action == "delete":
            return render_template('views/delete.html', goal = thisGoal, typeName = "goal")
        elif action == "edit":
            return render_template("views/goal_edit.html", goal = thisGoal, typeName = "goal")
        elif action == "tasks":
            return linkTasksToGoal(request, thisGoal, profile)
        elif action == "entires":
            return 
    elif action is not None:
        action = action.lower()
        if action == "create":
            return showCreateGoal(request, profile)

    else:
        if request.method == "GET":
            goalList = Goal.all().ancestor(profile)
            if not goalList:
                goalList = []
            return render_template("views/goal_list.html", goals = goalList)
        else:
            return showCreateGoal(request, profile)
Example #3
0
def showCreateGoalEntry(request, profile):
    form = forms.CreateGoalEntryForm()
    goalId = request.args["goal"]
    goal = Goal.get_by_id(int(goalId), profile)    
    # TODO: Error if goal ID not found
        
    if request.method == 'POST': #and form.validate():    
        taskKey = Key.from_path('Task', int(form.CompletedTask.data), parent=profile.key()) # = Task.get_by_id(int(form.CompletedTask.data), profile)
        CreateGoalEntry(
            profile, goal, taskKey, datetime.now(), form.Notes.data, 
            form.Quantity.data, form.Quality.data, form.Difficulty.data)
        return redirect(url_for('goal', id = goal.key().id()))

    taskLinks = TaskLink.all().ancestor(goal)
    tasks = [(link.Task.key().id(), link.Task.Name) for link in taskLinks] 
    form.CompletedTask.choices = tasks
    return render_template(
        "views/entry_edit.html", 
        typeName = "goal", actionName = "Create", 
        formMethod = "POST", formUrl = "/entries/?goal=%s" % goalId,
        form = form, unitLabel = TaskUnits.FieldLabels[goal.Unit])