예제 #1
0
def setPanier(request, id):

    try:
        if request.session['idcl'] != None:
            idcl = request.session['idcl']
            cl = Client.objects.get(id=idcl)
            lvr = Livre.objects.get(id=id)

            cart, created = Panier.objects.get_or_create(pclient=cl)
            livres = [livre for livre in cart.plivre.all()]

            if not lvr in livres:
                livres.append(lvr)
                cart.plivre.set(livres)
                cart.save()
            '''if not lvr.id in cart:
                panie = Panier(pclient=cl, plivre=lvr)
                panie.save()'''
            '''if not lvr.id in cart:
                cart.add(lvr.id)'''

            return listLivre(request)
            '''cart = Panier.objects.filter(pclient=cl).values_list('plivre')
            if not lvr in cart:
                cart.append(lvr)
            #form = PanieForm(request.POST, pclient = cl, plivre = lvr)
            if form.is_valid():
                form.save()'''

    except KeyError:
        return render(request, 'signin.html')
예제 #2
0
def rmLivre(request, id):

    try:
        idcl = request.session['idcl']
        cl = Client.objects.get(id=idcl)
        lvr = Livre.objects.get(id=id)

        panier = get_object_or_404(Panier, pclient=cl)
        panier.plivre.remove(lvr)
        return getPanier(request)
    except:
        return listLivre(request)
예제 #3
0
def Signin(request):
    em = request.POST.get('email')
    if em != None:
        email = request.POST.get('email')
        password = request.POST.get('password')
        try:
            cl = Client.objects.get(email=email, password=password)
            request.session["idcl"] = cl.id
            request.session["fullname"] = cl.nom + " " + cl.prenom
            return listLivre(request)
        except Client.DoesNotExist:
            #messages.add_message(request, messages.ERROR, 'Hello world.')
            messages.error(request, 'Mot de passe ou email incorrect.')
            return render(request, 'signin.html')
    return render(request, 'signin.html')
예제 #4
0
def setCommande(request):

    if request.session['idcl'] != None:
        idcl = request.session['idcl']
        cl = Client.objects.get(id=idcl)
        panier, created = Panier.objects.get_or_create(pclient=cl)
        cmd, created = Commande.objects.get_or_create(cmdclient=cl)
        for livre in panier.plivre.all():
            if not livre in cmd.cmdlivre.all():
                cmd.cmdlivre.add(livre)
        '''livres = [livre for livre in panier.plivre.all()]
        cmd, created = Commande.objects.get_or_create(cmdclient=cl)
        cmd.cmdlivre.set(livres)'''
        '''for ligne in panier:
            cmd.cmdlivre.add(ligne.plivre)'''
        cmd.save()
        panier.delete()

        return listLivre(request)
예제 #5
0
def Logout(request):
    #for sesskey in request.session.keys():
    #del request.session[sesskey]
    request.session.clear()
    return listLivre(request)