def edit_product(product_id): """Page: edit product""" check_admin() p = Product.query.get_or_404(product_id) if request.method == 'GET': mtypes = build_mtype_json() return render_template('product/edit_product.html', p=p, mtypes=mtypes) else: # Delete old image # TODO # Save new image image = request.files['image'] if image.filename: filename = images.save(image, name='p%s.' % str(p.id)) p.image = filename # Update product p.stype_id = request.form['stype_id'] p.name = request.form['name'] p.desc = request.form['desc'] p.show_order = request.form['show_order'] db.session.add(p) db.session.commit() return redirect(url_for('product', product_id=product_id))
def add_mtype(): """Page: add main product type""" check_admin() if request.method == 'GET': return render_template('type/add_mtype.html') elif request.method == 'POST': # Save image max_id = db.session.query(db.func.max(Mtype.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='m%s.' % str(max_id + 1)) # Add mtype mtype = Mtype(name=request.form['name'], image=filename, show_order=request.form['order']) db.session.add(mtype) db.session.commit() return redirect(url_for('home'))
def manage_carousel(): """Page - manage carousel""" check_admin() if request.method == 'GET': max_id = db.session.query(db.func.max(Carousel.id).label('max_id')).one().max_id carousels = Carousel.query.all() return render_template('carousel/manage.html', carousels=carousels, max_id=max_id) else: # Save image max_id = db.session.query(db.func.max(Carousel.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='c%s.' % str((max_id or 0) + 1)) # add carousel carousel = Carousel(image=filename) db.session.add(carousel) db.session.commit() return redirect(url_for('manage_carousel'))
def add_product(): """Page: add product""" check_admin() if request.method == 'GET': mtypes = build_mtype_json() return render_template('product/add_product.html', mtypes=mtypes) else: # Save image max_id = db.session.query(db.func.max(Product.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='p%s.' % str(max_id + 1)) # Add product product = Product(stype_id=request.form['stype_id'], name=request.form['name'], desc=request.form['desc'], image=filename, show_order=request.form['show_order']) db.session.add(product) db.session.commit() return redirect(url_for('product', product_id=product.id))
def edit_carousel(c_id): """Page - edit carousel""" check_admin() carousel = Carousel.query.get_or_404(c_id) if request.method == 'GET': return render_template('carousel/edit.html', carousel=carousel) else: # Delete old images # TODO - because upload sets has no delele method # Save new image if uploaded image = request.files['image'] if image.filename: filename = images.save(image, name='c%s.' % str(carousel.id)) carousel.image = filename db.session.add(carousel) db.session.commit() return redirect(url_for('manage_carousel'))
def add_mtype(): """Page: add main product type""" check_admin() if request.method == 'GET': return render_template('type/add_mtype.html') elif request.method == 'POST': # Save image max_id = db.session.query(db.func.max( Mtype.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='m%s.' % str(max_id + 1)) # Add mtype mtype = Mtype(name=request.form['name'], image=filename, show_order=request.form['order']) db.session.add(mtype) db.session.commit() return redirect(url_for('home'))
def edit_mtype(mtype_id): """Page: edit main product type""" check_admin() mt = Mtype.query.get_or_404(mtype_id) if request.method == 'GET': return render_template('type/edit_mtype.html', mt=mt) else: # Delete old image # TODO # Save new image image = request.files['image'] if image.filename: filename = images.save(image, name='m%s.' % str(mtype_id)) mt.image = filename # Update mtype mt.name = request.form['name'] mt.show_order = request.form['show_order'] db.session.add(mt) db.session.commit() return redirect(url_for('home'))
def manage_carousel(): """Page - manage carousel""" check_admin() if request.method == 'GET': max_id = db.session.query(db.func.max( Carousel.id).label('max_id')).one().max_id carousels = Carousel.query.all() return render_template('carousel/manage.html', carousels=carousels, max_id=max_id) else: # Save image max_id = db.session.query(db.func.max( Carousel.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='c%s.' % str(max_id + 1)) # add carousel carousel = Carousel(image=filename) db.session.add(carousel) db.session.commit() return redirect(url_for('manage_carousel'))
def add_product(): """Page: add product""" check_admin() if request.method == 'GET': mtypes = build_mtype_json() return render_template('product/add_product.html', mtypes=mtypes) else: # Save image max_id = db.session.query(db.func.max( Product.id).label('max_id')).one().max_id filename = images.save(request.files['image'], name='p%s.' % str(max_id + 1)) # Add product product = Product(stype_id=request.form['stype_id'], name=request.form['name'], desc=request.form['desc'], image=filename, show_order=request.form['show_order']) db.session.add(product) db.session.commit() return redirect(url_for('product', product_id=product.id))