def post(self,request): #post many data format is [bookscancode,bookscancode.....] #do not need authorized #if not request.user.is_authenticated(): # statusMessage={'status':'refuse'} # return Response(statusMessage,status=status.HTTP_400_BAD_REQUEST) bookRfidCodeListTmp= request.data.get('bookScanCode') #list contain unicode string bookRfidCodeList=[item.encode('utf-8') for item in bookRfidCodeListTmp] #convert to stand string bookDb=Dblibrary() locationDb=DbLocation() #this is class for query book location bookNameList=[bookDb.getBookNameByRfidCode(item) for item in bookRfidCodeList] #get book name #print bookNameList bookOnShelfList=[locationDb.getBookOnShelf(item) for item in bookRfidCodeList] #get book on shelf #print bookOnShelfList bookLocationList=[locationDb.getBookLocation(item) for item in bookRfidCodeList] #get book location #print bookLocationList bookInformationList=[] for code,name,shelf,location in zip(bookRfidCodeList,bookNameList,bookOnShelfList,bookLocationList): oneBook={} oneBook['bookRfidCode']=code.decode('utf-8') oneBook['bookName']=name.decode('utf-8') oneBook['bookOnShelf']=shelf.decode('utf-8') oneBook['bookLocation']=location.decode('utf-8') bookInformationList.append(oneBook) bookInformation={} bookInformation['book']=bookInformationList jsonString=json.dumps(bookInformation) #print jsonString statusMessage={'status':'success'} return Response(jsonString,status=status.HTTP_200_OK)
def get(self,request): #cursor = connections['bookInformationDatabase'].cursor() #cursor.execute("SELECT 索取号 FROM tmxxb where 条形码='214908723' "); #cursor.execute("select * from cgfpb where cgxxbid=296") #result=cursor.fetchall() #value=result[0][0] bookDb=Dblibrary() bookName=bookDb.getBookNameByRfidCode('214908723') return HttpResponse(bookName);