Example #1
0
def find_driver(request):
    if request.method == "POST":
        try:
            init_from_lat = request.POST['from_lat']
            init_to_lat = request.POST['to_lat']
            init_from_long = request.POST['from_long']
            init_to_long = request.POST['to_long']
            user_id = request.POST['user_id']
            patient = AuthUserDemographic.get_user_by_id(user_id)
            distance = request.POST['distance']

            trans = Transaction(init_from_lat=init_from_lat,init_to_lat=init_to_lat,
                                init_from_long=init_from_long,init_to_long=init_to_long,
                                init_distance=distance,status="Waiting For Driver",
                                patient=patient)
            trans.save()
            closest_ambulance = AmbulanceLocation.get_closest_ambulance(lat_a=init_from_lat,long_a=init_from_long)

            if closest_ambulance:
                driver = AmbulanceDriverAssignment.get_ambulance_driver(closest_ambulance.ambulance).driver
                send_driver_request_notification(driver.user,trans)
                response = json.dumps({'status': 'ok', 'message': "Connecting to Ambulance","transaction_id":trans.id})
            else:
                response = json.dumps({'status': 'error', 'message': "No Ambulance"})
        except Exception as ex:
            response = json.dumps({'status': 'error', 'message': str(ex)})

    else:
        response = json.dumps({'status': 'error', 'message': "Method not allowed"})
    return HttpResponse(response, content_type='application/json')
Example #2
0
 def addTransaction(self, sender: str, receiver: str, amount: float,
                    fee: float, signature, pubkey,
                    message: str) -> Transaction:
     tx = Transaction(sender, receiver, amount, fee, signature, pubkey,
                      message)
     if tx.verify(pubkey):
         self.transactions.append(tx)
         return tx
     else:
         return None
    def verify_funds(tx: Transaction, chain: List[Block], open_transactions: List[Transaction]) -> bool:
        """ Checks whether sufficient funds for the transaction are present """
        if(Transaction.is_root_sender(tx.sender)):
            return True

        balance_sender = get_balance(tx.sender, chain, open_transactions)
        return balance_sender >= tx.amount
Example #4
0
def transactionHistory(user):
    """
    Display transaction history of current user
    """
    # get all transactions involving current user (recent to oldest)
    cursor = get_Cursor()
    cursor.execute(
        "SELECT * FROM transactionhistory WHERE user1accno = {0} OR user2accno = {0} ORDER BY time_of_transaction DESC".format(
            user.accno,
        )
    )
    transaction_hist = []
    for transaction in cursor.fetchall():
        transaction_hist.append(Transaction.fromTuple(transaction))

    if transaction_hist == []:
        print("No Transactions")
    else:
        # print transactions
        print(
            "{:<23} {:<32} {:<12}   {:<12}".format(
                "Date", "Description", "Withdrawal", "Deposit"
            )
        )
        for transaction in transaction_hist:
            transaction.print(user)
    def is_verified(transaction: Transaction) -> bool:
        if Transaction.is_root_sender(transaction.sender):
            return True

        verifier = Wallet.sign_transaction(transaction.sender)
        hashed_tx = Wallet.hash_transaction(
            transaction.sender, transaction.recipient, transaction.amount)

        return verifier.verify(hashed_tx, Wallet.to_binary(transaction.signature))
def ambulance_service_trips(request):

    trips = Transaction.get_trips_for_ambulance_service(request.company)
    context = {"trips":trips}
    return render(request, 'trips_completed.html',context)
Example #7
0
def get_tx_data(sender: str,
                recipient: str,
                signature: str,
                value: float = 1.0) -> Transaction:
    """ Transform sender, recipient, signature and value to Transaction Data """
    return Transaction(sender, recipient, value, signature)
Example #8
0
 def get_ambulance_orders_count(self):
     from core.models.transaction import Transaction
     return Transaction.get_order_count_for_ambulance_service(ambulance_service=self)
def trx_from_deserialized_trx(
        deserializedTrx: Transaction.__dict__) -> Transaction:
    """ Deserializes the JSON to the Transaction instance """
    return Transaction(**deserializedTrx)