def addToCart(item_id): if 'email' not in session: return redirect(url_for('signin')) else: item=db.query(Product).filter_by(item_id=item_id).first() item_present=db.query(Storeshopper_track).filter_by(session_id=session['email'],sel_item_id=item_id).count() if item_present==0: mycart=Storeshopper_track(session_id=session['email'],name=item.name,sel_item_qty=1,sel_item_id=item_id,date_added=datetime.now(),price=item.price) db.add(mycart) db.commit() else: item_present=db.query(Storeshopper_track).filter_by(session_id=session['email'],sel_item_id=item_id).first() item_present.sel_item_qty+=2 flash("Item is Added to Cart") return redirect(url_for('viewProduct',cat_id=item_id[0]))
def viewProduct(cat_id): show_category() if cat_id>=3: return render_template('game.html') else: items=db.query(Product).filter_by(cat_id=cat_id) return render_template('cat_item.html',items=items,category="category",categories=categories)
def checkout(): msg=Message("you subject",sender='*****@*****.**',recipients=[session['email']]) items=db.query(Storeshopper_track).filter_by(session_id=session['email']).all() msg.body=""" """ total=0 for i in items: msg.body+=""" Name: %s Price: %s Quantity: %s Total Price: %s """%(i.name,i.price,i.sel_item_qty,i.price*i.sel_item_qty) total=total+i.price*i.sel_item_qty msg.body+=""" Total: %s Thankyou For Shopping """%(total) mail.send(msg) #adding user data to userData table newUserData=UserData(user_email=session['email'],date_added=items[0].date_added,amount=total) db.add(newUserData) db.commit() #deleting data from the storeshopper_trac for i in items: db.delete(i) db.commit() return render_template('checkout.html')
def checkout(): msg = Message("you subject", sender='*****@*****.**', recipients=[session['email']]) items = db.query(Storeshopper_track).filter_by( session_id=session['email']).all() msg.body = """ """ total = 0 for i in items: msg.body += """ Name: %s Price: %s Quantity: %s Total Price: %s """ % (i.name, i.price, i.sel_item_qty, i.price * i.sel_item_qty) total = total + i.price * i.sel_item_qty msg.body += """ Total: %s Thankyou For Shopping """ % (total) mail.send(msg) #adding user data to userData table newUserData = UserData(user_email=session['email'], date_added=items[0].date_added, amount=total) db.add(newUserData) db.commit() #deleting data from the storeshopper_trac for i in items: db.delete(i) db.commit() return render_template('checkout.html')
def profile(): if 'email' not in session: return redirect(url_for('signin')) user=db.query(Users).filter_by(email=session['email']).first() if user is None: return redirect(url_for('signup')) else: return redirect(url_for('profileHome'))
def profile(): if 'email' not in session: return redirect(url_for('signin')) user = db.query(Users).filter_by(email=session['email']).first() if user is None: return redirect(url_for('signup')) else: return redirect(url_for('profileHome'))
def showCart(): if 'email' not in session: return redirect(url_for('signin')) else: cart_item=db.query(Storeshopper_track).filter_by(session_id=session['email']) total=0 for item in cart_item: total=total+item.price*item.sel_item_qty return render_template('cart.html',cart_item=cart_item,total=total)
def showCart(): if 'email' not in session: return redirect(url_for('signin')) else: cart_item = db.query(Storeshopper_track).filter_by( session_id=session['email']) total = 0 for item in cart_item: total = total + item.price * item.sel_item_qty return render_template('cart.html', cart_item=cart_item, total=total)
def viewProduct(cat_id): show_category() if cat_id >= 3: return render_template('game.html') else: items = db.query(Product).filter_by(cat_id=cat_id) return render_template('cat_item.html', items=items, category="category", categories=categories)
def validate(self): if not Form.validate(self): return False user = db.query(Users).filter_by(email=self.email.data.lower()).first() if user and user.check_password(self.password.data): return True else: self.email.errors.append("Invalid email or password") return False
def validate(self): if not Form.validate(self): return False user=db.query(Users).filter_by(email=self.email.data.lower()).first() if user: self.email.errors.append("That email is already taken") return False else: return True
def validate(self): if not Form.validate(self): return False user=db.query(Users).filter_by(email=self.email.data.lower()).first() if user and user.check_password(self.password.data): return True else: self.email.errors.append("Invalid email or password") return False
def validate(self): if not Form.validate(self): return False user = db.query(Users).filter_by(email=self.email.data.lower()).first() if user: self.email.errors.append("That email is already taken") return False else: return True
def addToCart(item_id): if 'email' not in session: return redirect(url_for('signin')) else: item = db.query(Product).filter_by(item_id=item_id).first() item_present = db.query(Storeshopper_track).filter_by( session_id=session['email'], sel_item_id=item_id).count() if item_present == 0: mycart = Storeshopper_track(session_id=session['email'], name=item.name, sel_item_qty=1, sel_item_id=item_id, date_added=datetime.now(), price=item.price) db.add(mycart) db.commit() else: item_present = db.query(Storeshopper_track).filter_by( session_id=session['email'], sel_item_id=item_id).first() item_present.sel_item_qty += 2 flash("Item is Added to Cart") return redirect(url_for('viewProduct', cat_id=item_id[0]))
def removeItemFromCart(item_id): item = db.query(Storeshopper_track).filter_by(session_id=session['email'], sel_item_id=item_id).one() db.delete(item) db.commit() return redirect(url_for('showCart'))
def show_category(): global categories categories = db.query(Category).all()
def profileHome(): userData=db.query(UserData).filter_by(user_email=session['email']) return render_template('profileHome.html',userData=userData)
def profileDetails(): user=db.query(Users).filter_by(email=session['email']).first() return render_template('profileDetails.html',user=user)
def updateQuantity(item_id): if request.method=='POST': item=db.query(Storeshopper_track).filter_by(session_id=session['email'],sel_item_id=item_id).first() item.sel_item_qty=request.form['quantity'] return redirect(url_for('showCart'))
def removeItemFromCart(item_id): item=db.query(Storeshopper_track).filter_by(session_id=session['email'],sel_item_id=item_id).one() db.delete(item) db.commit() return redirect(url_for('showCart'))
def updateQuantity(item_id): if request.method == 'POST': item = db.query(Storeshopper_track).filter_by( session_id=session['email'], sel_item_id=item_id).first() item.sel_item_qty = request.form['quantity'] return redirect(url_for('showCart'))
def profileHome(): userData = db.query(UserData).filter_by(user_email=session['email']) return render_template('profileHome.html', userData=userData)
def profileDetails(): user = db.query(Users).filter_by(email=session['email']).first() return render_template('profileDetails.html', user=user)
def decrease_student_year(self): all = db.query(Student).filter_by().all() for each_student in all: each_student.student_year -= 1 db.session.commit()
def show_category(): global categories categories=db.query(Category).all()