Example #1
0
def editBodySection(body_section_id):

    try:
        form = NewBodySectionForm(request.form)
        body_section = (session.query(BodySection).filter(
            BodySection.id == body_section_id).one())
    except:
        flash("That section is not defined, please define it to continue ")
        return redirect(url_for('newBodySection'))

    if body_section.user_id == login_session['user_id']:
        if request.method == 'GET':

            return render_template('editBodySection.html',
                                   bodysection=body_section,
                                   image=login_session['picture'])

        if request.method == 'POST' and form.validate():

            if request.form['btn'] == 'Update':
                form.populate_obj(body_section)
                session.commit()
                return redirect(url_for('index'))

            elif request.form['btn'] == 'Cancel':
                return redirect(url_for('section', section_id=body_section_id))
    else:
        flash("Only the creator of every section can edit it")
        return redirect(url_for('index'))
Example #2
0
def editBodySection(body_section_id):
    

    try:
        form = NewBodySectionForm(request.form)
        body_section = (session.query(BodySection).
                        filter(BodySection.id==body_section_id).one())
    except:
        flash("That section is not defined, please define it to continue ")
        return redirect(url_for('newBodySection'))                    
        
    if body_section.user_id == login_session['user_id']:
        if request.method == 'GET':

                return render_template('editBodySection.html',
                                        bodysection=body_section,
                                        image=login_session['picture'])
                
        if request.method == 'POST' and form.validate():
        
            if request.form['btn'] == 'Update':
                form.populate_obj(body_section)
                session.commit()
                return redirect(url_for('index')) 
                
            elif request.form['btn'] == 'Cancel':
                return redirect(url_for('section', section_id=body_section_id))        
    else:
        flash("Only the creator of every section can edit it")
        return redirect(url_for('index'))
Example #3
0
def newBodySection():

    form = NewBodySectionForm(request.form)
    if request.method == 'GET':
        return render_template('newBodySection.html',
                               image=login_session['picture'])

    if request.method == 'POST' and form.validate():
        body_section = BodySection()
        form.populate_obj(body_section)
        body_section.user_id = login_session['user_id']
        session.add(body_section)
        session.commit()
        flash("New section added! ")
        return redirect(url_for('index'))
Example #4
0
def deleteBodySection(body_section_id):

    try:
        body_section = (session.query(BodySection).filter(
            BodySection.id == body_section_id).one())
    except:
        flash("That particular section is not defined ")
        return redirect(url_for('newBodySection'))

    form = NewBodySectionForm(request.form)

    if body_section.user_id == login_session['user_id']:
        if request.method == 'GET':
            return render_template('deleteBodySection.html',
                                   bodysection=body_section,
                                   image=login_session['picture'])

        if request.method == 'POST':
            if request.form['btn'] == 'Delete':
                session.delete(body_section)
                session.commit()
                return redirect(url_for('index'))

            elif request.form['btn'] == 'Cancel':
                return redirect(url_for('section', section_id=body_section_id))
    else:
        flash("Only the creator of every section can edit it")
        return redirect(url_for('index'))
Example #5
0
def newBodySection():
    

        
    form = NewBodySectionForm(request.form)
    if request.method == 'GET':
        return render_template('newBodySection.html',
            image=login_session['picture'])
        
    if request.method == 'POST' and form.validate():
        body_section = BodySection()
        form.populate_obj(body_section)
        body_section.user_id = login_session['user_id'] 
        session.add(body_section)
        session.commit()
        flash("New section added! ")
        return redirect(url_for('index'))