Esempio n. 1
0
def pfGroup_pfIndex_addSymbol_vf(request,pfGroup,pfIndex): #form post
  pfIndexNo=int(pfIndex.replace("pf",""))
  if request.method == "POST":
    stockSymbol = request.POST["symbol"]
    if stockSymbol != "":
      stockSymbol1, marketType = stockUtil.parseInputSymbol(pfGroup, stockSymbol); #If stockSymbol=xxxx__xx, stockSymbol1=xxxxx
      stockName = stockUtil.getStockNameFromCSV(marketType ,stockSymbol1); #Assume input is stockId. if input not in CSV, stockName is set None 
      stockId = stockUtil.getStockIdFromCSV(marketType, stockSymbol1); #Assume input is stockName.  if input not in CSV, stockId is set None
      if stockId==None and stockName!=None:
        stockId=stockSymbol1;  #input is stockId
      if stockId!=None and stockName==None:
        stockName=stockSymbol1;  #input is stockName
      if stockId==None and stockName==None: 
        stockId=stockSymbol1;  #input can't found in csv Table
        stockName=stockId;  #input can't found in csv Table
      #print("stockId:" + stockUtil.cvNone(stockId))
      #print("stockName:" + stockUtil.cvNone(stockName))
      #print("marketType:" + stockUtil.cvNone(marketType))
      #print("stockSymbol1:" + stockUtil.cvNone(stockSymbol1))
      currentPortfolio = Portfolio.select().where(Portfolio.group  == pfGroup, Portfolio.index == pfIndexNo).dicts().first()
      if currentPortfolio != None:
        stockArray=stockUtil.evalTextArray(currentPortfolio["stock_array"]) #stock_array is converted form string type to array
        stockArray.append( {"stockId":stockId.upper() , "stockName":stockName, "marketType":marketType});
        q = Portfolio.update(stock_array=stockArray).where(Portfolio.id == currentPortfolio["id"])
        q.execute()
        #print(currentPortfolio)
      #if no portfolio in pfGroup, addSymbol do nothing. User must add symbol by create portfolio menju.
      else:
        from django.contrib import messages
        messages.add_message(request, messages.INFO, 'add a symbol must within portfolio.')
  return HttpResponseRedirect("/portfolio/" + pfGroup + "/"+ pfIndex)
Esempio n. 2
0
def pfGroup_pfIndex_updateWatchList_vf(request,pfGroup,pfIndex): #ajax POST.
  pfIndexNo=int(pfIndex.replace("pf",""))
  if request.method == "POST":
    body_unicode = request.body.decode('utf-8')
    updatePortfolio = json.loads(body_unicode)
    #print(updatePortfolio)
    #print(updatePortfolio["stock_array"])
    q=Portfolio.update(stock_array=updatePortfolio["stock_array"]).where(Portfolio.group == pfGroup, Portfolio.index == pfIndexNo)
    q.execute()
  return HttpResponseRedirect("/portfolio/" + pfGroup + "/"+ pfIndex)
Esempio n. 3
0
def pfGroup_updatePortfolioList_vf(request,pfGroup): #ajax post json
  if request.method == "POST":
    body_unicode = request.body.decode('utf-8')
    updateArray = json.loads(body_unicode)
    #print(updateArray)
    for item in updateArray:
      #print(item)
      q=Portfolio.update(index=item["index"],name=item["name"]).where(Portfolio.id == item["id"]) #Portfolio is a class, item is a dictionary.
      q.execute()
  return HttpResponseRedirect("/portfolio/" + pfGroup + "/pf0")
Esempio n. 4
0
def pfGroup_deletePortfolioList_vf(request,pfGroup):
  if request.method == "POST":
     body_unicode = request.body.decode('utf-8')
     delIdStr = json.loads(body_unicode)
     delIdArray=delIdStr.split(",")
     for Id in delIdArray:
       #print(Id)
       q=Portfolio.delete().where(Portfolio.id == Id)
       q.execute()
     qry = Portfolio.select().where(Portfolio.group  == pfGroup).order_by(Portfolio.index)
     qry.count
     for index, item in enumerate(qry):
       #print(item._data)
       q = Portfolio.update(index=index).where(Portfolio.id == item.id)
       q.execute()
  return HttpResponseRedirect("/portfolio/" + pfGroup + "/pf0")