예제 #1
0
def commandeApproximite(request):
    idCommande = request.POST["idCommande"]
    token = request.POST["token"]
    is_error = 0
    try:
        commande = Commande.objects.filter(idCommande=idCommande)[0]
        terminal = Terminal.objects.filter(token=token)[0]
        notification = Notification()
        notification.titre = "info"
        notification.Notitype = 10
        notification.client = commande.client
        notification.content = "le livreur à proximité de vous"
        notification.url = "https://www.teranga-food.com/mes-commandes"
        notification.save()
    except:
        is_error = 1
    if is_error == 0:
        return HttpResponse("good")
    else:
        return HttpResponse("cet commande n'exite pas", status=403)
예제 #2
0
def changeState(request):
    idCommande = request.POST["idCommande"]
    token = request.POST["token"]
    state = request.POST["state"]
    user_request = request.user
    is_error = 0
    try:
        commande = Commande.objects.filter(idCommande=idCommande)[0]
        terminal = Terminal.objects.filter(token=token)[0]
        try:
            terminalClient = Terminal.objects.filter(
                utilisateur=commande.client.personne)[0]
        except:
            v = 1
        if int(state) == 2 or int(state) == 3:
            commande.state = state
            notification = Notification()
            notification.titre = "info"
            notification.client = commande.client
            if int(state) == 2:
                notification.content = "votre commande est en cours préparation"
                commande.datePreparation = datetime.now()
            if int(state) == 3:
                notification.content = "votre commande est en cours livraison"
                commande.dateLivraicon = datetime.now()
            notification.url = "https://www.teranga-food.com/mes-commandes"
            notification.save()
        else:
            commande.state = state
            if int(state) == 4:
                commande.estLivrer = 1
            if int(state) == 5:
                commande.estLivrer = 2
        commande.save()
    except:
        is_error = 1
    if is_error == 0:
        return HttpResponse("good")
    else:
        return HttpResponse("cet commande n'exite pas", status=403)
예제 #3
0
파일: views.py 프로젝트: youriyav/teranga
def affecterCommande(request):
    if request.user.is_authenticated():
        if request.user.is_active:
            if request.user.is_staff:
                if request.POST:
                    is_error = 0
                    listeLivreur = Livreur.objects.all()
                    idCommande = request.POST["idCommande"]
                    idLivreur = request.POST["livreur"]
                    if int(idLivreur) == 0:
                        is_error = 1
                        error_livreur = u"Veuillez sélectionner un livreur"
                        commande = Commande.objects.filter(
                            idCommande=idCommande)[0]

                        now = datetime.now()
                        now_minus_10 = now - timedelta(minutes=5)

                        listeLivreur = Livreur.objects.filter(
                            personne__terminal__lastUpdate__gte=now_minus_10)
                        messages.error(request,
                                       u"Veuillez sélectionner un livreur")
                        return redirect(
                            detailCommande, idCommande
                        )  #render(request, 'detail_commande.html', locals())
                    else:
                        commande = Commande.objects.filter(
                            idCommande=idCommande)[0]
                        livreur = Livreur.objects.filter(
                            idLivreur=idLivreur)[0]
                        commande.livreur = livreur
                        commande.state = 1
                        commande.dateValidation = datetime.now()
                        commande.manager = request.user.utilisateur
                        commande.save()
                        notification = Notification()
                        notification.titre = "info"
                        notification.client = commande.client
                        notification.content = "votre commande <br>vient être validée"
                        notification.url = "http://192.168.1.17:8000/mes-commandes"
                        notification.save()
                        lignecommandes = commande.lignecommande_set.all()
                        data = '['
                        mstop = 0
                        for ligne in lignecommandes:
                            mstop = mstop + 1
                            tmp = '{'
                            tmp += '"idProduit":"' + str(
                                ligne.produit.idProduit) + '",'
                            tmp += '"produit":"' + ligne.produit.nomProduit + '",'
                            tmp += '"prix":"' + str(
                                ligne.produit.prixProduit) + '",'
                            tmp += '"quantite":"' + str(ligne.quantite) + '"'
                            tmp += '}'
                            data += tmp
                            if mstop != lignecommandes.count():
                                data = data + ","
                        data += ']'
                        data_message = {
                            "idCommande":
                            str(commande.idCommande),
                            "longitude":
                            str(commande.longitude),
                            "latitude":
                            str(commande.latitude),
                            "montant":
                            str(commande.get_montant()),
                            "entite":
                            commande.entite.nomEntite,
                            "numero":
                            commande.numero,
                            "heure":
                            str(commande.dateCreation),
                            "client":
                            commande.client.personne.nomPersonne + " " +
                            commande.client.personne.prenomPersonne,
                            "numero_client":
                            str(commande.client.personne.numeroPersonne),
                            "produits":
                            '{"liste":' + data + '}'
                        }
                        #terminal=livreur.personne.terminal_set[0]
                        token = livreur.personne.terminal.token

                        push_service = FCMNotification(
                            api_key=
                            "AAAA9bOoHa8:APA91bHrbWMoCSvFYHD9_ORd8P4lv-D0RaPf3cWaP_yRBJ_JeyCF3tSVRJfrr0bzLSzPAkmaU2zodtF7OjysaOnkckRalzUFvox_ZumkcdLtoOG414BNhIJyuibxXtXHzIXR_-EyU3Aj"
                        )
                        result = push_service.notify_single_device(
                            registration_id=token,
                            data_message=data_message,
                            time_to_live=300000)

                        return redirect(homeUtilisateur)