示例#1
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)
示例#2
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])