Esempio n. 1
0
def strategy_outline(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() 
    S=pgoal.strategies.all()
    sform=strategy_form(request.values)
    delete_form=DeleteRow_form()
    q_sum = (db.session.query(
    Projects.id.label("project_id"),
    func.sum(case([(Tasks.complete == True, 1)], else_=0)).label("x"),
    func.sum(case([(and_(Tasks.deadline != None, Tasks.completeDate != None, Tasks.deadline > Tasks.completeDate), 1)], else_=0)).label("y"),
    func.count(Tasks.id).label("total"),
    Strategies.id.label("strategy_id"),
    Goals.id.label("goal_id"),
    ).join(Goals, Projects.goals).outerjoin(Strategies, Goals.strategies).outerjoin(Tasks, Strategies.tasks).group_by(Projects.id,Goals.id,Strategies.id).filter(Goals.id == goal) )
    if request.method == 'POST' and sform.submit.data:
        print sform.validate()
        if sform.validate() == False:
            flash('Failed Field validation.')
            flash_errors(sform)
            return redirect(url_for('strategy_outline',name=name,goal=goal))
        else:
            p=models.Strategies(strategy=sform.strategy.data,goa=pgoal)
            db.session.add(p)
            db.session.commit()
            return redirect(url_for('strategy_outline',name=name,goal=goal))
    if request.method == 'POST' and  delete_form.submitd.data:
        pstratrow = delete_form.row_id.data
        pstrat=models.Strategies.query.filter_by(id=pstratrow).first()
        db.session.delete(pstrat)
        db.session.commit()
        return redirect(url_for('strategy_outline',name=name,goal=goal))
    return render_template("index_for_strategy.html",project=project,S=S,sform=sform,pgoal=pgoal,P=P,zipit=zip(S,q_sum),delete_form=delete_form)
Esempio n. 2
0
def index():
    pform=project_form()
    tform=task_form()
    sform=strategy_form()
    gform=goal_form()
    P=models.Projects.query.all()
    if gform.validate_on_submit():
        u=models.Projects.query.get(1)
        p=models.Goals(goal=gform.goal.data,proj=u)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template("baseindex.html",pform=pform,gform=gform,tform=tform,sform=sform,P=P)
Esempio n. 3
0
def edit_strategy(name,goal,strategy):
    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() 
    delete_form=DeleteRow_form()
    form = strategy_form(obj=pstrat)
    form.populate_obj(pstrat)
    # tform=task_form(request.values)
    if request.method == 'POST' and form.validate_on_submit():
        db.session.commit()
        return redirect(url_for('strategy_outline',name=name,goal=goal))
    if delete_form.validate_on_submit():
        db.session.delete(pstrat)
        db.session.commit()
        return redirect(url_for('strategy_outline',name=name,goal=goal))
    return render_template('edit_strategy.html',form=form,project=project,pgoal=pgoal,pstrat=pstrat,delete_form=delete_form,P=P)