Ejemplo n.º 1
0
def update(id):
    user = get_user(id)

    cats = all_category()

    if request.method == 'POST':
        username = request.form['username']
        admin = request.form['admin']
        error = None

        if not username:
            error = 'Login obligatoire.'

        if error is not None:
            flash(error)
        else:
            db = get_db()
            db.execute(
                'UPDATE user SET username = ?, isAdmin = ?'
                ' WHERE id = ?', (username, admin, id))
            db.commit()
            flash('Modification réussie !', 'success')
            return redirect(url_for('admin.all'))

    return render_template('administration/update-user.html',
                           cats=cats,
                           user=user)
Ejemplo n.º 2
0
def index():
    db = get_db()
    products = db.execute(
        'SELECT p.id, name, description, price, state, image, created, author_id, username'
        ' FROM product p JOIN user u ON p.author_id = u.id'
        ' ORDER BY created DESC'
    ).fetchall()

    cats = all_category()
    return render_template('product/home.html', products=products, cats=cats)
Ejemplo n.º 3
0
def product():
    db = get_db()
    products = db.execute('SELECT id, name, description, price, state'
                          ' FROM product'
                          ' ORDER BY id DESC').fetchall()

    cats = all_category()
    return render_template('administration/product.html',
                           products=products,
                           cats=cats)
Ejemplo n.º 4
0
def category():
    db = get_db()
    categories = db.execute('SELECT id, name'
                            ' FROM category'
                            ' ORDER BY id DESC').fetchall()

    cats = all_category()
    return render_template('administration/category.html',
                           categories=categories,
                           cats=cats)
Ejemplo n.º 5
0
def order():
    db = get_db()
    orders = db.execute('SELECT c.id, c.created, p.name, p.price, u.username'
                        ' FROM command c'
                        ' JOIN user u ON c.author_id = u.id'
                        ' JOIN product p ON c.product_id = p.id'
                        ' ORDER BY p.name ASC').fetchall()

    cats = all_category()
    return render_template('administration/command.html',
                           orders=orders,
                           cats=cats)
Ejemplo n.º 6
0
def search():
    query = "%" + request.args['q'] + "%"

    db = get_db()
    # Pour afficher la liste des catégories dans le menu
    cats = all_category()

    searches = db.execute(
        'SELECT *'
        ' FROM product p JOIN user u ON p.author_id = u.id'
        ' where name like ? OR description like ?', (query, query,)
    ).fetchall()

    # Si pas de résultats trouvés
    if not searches:
        flash('Pas de résultats trouvés pour ' + query.replace("%", ""), 'danger')
    return render_template('product/search.html', searches=searches, query=query.replace("%", ""), cats=cats)
Ejemplo n.º 7
0
def inventory():
    # On récupère l'ID de l'utilisateur en session
    user_id = session.get('user_id')
    db = get_db()
    products = db.execute(
        'SELECT p.id, name, description, price, state, image, created, author_id, username'
        ' FROM product p JOIN user u ON p.author_id = u.id'
        ' WHERE author_id = ?'
        ' ORDER BY created DESC'
        , (user_id,)
    ).fetchall()

    cats = all_category()

    if not products:
        flash('Vous n\'avez pas encore de livre en vente.', 'danger')

    return render_template('product/inventory.html', products=products, cats=cats)
Ejemplo n.º 8
0
def detail(id):
    db = get_db()

    comments = db.execute(
        'SELECT c.id, comment, username'
        ' FROM comment c JOIN user u ON c.author_id = u.id'
        ' JOIN product p ON c.product_id = ?'
        ' GROUP BY comment',
        (id,)
    ).fetchall()

    cats = all_category()

    details = db.execute(
        'SELECT p.id, name, description, price, state, image, created, author_id, username'
        ' FROM product p JOIN user u ON p.author_id = u.id'
        ' WHERE p.id = ?',
        (id,)
    ).fetchall()
    return render_template('product/detail.html', details=details, title=id, cats=cats, comments=comments)
Ejemplo n.º 9
0
def cart():
    user_id = session.get('user_id')
    db = get_db()
    panier = db.execute(
        'SELECT c.id, p.name, p.price, p.image'
        ' FROM cart c'
        ' JOIN user u ON c.author_id = u.id'
        ' JOIN product p ON c.product_id = p.id'
        ' WHERE c.author_id = ?'
        ' ORDER BY p.name ASC', (user_id, )).fetchall()

    totalPrice = 0
    # Pour calculer le prix total des articles dans le panier
    for row in panier:
        totalPrice += row[2]

    cats = all_category()
    return render_template('cart/index.html',
                           panier=panier,
                           totalPrice=totalPrice,
                           cats=cats)
Ejemplo n.º 10
0
def my_command():
    # On récupère l'ID session de l'utilisateur
    user_id = session.get('user_id')

    db = get_db()
    command = db.execute(
        'SELECT c.id, c.created, p.name, p.price, p.image'
        ' FROM command c'
        ' JOIN user u ON c.author_id = u.id'
        ' JOIN product p ON c.product_id = p.id'
        ' WHERE c.author_id = ?'
        ' ORDER BY p.name ASC', (user_id, )).fetchall()

    totalPrice = 0
    for row in command:
        totalPrice += row[3]

    cats = all_category()
    return render_template('order/index.html',
                           command=command,
                           totalPrice=totalPrice,
                           cats=cats)
Ejemplo n.º 11
0
def all():
    db = get_db()
    users = db.execute('SELECT *' ' FROM user' ' ORDER BY id DESC').fetchall()

    cats = all_category()
    return render_template('administration/index.html', users=users, cats=cats)