def buy(request): gid=request.GET['id'] good=Goods.objects(pk=gid).first() buylog=Buy() buylog.good=good request.user.buylog=request.user.buylog+[buylog] request.user.save() return HttpResponse("buy success")
def getPicture(request): gid=request.GET['id'] num=int(request.GET['num']) good=Goods.objects(pk=gid).first() if num==1: image=good.picture1.read() if num==2: image=good.picture2.read() if num==3: image=good.picture3.read() return HttpResponse(image,mimetype="image/jpeg")
def getGoods(request): gid=request.GET['id'] goods=Goods.objects(pk=gid).first() result=goods.to_mongo() del(result['_types']) result['picture1']=endpoint+"goods/getPicture?id="+str(result['_id'])+"&&num=1" result['picture2']=endpoint+"goods/getPicture?id="+str(result['_id'])+"&&num=2" result['picture3']=endpoint+"goods/getPicture?id="+str(result['_id'])+"&&num=3" del(result['_cls']) del(result['_id']) return HttpResponse(dumps(result))
def getGoodsList(request): buylogs=request.user.to_mongo()['buylog'] for buylog in buylogs: # buylog=buylog.to_mongo() del(buylog['_types']) del(buylog["_cls"]) buylog["time"]=str(buylog["time"]) name=Goods.objects(pk=buylog["good"].id).first().name buylog['name']=name buylog['id']="http://192.168.47.19:8080/goods/getGoods?id="+str(buylog["good"].id) del(buylog['good']) return HttpResponse(ju.dumps(buylogs))
def addNews(request): url=request.POST['url'] news = News() user = request.user # change to request.user news.author = user news.picture = open(request.FILES['picture'].temporary_file_path(), "rb") news.voice = open(request.FILES['voice'].temporary_file_path(), "rb")#change to data from request result=urlparse.urlparse(url) params=urlparse.parse_qs(result.query,True) gid=params['id'] news.good = Goods.objects(pk=gid[0]).first() news.save() return HttpResponse("success")