def modify(request): documentId=request.POST.get('documentId') deliverystate=request.POST.get('deliveryState') deliverycode=request.POST.get('deliverycode') deliverynum=request.POST.get('deliverynum') doc_ref=db.collection("delivery").document(documentId) doc=doc_ref.get() if doc.exists: delivery=Delivery.from_dict(doc.to_dict()) option="s:"+str(delivery.option['s'])+"m:"+str(delivery.option['m'])+"l:"+str(delivery.option['l'])+"xl:"+str(delivery.option['xl']) # doc_ref.set( # Delivery(delivery.brandname,delivery.product_name,checkbox,name,sex,zipcode,adress,adressdetail).to_dict() # ) doc_ref.update({u'deliverystate': deliverystate}) doc_ref.update({u'deliverycode': deliverycode}) doc_ref.update({u'deliverynum': deliverynum}) user_uid=delivery.uid user_ref=db.collection("users").document(user_uid).collection("delivery").document(documentId) user_ref.update({u'deliverystate': deliverystate}) user_ref.update({u'deliverycode': deliverycode}) user_ref.update({u'deliverynum': deliverynum}) else: print(u'No such document!') doc2=doc_ref.get() if doc2.exists: delivery2=Delivery.from_dict(doc2.to_dict()) print(type(delivery2.option)) print(delivery2.option['s']) option2="s:"+str(delivery2.option['s'])+"m:"+str(delivery2.option['m'])+"l:"+str(delivery2.option['l'])+"xl:"+str(delivery2.option['xl']) # doc_ref.set( # Delivery(delivery.brandname,delivery.product_name,checkbox,name,sex,zipcode,adress,adressdetail).to_dict() # ) else: print(u'No such document!') #url="admin/delivery/home/detail/"+documentId+"/" return render(request,"admin_delivery_modify.html",{'delivery':delivery2,'option':option2,'id':documentId})
def detail(request,id): doc_ref=db.collection("delivery").document(id) doc=doc_ref.get() if doc.exists: delivery=Delivery.from_dict(doc.to_dict()) print(type(delivery.option)) print(delivery.option['s']) option="s:"+str(delivery.option['s'])+"m:"+str(delivery.option['m'])+"l:"+str(delivery.option['l'])+"xl:"+str(delivery.option['xl']) else: print(u'No such document!') return render(request,"admin_delivery_modify.html",{'delivery':delivery,'option':option,'id':id})
def review_write(request,delivery_uid): delivery_ref=db.collection("delivery").document(delivery_uid) delivery_doc=delivery_ref.get() if delivery_doc.exists: delivery=Delivery.from_dict(delivery_doc.to_dict()) return render(request, 'reviewIndex.html',{"delivery_uid":delivery_uid,"delivery":delivery}) else: print(u'No such document!') return render(request, 'reviewIndex.html',{"delivery_uid":delivery_uid})
def cart_order_complete(request, total_price, username, phonenumber, address, uid, delivery_message): delivery_lis = [] cart_ref = db.collection("users").document(uid).collection('cart') cart_alldoc = cart_ref.stream() for doc in cart_alldoc: cart = Cart.from_dict(doc.to_dict()) doc_ref = db.collection("delivery") doc_ref_random = db.collection("delivery").document() doc_ref_random.set( Delivery(cart.brand, cart.name, cart.sizedic, total_price, username, phonenumber, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, cart.downloadurl, cart.documentId).to_dict()) user_doc = db.collection("users").document(uid).collection( "delivery").document(doc_ref_random.id) user_doc.set( Delivery(cart.brand, cart.name, cart.sizedic, total_price, username, phonenumber, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, cart.downloadurl, cart.documentId).to_dict()) delievery_par = Delivery.from_dict( Delivery(cart.brand, cart.name, cart.sizedic, cart.price, username, phonenumber, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, cart.downloadurl, cart.documentId).to_dict()) # delivery=Delivery.from_dict(delivery_docs.to_dict()) delivery_lis.append(delievery_par) #print(delivery_lis) #for문끝 def delete_collection(coll_ref, batch_size): deldocs = coll_ref.limit(batch_size).stream() deleted = 0 for doc in deldocs: print(f'Deleting doc {doc.id} => {doc.to_dict()}') doc.reference.delete() deleted = deleted + 1 if deleted >= batch_size: return delete_collection(coll_ref, batch_size) delete_collection(cart_ref, 3) return render(request, 'getdata.html', {'delivery_lis': delivery_lis})
def home(request): adminemail="Dumstruck" adminpass="******" email=request.POST.get('email') passw=request.POST.get('pass') if adminemail != email or passw != adminpass : try : request.session['admin_delivey_uid'] delivery_lis=[] delivery_id=[] delivery_ref=db.collection("delivery") delivery_docs=delivery_ref.stream() for doc in delivery_docs: #print(f'{doc.id} => {doc.to_dict()}') delivery=Delivery.from_dict(doc.to_dict()) delivery_lis.append(delivery) delivery_id.append(doc.id) comb_lis=zip(delivery_lis,delivery_id) return render(request,"admin_delivery_home.html",{"e":email,'comb_lis':comb_lis}) except: message="Invalid credentials" return render(request,"admin_delivery_login.html",{"messg":message}) else : request.session['admin_delivey_uid']=adminemail delivery_lis=[] delivery_id=[] delivery_ref=db.collection("delivery") delivery_docs=delivery_ref.stream() for doc in delivery_docs: #print(f'{doc.id} => {doc.to_dict()}') delivery=Delivery.from_dict(doc.to_dict()) delivery_lis.append(delivery) delivery_id.append(doc.id) comb_lis=zip(delivery_lis,delivery_id) return render(request,"admin_delivery_home.html",{"e":email,'comb_lis':comb_lis})
def orderinfo(request): uid=None try: print("카트"+request.session['uid']) uid=request.session['uid'] user_doc=db.collection("users").document(uid).collection("delivery") user_alldocs=user_doc.stream() print("??") deliverylist=[] doc_id_lis=[] krtime_lis=[] option_lis=[] for doc in user_alldocs: option="" delivery=Delivery.from_dict(doc.to_dict()) ustime=str(delivery.timestamp)[0:10] print("도큐아이디"+str(doc.id)) ##옵션 만들기 if delivery.option['s'] !=0: option+="S:"+str(delivery.option['s'])+" " if delivery.option['m'] !=0: option+="M:"+str(delivery.option['m'])+" " if delivery.option['l'] !=0: option+="L:"+str(delivery.option['l'])+" " if delivery.option['xl'] !=0: option+="XL:"+str(delivery.option['xl'])+" " print(option) krtime_lis.append(ustime) deliverylist.append(delivery) doc_id_lis.append(doc.id) option_lis.append(option) comb_lis=zip(deliverylist,doc_id_lis,krtime_lis,option_lis) return render(request, 'orderinfo.html',{'uid':uid,'comb_lis':comb_lis}) except: return render(request, 'signin.html',{'uid':uid})
def nonmember_lookup_action(request) : uid=None tel=request.POST.get('tel') uid=tel user_doc=db.collection("users").document(uid).collection("delivery") user_alldocs=user_doc.stream() print("??") deliverylist=[] for doc in user_alldocs: delivery=Delivery.from_dict(doc.to_dict()) #print(delivery) deliverylist.append(delivery) return render(request, 'orderinfo.html',{'deliverylist':deliverylist})
def getdata(request, option, price, username, phonenum, address, uid, delivery_message, product_id): delivery_lis = [] prd_ref = db.collection(u'product').document(product_id) prd_docs = prd_ref.get() dictionary = literal_eval(option) if prd_docs.exists: products = Product.from_dict(prd_docs.to_dict()) img = products.downloadurl brandname = products.brand product_name = products.name doc_ref = db.collection("delivery") doc_ref_random = db.collection("delivery").document() doc_ref_random.set( Delivery(brandname, product_name, dictionary, price, username, phonenum, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, img, product_id).to_dict()) user_doc = db.collection("users").document(uid).collection( "delivery").document(doc_ref_random.id) user_doc.set( Delivery(brandname, product_name, dictionary, price, username, phonenum, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, img, product_id).to_dict()) delievery_par = Delivery.from_dict( Delivery(brandname, product_name, dictionary, price, username, phonenum, address, firestore.SERVER_TIMESTAMP, "배송전", "", "", uid, delivery_message, img, product_id).to_dict()) # delivery=Delivery.from_dict(delivery_docs.to_dict()) delivery_lis.append(delievery_par) #print(delivery_lis) #유저에서 딜리버리 가져오기 else: print(u'No such document!') return render(request, 'getdata.html', {'delivery_lis': delivery_lis})
def cartfinishedpay(request, total_price, username, phonenumber, address, uid, delivery_message): uid = None try: print("카트" + request.session['uid']) uid = request.session['uid'] user_doc = db.collection("users").document(uid).collection("delivery") user_alldocs = user_doc.stream() print("??") deliverylist = [] for doc in user_alldocs: delivery = Delivery.from_dict(doc.to_dict()) #print(delivery) deliverylist.append(delivery) return render(request, 'orderinfo.html', { 'uid': uid, 'deliverylist': deliverylist }) except: return render(request, 'signin.html', {'uid': uid})
def detail(request,documentId): #테스트 uid=None com_lis=[] recentview_lis=[] print("홈시작") try: recentview_lis=request.session['RecentView'] except: print("recentview 없음") if len(recentview_lis)<6 : recentview_lis.append(documentId) my_set = set(recentview_lis) my_list = list(my_set) request.session['RecentView']=my_list else : recentview_lis.pop(0) recentview_lis.append(documentId) my_set = set(recentview_lis) my_list = list(my_set) request.session['RecentView']=my_list try: print("홈에서"+request.session['uid']) uid=request.session['uid'] except: print("로그인안댐") doc_ref=db.collection(u'product').document(documentId) doc = doc_ref.get() products=None review_lis=[] user_lis=[] delivery_lis=[] if doc.exists: print(u'Document data: {}'.format(doc.to_dict())) products=Product.from_dict(doc.to_dict()) review_ref=db.collection(u'product').document(documentId).collection('review') review_alldocs=review_ref.stream() for doc in review_alldocs: review=Review.from_dict(doc.to_dict()) print(review.text) review_lis.append(review) #review user review_user_ref=db.collection(u'users').document(review.user_uid) review_user_doc=review_user_ref.get() if review_user_doc.exists: user=UserModel.from_dict(review_user_doc.to_dict()) user_lis.append(user) #review delivery review_delivery_ref=db.collection(u'delivery').document(review.delivery_uid) review_delivery_doc=review_delivery_ref.get() if review_delivery_doc.exists: delivery=Delivery.from_dict(review_delivery_doc.to_dict()) delivery_lis.append(delivery) com_lis=zip(review_lis,user_lis,delivery_lis) else: print(u'No such document!') return render(request,"detail.html",{'products':products,'documentId':documentId,'uid':uid,'com_lis':com_lis })