Beispiel #1
0
 def get(self):
     # Getting bids from the Db
     bidsModelObj = []
     modelBids = getTheUser(users.get_current_user()).bids
     #TODO add the new fields
     for modelBid in modelBids:
         bidModelObj = {}
         if modelBid.loan:
             bidModelObj['collateral_key'] = modelBid.loan.collateral_key
         else:
             bidModelObj['collateral_key'] = ""
         bidModelObj['participation'] = modelBid.participation
         bidModelObj['bidrate'] = modelBid.bidrate
         bidModelObj['status'] = modelBid.status
         bidModelObj['createdAt'] = modelBid.createdAt. \
                 strftime('%Y/%m/%d %H:%M:%S')
         bidModelObj['expiresAt'] = modelBid.expiresAt. \
                 strftime('%Y/%m/%d %H:%M:%S')
         bidsModelObj.append(bidModelObj)
     # Wrapping and sending
     itemsWrapper = {}
     itemsWrapper['items'] = bidsModelObj
     bidsToSendJson = json.dumps(itemsWrapper)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(bidsToSendJson)
Beispiel #2
0
 def post(self):
     bidsToAddJson = self.request.get(dojoAjaxKey)
     bidsToAddObj = json.loads(bidsToAddJson)
     # Adding the bid model objects
     dbUser = getTheUser(users.get_current_user())
     # Getting the bids for the current user
     userBids = dbUser.bids
     currentBids = {}
     #TODO if the user is an admin, then add all the bids
     #TODO if the user is a MO, the add the users for the MO
     i = 0 
     for bid in userBids:
         if bid.loan:
             currentBids[bid.loan.collateral_key] = bid
         else:
             currentBids[i] = bid
             i += 1
            
     currentBidsKeys = currentBids.keys()
     # Adding or updating the bids
     statusChoices = Bid.status.choices
     creationTime = datetime.now()
     expirationTime = creationTime + timedelta(hours=2)
     for key, value in bidsToAddObj.iteritems():
         # Getting user input values
         participation = float(value['participation'])
         bidrate = float(value['bidrate'])
         # Checking if there is a bid for a given collateral key
         if (key in currentBidsKeys):
             bid = currentBids[key]
             bid.participation = participation
             bid.bidrate = bidrate
             bid.put()
         else:
             loanQuery = loan.Loan.all(). \
                     filter('collateral_key =', key)
             loan = loanQuery.get()
             #TODO check why the status is random?
             #status = random.choice(statusChoices)
             status = 'Active'
             Bid(parent = dbUser,
                     user = dbUser,
                     loan = loan,
                     participation = participation,
                     bidrate = bidrate,
                     #TODO add the posibility of get a None value in
                     # bidrate, it is in the myscript.js
                     ordertype = 'Noncompetitive' if bidrate else
                             'Competitive',
                     status = status,
                     createdAt = creationTime,
                     expiresAt = expirationTime,
                     #Added to agree with the LiqSpop engine
                     #TODO is better to put it on the web
                     bidtype = 'Specified',
                     lorm = 'Loan',
                     ordertiming = 'Day Trade',
                     key_name = "%s %s" % (getCurrentUser(),
                         creationTime),
                 ).put()
Beispiel #3
0
 def delete(self):
     bidsToDeleteJson = self.request.get(dojoAjaxKey)
     bidsToDeleteObj = json.loads(bidsToDeleteJson)
     userBids = getTheUser(users.get_current_user()).bids
     currentBids = {}
     for bid in userBids:
         currentBids[bid.loan.collateral_key] = bid
     currentBidsKeys = currentBids.keys()
     # Deleting bid model
     for key in bidsToDeleteObj.iterkeys():
         if(key in currentBidsKeys):
             currentBids.pop(key).delete()
             currentBidsKeys = currentBids.keys()