Exemple #1
0
def editProduct(product_id):
           
    try:
        form = NewProductForm(request.form)
        product = (session.query(Product).
                        filter(Product.id==product_id).one())
        sections = session.query(BodySection).all()
    except:
        flash("That particular product is not registered ")
        return redirect(url_for('newProduct'))    
    
    if product.user_id == login_session['user_id']:
        if request.method == 'GET':
                return render_template('editProduct.html', 
                                product=product, sections= sections,
                                image=login_session['picture'])
           
        if request.method == 'POST' and form.validate():
            print '/n/n/n/ post/n/n'
            if request.form['btn'] == 'Save':
                form.populate_obj(product)           
                if request.files['picture']:
                    file = request.files['picture']
                    filename = secure_filename(file.filename)
                    product.picture_name = IMAGES_FOLDER + filename
                    file.save(app.config['UPLOAD_FOLDER'] + filename)
                    session.add(product)
                    session.commit()
                return redirect(url_for('product', product_id=product_id)) 
                
            elif request.form['btn'] == 'Cancel':
                return redirect(url_for('product', product_id=product_id))       
    else:
        flash("Only the creator of every product can edit it")
        return redirect(url_for('product', product_id=product_id ))
Exemple #2
0
def createUser(login_session):

    try:
        user = User(login_session['username'], login_session['email'],
                    login_session['picture'], True)

        session.add(user)
        session.commit()
        user = session.query(User).filter_by(
            email=login_session['email']).one()
        return user.id

    except:
        return None
Exemple #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'))
Exemple #4
0
def createUser(login_session):

    try:
        user = User(login_session['username'], 
                    login_session['email'], 
                    login_session['picture'],
                    True)
                    
        session.add(user)
        session.commit()
        user = session.query(User).filter_by(email=login_session['email']).one()
        return user.id   
    
    except:
        return None
Exemple #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'))
Exemple #6
0
def editProduct(product_id):

    try:
        form = NewProductForm(request.form)
        product = (session.query(Product).filter(
            Product.id == product_id).one())
        sections = session.query(BodySection).all()
    except:
        flash("That particular product is not registered ")
        return redirect(url_for('newProduct'))

    if product.user_id == login_session['user_id']:
        if request.method == 'GET':
            return render_template('editProduct.html',
                                   product=product,
                                   sections=sections,
                                   image=login_session['picture'])

        if request.method == 'POST' and form.validate():
            print '/n/n/n/ post/n/n'
            if request.form['btn'] == 'Save':
                form.populate_obj(product)
                if request.files['picture']:
                    file = request.files['picture']
                    filename = secure_filename(file.filename)
                    product.picture_name = IMAGES_FOLDER + filename
                    file.save(app.config['UPLOAD_FOLDER'] + filename)
                    session.add(product)
                    session.commit()
                return redirect(url_for('product', product_id=product_id))

            elif request.form['btn'] == 'Cancel':
                return redirect(url_for('product', product_id=product_id))
    else:
        flash("Only the creator of every product can edit it")
        return redirect(url_for('product', product_id=product_id))
Exemple #7
0
def newProduct(section_id):

    sections = session.query(BodySection).all()

    # Check if the request comes from a particular section
    if section_id:
        preselected_section = (session.query(BodySection).filter(
            BodySection.id == section_id).one())
    else:
        preselected_section = section_id

    form = NewProductForm(request.form)
    product = Product()
    if request.method == 'GET':
        return render_template('newProduct.html',
                               sections=sections,
                               ps_section=preselected_section,
                               image=login_session['picture'])

    if request.method == 'POST' and form.validate():
        form.populate_obj(product)
        file = request.files['picture']
        filename = secure_filename(file.filename)
        product.user_id = login_session['user_id']
        product.picture_name = app.config['IMAGES_FOLDER'] + filename
        if allowed_file(filename):
            file.save(app.config['UPLOAD_FOLDER'] + filename)
            session.add(product)
            session.commit()
            flash("New product added! ")
        else:
            flash("Error while saving the photo file!")
        if section_id:
            return redirect(url_for('section', section_id=section_id))

    return redirect(url_for('viewProducts'))
Exemple #8
0
def newProduct(section_id):
    
  
    sections = session.query(BodySection).all()
    
    # Check if the request comes from a particular section 
    if section_id:
        preselected_section = (session.query(BodySection).
                                    filter(BodySection.id==section_id).one())
    else:
        preselected_section = section_id
        
    form = NewProductForm(request.form)
    product = Product()
    if request.method == 'GET':
        return render_template('newProduct.html', sections=sections,
                                ps_section=preselected_section,
                                image=login_session['picture'])
        
    if request.method == 'POST' and form.validate():       
        form.populate_obj(product)
        file = request.files['picture']
        filename = secure_filename(file.filename)
        product.user_id = login_session['user_id']
        product.picture_name = app.config['IMAGES_FOLDER'] + filename 
        if allowed_file(filename):
            file.save(app.config['UPLOAD_FOLDER'] + filename)
            session.add(product)
            session.commit()
            flash("New product added! ")
        else:
            flash("Error while saving the photo file!")
        if section_id:
            return redirect(url_for('section', section_id=section_id))
            
    return redirect(url_for('viewProducts'))