Exemple #1
0
def edit_task(name,goal,strategy,task):
    P=models.Projects.query.all()
    project=models.Projects.query.filter_by(id=name).first() 
    pgoal=models.Goals.query.filter_by(id=goal).first() 
    pstrat=models.Strategies.query.filter_by(id=strategy).first() 
    ptask=models.Tasks.query.filter_by(id=task).first()
    delete_form=DeleteRow_form()
    form = task_form(obj=ptask)
    form.populate_obj(ptask)
    form.deadline.data = ptask.deadline.strftime("%m/%d/%Y")
    tform=task_form(request.values)
    if request.method == 'POST' and form.validate_on_submit():
        #if it changed from True to false, set complete date to None
        # import pdb;pdb.set_trace()
        if get_history(ptask, 'complete')[0]==[True] and get_history(ptask, 'complete')[2]==[False]:
            print 'changed from false to true'
            ptask.completeDate=datetime.datetime.utcnow()
        if get_history(ptask, 'complete')[0]==[False] and get_history(ptask, 'complete')[2]==[True]:
            print 'changed from true to false'
            ptask.completeDate=None
        else:
            if get_history(ptask, 'complete')[0]==[True] and get_history(ptask, 'complete')[2]==[None]:
                ptask.complete=True
                ptask.completeDate=None
        db.session.commit()
        return redirect(url_for('task_outline',name=name,goal=goal,strategy=strategy))
    if delete_form.validate_on_submit():
        db.session.delete(ptask)
        db.session.commit()
        return redirect(url_for('task_outline',name=name,goal=goal,strategy=strategy))
    return render_template('edit_task.html', tform=tform,form=form,project=project,pgoal=pgoal,pstrat=pstrat,ptask=ptask,delete_form=delete_form,P=P)
def edit_objective(name,goal):
    P=models.Projects.query.all()
    project=models.Projects.query.filter_by(id=name).first() 
    pgoal=models.Goals.query.filter_by(id=goal).first() 
    delete_form=DeleteRow_form()
    form = goal_form(obj=pgoal)
    form.populate_obj(pgoal)
    # tform=task_form(request.values)
    if request.method == 'POST' and form.validate_on_submit():
        db.session.commit()
        return redirect(url_for('project_outline',name=name))
    if delete_form.validate_on_submit():
        db.session.delete(pstrat)
        db.session.commit()
        return redirect(url_for('project_outline',name=name))
    return render_template('edit_objective.html',form=form,project=project,pgoal=pgoal,delete_form=delete_form,P=P)