Пример #1
0
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))
Пример #2
0
def delete_para(para_id):
    """Page: delete product parameter"""
    check_admin()
    para = ProductParamter.query.get_or_404(para_id)
    db.session.delete(para)
    db.session.commit()
    return redirect(url_for('product', product_id=para.product_id))
Пример #3
0
def delete_stype(stype_id):
    """Proc: delete sub product type"""
    check_admin()
    stype = Stype.query.get_or_404(stype_id)
    db.session.delete(stype)
    db.session.commit()
    return redirect(url_for('home'))
Пример #4
0
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))
Пример #5
0
def delete_para(para_id):
    """Page: delete product parameter"""
    check_admin()
    para = ProductParamter.query.get_or_404(para_id)
    db.session.delete(para)
    db.session.commit()
    return redirect(url_for('product', product_id=para.product_id))
Пример #6
0
def delete_stype(stype_id):
    """Proc: delete sub product type"""
    check_admin()
    stype = Stype.query.get_or_404(stype_id)
    db.session.delete(stype)
    db.session.commit()
    return redirect(url_for('home'))
Пример #7
0
def add_para(product_id):
    """Proc: manage product parameters"""
    check_admin()
    para = ProductParamter(product_id=product_id, key=request.form['key'], value=request.form['value'])
    db.session.add(para)
    db.session.commit()
    return redirect(url_for('product', product_id=product_id))
Пример #8
0
def add_para(product_id):
    """Proc: manage product parameters"""
    check_admin()
    para = ProductParamter(product_id=product_id,
                           key=request.form['key'],
                           value=request.form['value'])
    db.session.add(para)
    db.session.commit()
    return redirect(url_for('product', product_id=product_id))
Пример #9
0
def add_stype():
    """Page: add sub product type"""
    check_admin()
    if request.method == 'GET':
        mtypes = Mtype.query.order_by(Mtype.show_order).all()
        return render_template('type/add_stype.html', mtypes=mtypes)
    elif request.method == 'POST':
        stype = Stype(mtype_id=request.form['mtype_id'], name=request.form['name'], show_order=request.form['show_order'])
        db.session.add(stype)
        db.session.commit()
        return redirect(url_for('stype', stype_id=stype.id))
Пример #10
0
def delete_mtype(mtype_id):
    """Proc: delete main product type"""
    check_admin()

    # Try to delete img file
    # TODO

    mtype = Mtype.query.get_or_404(mtype_id)
    db.session.delete(mtype)
    db.session.commit()
    return redirect(url_for('home'))
Пример #11
0
def delete_mtype(mtype_id):
    """Proc: delete main product type"""
    check_admin()

    # Try to delete img file
    # TODO

    mtype = Mtype.query.get_or_404(mtype_id)
    db.session.delete(mtype)
    db.session.commit()
    return redirect(url_for('home'))
Пример #12
0
def delete_carousel(c_id):
    """Proc - delete carousel"""
    check_admin()

    # Try to delete image file
    # TODO

    carousel = Carousel.query.get_or_404(c_id)
    db.session.delete(carousel)
    db.session.commit()
    return redirect(url_for('manage_carousel'))
Пример #13
0
def delete_carousel(c_id):
    """Proc - delete carousel"""
    check_admin()

    # Try to delete image file
    # TODO

    carousel = Carousel.query.get_or_404(c_id)
    db.session.delete(carousel)
    db.session.commit()
    return redirect(url_for('manage_carousel'))
Пример #14
0
def edit_para(para_id):
    """Page: edit product parameter"""
    check_admin()
    para = ProductParamter.query.get_or_404(para_id)
    if request.method == 'GET':
        return render_template('product/edit_para.html', para=para)
    else:
        para.key = request.form['key']
        para.value = request.form['value']
        db.session.add(para)
        db.session.commit()
        return redirect(url_for('product', product_id=para.product_id))
Пример #15
0
def delete_product(product_id):
    """Page: delete product"""
    check_admin()

    # Delete image file
    # TODO

    # Delete product
    product = Product.query.get_or_404(product_id)
    db.session.delete(product)
    db.session.commit()
    return redirect(url_for('home'))
Пример #16
0
def delete_product(product_id):
    """Page: delete product"""
    check_admin()

    # Delete image file
    # TODO

    # Delete product
    product = Product.query.get_or_404(product_id)
    db.session.delete(product)
    db.session.commit()
    return redirect(url_for('home'))
Пример #17
0
def edit_para(para_id):
    """Page: edit product parameter"""
    check_admin()
    para = ProductParamter.query.get_or_404(para_id)
    if request.method == 'GET':
        return render_template('product/edit_para.html', para=para)
    else:
        para.key = request.form['key']
        para.value = request.form['value']
        db.session.add(para)
        db.session.commit()
        return redirect(url_for('product', product_id=para.product_id))
Пример #18
0
def add_stype():
    """Page: add sub product type"""
    check_admin()
    if request.method == 'GET':
        mtypes = Mtype.query.order_by(Mtype.show_order).all()
        return render_template('type/add_stype.html', mtypes=mtypes)
    elif request.method == 'POST':
        stype = Stype(mtype_id=request.form['mtype_id'],
                      name=request.form['name'],
                      show_order=request.form['show_order'])
        db.session.add(stype)
        db.session.commit()
        return redirect(url_for('stype', stype_id=stype.id))
Пример #19
0
def edit_stype(stype_id):
    """Page: edit sub product type"""
    check_admin()
    st = Stype.query.get_or_404(stype_id)
    if request.method == 'GET':
        mtypes = Mtype.query.order_by(Mtype.show_order).all()
        return render_template('type/edit_stype.html', st=st, mtypes=mtypes)
    elif request.method == 'POST':
        st.mtype_id = request.form['mtype_id']
        st.name = request.form['name']
        st.show_order = request.form['show_order']
        db.session.add(st)
        db.session.commit()
        return redirect(url_for('stype', stype_id=stype_id))
Пример #20
0
def edit_stype(stype_id):
    """Page: edit sub product type"""
    check_admin()
    st = Stype.query.get_or_404(stype_id)
    if request.method == 'GET':
        mtypes = Mtype.query.order_by(Mtype.show_order).all()
        return render_template('type/edit_stype.html', st=st, mtypes=mtypes)
    elif request.method == 'POST':
        st.mtype_id = request.form['mtype_id']
        st.name = request.form['name']
        st.show_order = request.form['show_order']
        db.session.add(st)
        db.session.commit()
        return redirect(url_for('stype', stype_id=stype_id))
Пример #21
0
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'))
Пример #22
0
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))
Пример #23
0
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'))
Пример #24
0
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'))
Пример #25
0
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'))
Пример #26
0
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'))
Пример #27
0
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))
Пример #28
0
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'))
Пример #29
0
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'))
Пример #30
0
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'))