示例#1
0
def panier_ajout():
    error = None
    if session['username'] is None:
        error= "Vous devez vous connecter pour ajouter un item au panier."
        return render_template('index.html', error=error)
    else:
        ajoutpanier = db.cursor()
        ajoutpanier.execute("Select * from panier where ISBN='%s'" % request.form['ISBN'])
        if ajoutpanier.fetchone() is None:
            itempanier = {'username': session['username'],'ISBN': request.form['ISBN'], 'Quantite': '1'}
            ajoutpanier.execute(
            "insert into panier(username, ISBN, Quantite) "
            "values('%(username)s','%(ISBN)s', '%(Quantite)s')" % itempanier)
            db.commit()
        else:
            itempanier = {'username': session['username'],'ISBN': request.form['ISBN']}
            ajoutpanier.execute("Select Quantite from livre where ISBN='%s'" %request.form['ISBN'])
            quantiteEnStock = ajoutpanier.fetchone()[0]
            ajoutpanier.execute("Select Quantite from panier where username='******' AND ISBN='%(ISBN)s'" % itempanier)
            quantiteEnPanier = ajoutpanier.fetchone()[0]

            if quantiteEnStock > quantiteEnPanier:
                ajoutpanier.execute("Update panier SET quantite=quantite+1 where username='******' AND ISBN='%(ISBN)s'" % itempanier )
                db.commit();
            else:
                error = "Votre panier contient tous les exemplaires en stock"


        return flask.redirect('/livres/panier')
示例#2
0
def panier_achat():
    error = None
    message = None
    soldeuser = db.cursor()
    soldeuser.execute("Select solde from user WHERE username='******'" %
                      session['username'])
    solde = soldeuser.fetchone()[0]
    prixpanier = 0
    p = db.cursor()
    p.execute("Select ISBN from panier where username='******'" %
              session['username'])
    listeLivres = p.fetchall()
    listePanier = []
    for i in range(0, len(listeLivres)):
        p.execute("Select prix from livre where ISBN='%s'" % listeLivres[i][0])
        prixpanier += p.fetchone()[0]
    if prixpanier > solde:
        error = "Solde insuffisant"

    else:
        message = "Achat effectuer! "
        prixuser = {'username': session['username'], 'prixpanier': prixpanier}
        achat = db.cursor()
        achat.execute(
            "Update user SET solde=(solde-%(prixpanier)s) where username='******'"
            % prixuser)
        delete = db.cursor()
        delete.execute("DELETE FROM panier WHERE username='******'" %
                       session['username'])
        db.commit()
    return panier(message=message, error=error)
示例#3
0
def panier_achat():
    error = None
    message = None
    soldeuser = db.cursor()
    soldeuser.execute("Select solde from user WHERE username='******'" % session['username'])
    solde = soldeuser.fetchone()[0]
    prixpanier = 0
    p = db.cursor()
    p.execute(
        "Select ISBN from panier where username='******'" % session['username'])
    listeLivres = p.fetchall();
    listePanier =[]
    for i in range(0, len(listeLivres)):
        p.execute("Select prix from livre where ISBN='%s'" % listeLivres[i][0])
        prixpanier += p.fetchone()[0]
    if prixpanier>solde:
        error = "Solde insuffisant"

    else:
        message = "Achat effectuer! "
        prixuser = {'username': session['username'],'prixpanier': prixpanier}
        achat = db.cursor()
        achat.execute("Update user SET solde=(solde-%(prixpanier)s) where username='******'" % prixuser )
        delete = db.cursor()
        delete.execute("DELETE FROM panier WHERE username='******'" % session['username'])
        db.commit()
    return panier(message=message, error=error)
示例#4
0
def membres_delete():
    username = request.values['username']

    delete = db.cursor()
    delete.execute("DELETE FROM user WHERE username='******'" % username)
    db.commit()

    return flask.redirect('/membres')
示例#5
0
def livres_delete():
    ISBN = request.values['ISBN']

    delete = db.cursor()
    delete.execute("DELETE FROM livre WHERE ISBN='%s'" % ISBN)
    db.commit()

    return flask.redirect('/livres')
示例#6
0
def membres_delete():
    username = request.values['username']

    delete = db.cursor()
    delete.execute("DELETE FROM user WHERE username='******'" % username)
    db.commit()

    return flask.redirect('/membres')
示例#7
0
def livres_delete():
    ISBN = request.values['ISBN']

    delete = db.cursor()
    delete.execute("DELETE FROM livre WHERE ISBN='%s'" % ISBN)
    db.commit()

    return flask.redirect('/livres')
示例#8
0
def livre_ajout():
    ajout = db.cursor()
    ajout.execute(
        "insert into livre(titre, auteur, nombrePage, prix, categorie, quantite, datePublication) "
        "values('%(titre)s','%(auteur)s','%(nombrePage)s',"
        "'%(prix)s','%(categorie)s','%(quantite)s','%(datePublication)s')" %
        request.values)
    db.commit()
    return flask.redirect('/livres')
示例#9
0
def livre_ajout():
    ajout = db.cursor()
    ajout.execute(
        "insert into livre(titre, auteur, nombrePage, prix, categorie, quantite, datePublication) "
        "values('%(titre)s','%(auteur)s','%(nombrePage)s',"
        "'%(prix)s','%(categorie)s','%(quantite)s','%(datePublication)s')"
        % request.values
    )
    db.commit()
    return flask.redirect('/livres')
示例#10
0
def register_post():
    registration = db.cursor()
    if 'permission' in session.keys() and session['permission'] == 'admin':
         registration.execute(
        "insert into user(username, password, nom, prenom, courriel, codePostal, adresse, permission, solde) "
        "values('%(username)s','%(password)s','%(nom)s','%(prenom)s','%(courriel)s','%(codePostal)s','%(adresse)s',%(permission)s, 0)"
        % request.values)
    else:
         registration.execute(
             "insert into user(username, password, nom, prenom, courriel, codePostal, adresse, permission, solde)"+
             "values('%(username)s','%(password)s','%(nom)s','%(prenom)s','%(courriel)s','%(codePostal)s','%(adresse)s',2, 0) " % request.values)
         db.commit()

    return render_template('loginsuccess.html')
示例#11
0
def register_post():
    registration = db.cursor()
    if 'permission' in session.keys() and session['permission'] == 'admin':
        registration.execute(
            "insert into user(username, password, nom, prenom, courriel, codePostal, adresse, permission, solde) "
            "values('%(username)s','%(password)s','%(nom)s','%(prenom)s','%(courriel)s','%(codePostal)s','%(adresse)s',%(permission)s, 0)"
            % request.values)
    else:
        registration.execute(
            "insert into user(username, password, nom, prenom, courriel, codePostal, adresse, permission, solde)"
            +
            "values('%(username)s','%(password)s','%(nom)s','%(prenom)s','%(courriel)s','%(codePostal)s','%(adresse)s',2, 0) "
            % request.values)
        db.commit()

    return render_template('loginsuccess.html')
示例#12
0
def panier(message=None, error=None):
    panier = db.cursor()
    panier.execute(
        "Select ISBN from panier where username='******'" % session['username'])
    listeLivres = panier.fetchall();
    listePanier =[]
    prixpanier = 0

    for i in range(0, len(listeLivres)):
        panier.execute("Select prix from livre where ISBN='%s'" % listeLivres[i][0])
        prixpanier += panier.fetchone()[0]

    for i in range(0, len(listeLivres)):
        panier.execute("Select * from livre where ISBN='%s'" % listeLivres[i][0])
        listePanier.append(panier.fetchone())
    db.commit()
    return render_template('panier.html', listePanier=listePanier, message=message, error=error, prixpanier=prixpanier)
示例#13
0
def panier_ajout():
    error = None
    if session['username'] is None:
        error = "Vous devez vous connecter pour ajouter un item au panier."
        return render_template('index.html', error=error)
    else:
        ajoutpanier = db.cursor()
        ajoutpanier.execute("Select * from panier where ISBN='%s'" %
                            request.form['ISBN'])
        if ajoutpanier.fetchone() is None:
            itempanier = {
                'username': session['username'],
                'ISBN': request.form['ISBN'],
                'Quantite': '1'
            }
            ajoutpanier.execute(
                "insert into panier(username, ISBN, Quantite) "
                "values('%(username)s','%(ISBN)s', '%(Quantite)s')" %
                itempanier)
            db.commit()
        else:
            itempanier = {
                'username': session['username'],
                'ISBN': request.form['ISBN']
            }
            ajoutpanier.execute("Select Quantite from livre where ISBN='%s'" %
                                request.form['ISBN'])
            quantiteEnStock = ajoutpanier.fetchone()[0]
            ajoutpanier.execute(
                "Select Quantite from panier where username='******' AND ISBN='%(ISBN)s'"
                % itempanier)
            quantiteEnPanier = ajoutpanier.fetchone()[0]

            if quantiteEnStock > quantiteEnPanier:
                ajoutpanier.execute(
                    "Update panier SET quantite=quantite+1 where username='******' AND ISBN='%(ISBN)s'"
                    % itempanier)
                db.commit()
            else:
                error = "Votre panier contient tous les exemplaires en stock"

        return flask.redirect('/livres/panier')
示例#14
0
def panier(message=None, error=None):
    panier = db.cursor()
    panier.execute("Select ISBN from panier where username='******'" %
                   session['username'])
    listeLivres = panier.fetchall()
    listePanier = []
    prixpanier = 0

    for i in range(0, len(listeLivres)):
        panier.execute("Select prix from livre where ISBN='%s'" %
                       listeLivres[i][0])
        prixpanier += panier.fetchone()[0]

    for i in range(0, len(listeLivres)):
        panier.execute("Select * from livre where ISBN='%s'" %
                       listeLivres[i][0])
        listePanier.append(panier.fetchone())
    db.commit()
    return render_template('panier.html',
                           listePanier=listePanier,
                           message=message,
                           error=error,
                           prixpanier=prixpanier)
示例#15
0
def panier_delete():
    ISBN = request.values['ISBN']
    delete = db.cursor()
    delete.execute("DELETE FROM panier WHERE ISBN='%s'" % ISBN)
    db.commit()
    return flask.redirect('livres/panier')
示例#16
0
def panier_delete():
    ISBN = request.values['ISBN']
    delete = db.cursor()
    delete.execute("DELETE FROM panier WHERE ISBN='%s'" % ISBN)
    db.commit()
    return flask.redirect('livres/panier')