コード例 #1
0
ファイル: app.py プロジェクト: MotazBellah/udacity
def enrollment():
    # get the programs
    catalogs = get_nanodegrees()
    # If the user click enroll, get the key from the url
    # check if the user not enrolled already in the program, and notify him if so
    # otherwise, update the db and inform the user
    if request.method == 'POST':
        nanodegree_key = str(request.args.get('key'))
        udacity_user_key = '1'
        status = 'ENROLLED'
        check_enroll = db.execute('''SELECT * FROM enrollments WHERE status = 'ENROLLED'
                                  and nanodegree_key= :key and udacity_user_key = :user_key LIMIT 1;''',
                                  {"key": nanodegree_key, "user_key": udacity_user_key}).fetchall()

        if check_enroll:
            flash("You aleardy enrolled in this program!", 'error')
            return redirect(url_for('enrollment'))

        db.execute("INSERT INTO enrollments (nanodegree_key, udacity_user_key, status) VALUES (:nanodegree_key, :udacity_user_key, :status)",
                    {"nanodegree_key": nanodegree_key, "udacity_user_key": udacity_user_key, "status": status})
        db.commit()
        flash("You have enrolled successfully", 'success')
        return redirect(url_for('enrollment'))

    return render_template('index.html', catalogs=catalogs)
コード例 #2
0
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')
コード例 #3
0
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')
コード例 #4
0
def sellProduct():
	if request.method=='POST':
		if request.form['productName']=='' or request.form['productPrice']=='':
			flash("Enter all details Product Name and Product Price")
		else:
			newProduct=Product(cat_id=request.form['Category'],item_id='2I',name=request.form['productName'],price=request.form['productPrice'],seller=session['email'])
			db.add(newProduct)
			db.commit()
			flash('Your Product is added')

	return redirect(url_for('sellItem'))		
コード例 #5
0
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]))
コード例 #6
0
def signup():
	form=SignupForm()

	if request.method=='POST':
		if form.validate()==False:
			return render_template('signup.html',form=form)
		else:
			newUser=Users(form.firstname.data,form.lastname.data,form.email.data,form.password.data,form.address.data)
			db.add(newUser)
			db.commit()
			session['email']=newUser.email
			return redirect(url_for('profile'))

	elif request.method=='GET':
		return render_template('signup.html',form=form)
コード例 #7
0
def sellProduct():
    if request.method == 'POST':
        if request.form['productName'] == '' or request.form[
                'productPrice'] == '':
            flash("Enter all details Product Name and Product Price")
        else:
            newProduct = Product(cat_id=request.form['Category'],
                                 item_id='2I',
                                 name=request.form['productName'],
                                 price=request.form['productPrice'],
                                 seller=session['email'])
            db.add(newProduct)
            db.commit()
            flash('Your Product is added')

    return redirect(url_for('sellItem'))
コード例 #8
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:
            newUser = Users(form.firstname.data, form.lastname.data,
                            form.email.data, form.password.data,
                            form.address.data)
            db.add(newUser)
            db.commit()
            session['email'] = newUser.email
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signup.html', form=form)
コード例 #9
0
ファイル: app.py プロジェクト: MotazBellah/enrollment
def enrollment():
    catalogs = get_nanodegrees()
    if request.method == 'POST':
        nanodegree_key = request.args.get('key')
        udacity_user_key = '1'
        status = 'ENROLLED'
        db.execute(
            "INSERT INTO enrollments (nanodegree_key, udacity_user_key, status) VALUES (:nanodegree_key, :udacity_user_key, :status)",
            {
                "nanodegree_key": nanodegree_key,
                "udacity_user_key": udacity_user_key,
                "status": status
            })
        db.commit()
        return redirect(url_for('enrollment'))

    return render_template('index.html', catalogs=catalogs.keys()[0])
コード例 #10
0
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]))
コード例 #11
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'))
コード例 #12
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'))