diff --git a/shop/__init__.py b/shop/__init__.py index a589609519f6778fe18442fa8c234c326c8aea87..8a7e0ce9a592ddca50f2acd428bdbe1711813df7 100644 --- a/shop/__init__.py +++ b/shop/__init__.py @@ -6,9 +6,6 @@ from flask_login import LoginManager app = Flask(__name__) app.config['SECRET_KEY'] = 'edd9229339e5754427a7792fc79b51318395e93569165fa4' -# Note: type 'app.config[..]' as one line, it is split into -# multiple lines in this document to fit on the page -# {USERNAME} and {YOUR_DATABASE} are your Cardiff username app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://c2003538:Newport123@csmysql.cs.cf.ac.uk:3306/c2003538_Online_Shop' db = SQLAlchemy(app) login_manager = LoginManager() diff --git a/shop/__pycache__/__init__.cpython-36.pyc b/shop/__pycache__/__init__.cpython-36.pyc index 7ac21e429f8d4ff6a5fbc6f32999dfad242e3cc5..b5e484a9e9eaf26247ba2fccb0bffdd504c6ed1d 100644 Binary files a/shop/__pycache__/__init__.cpython-36.pyc and b/shop/__pycache__/__init__.cpython-36.pyc differ diff --git a/shop/__pycache__/forms.cpython-36.pyc b/shop/__pycache__/forms.cpython-36.pyc index f528a15e149e1029f9899d252b1531fbc35bbb5b..1e65f1827fd0bc722984333f05e736f8d51d84a2 100644 Binary files a/shop/__pycache__/forms.cpython-36.pyc and b/shop/__pycache__/forms.cpython-36.pyc differ diff --git a/shop/__pycache__/models.cpython-36.pyc b/shop/__pycache__/models.cpython-36.pyc index 4dbdbba77a5dc13fec52702b0780c3e813ce53fb..4150373573d57f39b6e8e230f096525334e6822c 100644 Binary files a/shop/__pycache__/models.cpython-36.pyc and b/shop/__pycache__/models.cpython-36.pyc differ diff --git a/shop/__pycache__/routes.cpython-36.pyc b/shop/__pycache__/routes.cpython-36.pyc index 4247e39a88d7ca520d3d5e2aec2a0f63464ddec1..9de1141d2e720f51a4efea0aba1e63abc1b57ecd 100644 Binary files a/shop/__pycache__/routes.cpython-36.pyc and b/shop/__pycache__/routes.cpython-36.pyc differ diff --git a/shop/__pycache__/views.cpython-36.pyc b/shop/__pycache__/views.cpython-36.pyc index 6c01cf3bc463ecb04415b1534c1b5e0e67c8e14d..b11e42be9cc2b4a56977d3e218f9ce0d3fc65e59 100644 Binary files a/shop/__pycache__/views.cpython-36.pyc and b/shop/__pycache__/views.cpython-36.pyc differ diff --git a/shop/forms.py b/shop/forms.py index 4c6be5f6473e9a739a50be70e5de5910edf7f588..f7b5545ca72580e69c39b9cdeae772edfca1d892 100644 --- a/shop/forms.py +++ b/shop/forms.py @@ -16,13 +16,13 @@ class RegistrationForm(FlaskForm): def validate_username(self, username): user = User.query.filter_by(username=username.data).first() if user: - raise ValidationError('Oh no! This username has already been taken. Please choose a different one.') + raise ValidationError('This username has already been taken. Please choose a different one.') def validate_email(self, email): user = User.query.filter_by(email=email.data).first() - + if user: - raise ValidationError('Oh no! This email is already registered. Please choose a different one.') + raise ValidationError('This email is already registered. Please choose a different one.') class LoginForm(FlaskForm): @@ -32,19 +32,14 @@ class LoginForm(FlaskForm): class SearchForm(FlaskForm): - choices = [('Rose', 'Rose'), ('Lily', 'Lily'), ('Daisy', 'Daisy'), ('Sunflower', 'Sunflower'), ('Carnation', 'Carnation'), ('Freesia', 'Freesia'), ('Jasmine', 'Jasmine'), ('Peony', 'Peony'), ('Amaryllis', 'Amaryllis')] - select = SelectField('Search flower:', choices=choices) + choices = [('Pen', 'Pen'), ('Pencil', 'Pencil'), ('Rubber', 'Rubber'), ('USB', 'USB'), ('Rubber', 'Rubber'), ('Calculator', 'Calculator')] + select = SelectField('Search item:', choices=choices) search = StringField('') class CheckoutForm(FlaskForm): - forename = StringField('Forename', validators=[DataRequired('Please enter your forename'), Length(min=3, max=15)]) - surname = StringField('Surname', validators=[DataRequired('Please enter your surname'), Length(min=3, max=15)]) - address = StringField('Address', - validators=[DataRequired('Please enter your billing address')]) - card_no = PasswordField('card_no', validators=[DataRequired('Please enter your 16-digit card number'), Length(min=16, max=16)]) - cvc = PasswordField('cvc', validators=[DataRequired('Please enter your 3-digit CVC'), Length(min=3, max=3)]) - submit = SubmitField('Checkout') - - - - + FisrtName = StringField('First Name', validators=[DataRequired('Please enter your First Name'), Length(min=3, max=15)]) + LastName = StringField('Last Name', validators=[DataRequired('Please enter your Last Name'), Length(min=3, max=15)]) + Adress = StringField('Address', validators=[DataRequired('Please enter your Address')]) + Card_No = PasswordField('Card_No', validators=[DataRequired('Please enter your 16-digit card number'), Length(min=16, max=16)]) + CVC = PasswordField('CVC', validators=[DataRequired('Please enter your 3-digit CVC'), Length(min=3, max=3)]) + Submit = SubmitField('Checkout') diff --git a/shop/models.py b/shop/models.py index b3d1f8376091f1453b433c0ee9d9c099ee54955d..3422bd4f4dcfffdaf9237f32608666c35635a604 100644 --- a/shop/models.py +++ b/shop/models.py @@ -7,7 +7,6 @@ class Item(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(50),nullable=False) description = db.Column(db.String(300), nullable=False) - #publication_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) price = db.Column(db.Numeric(10,2), nullable=False) image_file = db.Column(db.String(50), nullable=False, default='default.jpg') @@ -40,7 +39,7 @@ class User(UserMixin, db.Model): def load_user(user_id): return User.query.get(int(user_id)) -class Cart(db.Model): +class Basket(db.Model): id = db.Column(db.Integer, primary_key=True) quantity = db.Column(db.Integer) item_id = db.Column(db.Integer, db.ForeignKey('item.id'), nullable=False) diff --git a/shop/routes.py b/shop/routes.py index c25347689cde298b578e429e48179ad90e38cf29..63c840200ac418d0fc2c383c3b63e2337fdc9e06 100644 --- a/shop/routes.py +++ b/shop/routes.py @@ -5,6 +5,7 @@ from shop.models import Item, User from shop.forms import RegistrationForm, LoginForm, SearchForm, CheckoutForm from flask_login import login_user, current_user, logout_user, login_required + @app.route("/", methods= ['GET', 'POST']) @app.route("/home", methods= ['GET', 'POST']) @@ -23,18 +24,18 @@ def about(): return render_template('about.html', title='About') -@app.route("/orderasc") -def orderasc(): +@app.route("/Asc") +def Asc(): return render_template('home.html', items = Item.query.order_by("price"), title='Home') -@app.route("/orderdesc") -def orderdesc(): +@app.route("/Desc") +def Desc(): return render_template('home.html', items = Item.query.order_by("price")[::-1], title='Home') @app.route("/item/<int:item_id>") def item(item_id): item = Item.query.get_or_404(item_id) - return render_template('item.html', item=item) #title=book.title + return render_template('item.html', item=item) @app.route("/register", methods=['GET', 'POST']) def register(): @@ -54,8 +55,7 @@ def register(): def checkout(): form = CheckoutForm() if form.validate_on_submit(): - #user = User(forename=form.forename.data,surname=form.surname.data) - session["cart"] = [] + session["basket"] = [] return redirect(url_for('thankyou')) return render_template('checkout.html', title='Checkout', form=form) @@ -82,22 +82,22 @@ def logout(): logout_user() return redirect(url_for('home')) -@app.route("/add_to_cart/<int:item_id>") -def add_to_cart(item_id): - if "cart" not in session: - session["cart"] = [] - session["cart"].append(item_id) - flash("The item is added to your shopping cart!") - return redirect("/cart") - -@app.route("/cart", methods=['GET', 'POST']) -def cart_display(): - if "cart" not in session: - flash('There is nothing in your cart.') - return render_template("cart.html", display_cart = {}, total = 0) +@app.route("/add_to_basket/<int:item_id>") +def add_to_basket(item_id): + if "basket" not in session: + session["basket"] = [] + session["basket"].append(item_id) + flash("The item is added to your shopping basket!") + return redirect("/basket") + +@app.route("/basket", methods=['GET', 'POST']) +def basket_display(): + if "basket" not in session: + flash('There is nothing in your basket.') + return render_template("basket.html", display_basket = {}, total = 0) else: - items = session["cart"] - cart = {} + items = session["basket"] + basket = {} total_price = 0 total_quantity = 0 @@ -105,29 +105,29 @@ def cart_display(): item = Item.query.get_or_404(item) total_price += item.price - if item.id in cart: - cart[item.id]["quantity"] += 1 + if item.id in basket: + basket[item.id]["quantity"] += 1 else: - cart[item.id] = {"quantity":1, "title": item.title, "price":item.price} - total_quantity = sum(item['quantity'] for item in cart.values()) + basket[item.id] = {"quantity":1, "title": item.title, "price":item.price} + total_quantity = sum(item['quantity'] for item in basket.values()) - return render_template("cart.html", title='Your Shopping Cart', display_cart = cart, total = total_price, total_quantity = total_quantity) + return render_template("basket.html", title='Your Shopping basket', display_basket = basket, total = total_price, total_quantity = total_quantity) - return render_template('cart.html') + return render_template('basket.html') @app.route("/delete_item/<int:item_id>", methods=['GET', 'POST']) def delete_item(item_id): - if "cart" not in session: - session["cart"] = [] + if "basket" not in session: + session["basket"] = [] - session["cart"].remove(item_id) + session["basket"].remove(item_id) - flash("The item has been removed from your shopping cart!") + flash("The item has been removed from your shopping basket!") session.modified = True - return redirect("/cart") + return redirect("/basket") @app.route("/add_to_wishlist/<int:item_id>") def add_to_wishlist(item_id): @@ -158,7 +158,7 @@ def wishlist_display(): wishlist[item.id] = {"quantity":1, "title": item.title, "price":item.price} total_quantity_wishlist = sum(item_id['quantity'] for item_id in wishlist.values()) - return render_template("wishlist.html", title= "Your Shopping Cart", display_wishlist = wishlist, total = total_price, total_quantity_wishlist = total_quantity_wishlist) + return render_template("wishlist.html", title= "Your Shopping Basket", display_wishlist = wishlist, total = total_price, total_quantity_wishlist = total_quantity_wishlist) @app.route("/delete_item_wishlist/<int:item_id>", methods=['GET', 'POST']) def delete_item_wishlist(item_id): diff --git a/shop/static/style.css b/shop/static/style.css index f0679003fb28b392e038d1e6b342d15b8d9854dd..65c0c1a87cbedd1a84f89e63bfff30a4113cde0a 100644 --- a/shop/static/style.css +++ b/shop/static/style.css @@ -1,11 +1,11 @@ body { - font-family:helvetica, sans-serif; + font-family:Arial, sans-serif; background-color: white; } h1 { padding-left: 20px; - font-family:sans-serif; + font-family:san-serif; color:black; } diff --git a/shop/templates/about.html b/shop/templates/about.html index b822f8d95d51c6478c0c45584adcc720b504234f..1e1c436801c25246cab6cf3cc109157fb5cf62ef 100644 --- a/shop/templates/about.html +++ b/shop/templates/about.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} {% block content %} <h1>This is the About Us Page</h1> -<p>Needs some new staionary? this place sells all of it </p> +<p>Needs some new staionary? StationaryFix sells all of it </p> {% endblock content %} diff --git a/shop/templates/cart.html b/shop/templates/cart.html deleted file mode 100644 index 026dbca70e8d61acd1e5bb11d9fc83e8a5f0025f..0000000000000000000000000000000000000000 --- a/shop/templates/cart.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends "layout.html" %} -{% block content %} -<h1>{{ title }}</h1> - -<table class=""> - <tr><th>Product</th><th>Quantity</th><th>Price</th><th>Total</th></tr> - - {% for key, value in display_cart.items() %} - <tr> - <!-- <td>{{ key }}</td> --> - <td>{{ value["title"] }}</td> - <td>{{ value["quantity"] }}</td> - <td>£{{ value["price"] }}</td> - <td>£{{ (value["quantity"] * value["price"]) }}</td> - - <td> - <form action="{{ url_for('delete_item', item_id=key|int) }}" method="POST"> - <input class="" type="submit" value="Delete"> - </form> - </td> - </tr> - {% endfor %} - -</table> -<h3>Total: £{{ total }} </h3> -<h3>Number of items: {{ total_quantity }} </h3> - -{% if current_user.is_authenticated %} - -<a href = "{{ url_for('checkout') }}">Checkout</a>  - -{% else %} - -<a href = "{{ url_for('register') }}">Create an account to checkout</a> - -{% endif %} - -{% endblock content %} diff --git a/shop/templates/home.html b/shop/templates/home.html index 5c6335ba194c40dd1deda3dfe4aaf17783579d6a..5c8a7d2b59abe44750d9aed611c32af97653bfa1 100644 --- a/shop/templates/home.html +++ b/shop/templates/home.html @@ -1,4 +1,36 @@ {% extends "layout.html" %} {% block content %} -<h1>This is About Us page</h1> +<h1> StationaryFix </h1> +<div class="search-container"> + <form method="POST"> + <input type="text" placeholder="Search..." name="home"> + <button type="submit">Search</button> + </form> +</div> + +<div class="dropdown"> + <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + Sort By + </button> + <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> + <a class="dropdown-item" href="Asc">Low-High</a> | + <a class="dropdown-item" href="Desc">High-Low</a> | +</div> + + {% for item in items %} +<div style="float:left; margin:40px; width: 295px; padding: 40px;"> + <a href="{{ url_for('item', item_id=item.id) }}"> + <img src = "{{ url_for('static', filename='img/' + item.image_file) }}" width="300" height="300"></a> + <!--<a href="{{ url_for('item', item_id=item.id) }}">--> + <p>"{{ item.title }}"</p></a> + <p>Price (£): {{ item.price }}</p> + <p>Description: {{item.description}}</p> + <a class="" href="/add_to_basket/{{item.id}}">Add to Basket</a> <br/> + + <a class="" href="/add_to_wishlist/{{item.id}}">Add to Wishlist</a>  + +</div> + + {% endfor %} +</div> {% endblock content %} diff --git a/shop/templates/item.html b/shop/templates/item.html index 924f491d806893055b8f7ee56340c6ace27a89ff..ebd68b7e948acc6b00156efc683eaaaf83829be0 100644 --- a/shop/templates/item.html +++ b/shop/templates/item.html @@ -3,10 +3,10 @@ <img src = "{{ url_for('static', filename='img/' + item.image_file) }}" width="300" height="300"> - <p>"{{ item.title }}" </p> + <p>{{ item.title }} </p> <p>Price: {{ item.price }}</p> <p>Description: {{item.description}}</p> - <a class="" href="/add_to_cart/{{item.id}}">Add to Cart</a> | - <a class="" href="/add_to_wishlist/{{item.id}}">Add to Wishlist</a> | + <a class="" href="/add_to_basket/{{item.id}}">Add to Basket</a>  + <a class="" href="/add_to_wishlist/{{item.id}}">Add to Wishlist</a>  {% endblock content %} diff --git a/shop/templates/layout.html b/shop/templates/layout.html index dd013bbc5b725de58f9b430841d0e81f695cf4e9..979e6a5f1fb488c472f5b439834a27d2ab9fd080 100644 --- a/shop/templates/layout.html +++ b/shop/templates/layout.html @@ -14,17 +14,17 @@ <body> <div id="header"> - <a href="{{ url_for('home') }}" class="header">Home</a> | - <a href="{{ url_for('about') }}" class="header">About Us</a> | + <a href="{{ url_for('home') }}" class="header">Home</a>  + <a href="{{ url_for('about') }}" class="header">About Us</a>  {% if current_user.is_authenticated %} Hello, {{ current_user.username }}! - <a class="nav-item nav-link" href="{{ url_for('logout') }}">Logout</a> | + <a class="nav-item nav-link" href="{{ url_for('logout') }}">Logout</a>  {% else %} - Hello, Guest!  | <a href="{{ url_for('login') }}">Login </a> - or <a href="{{ url_for('register') }}">Register</a> | + Hello, Guest!   <a href="{{ url_for('login') }}">Login </a> + or <a href="{{ url_for('register') }}">Register</a>  {% endif %} - <a href="{{ url_for('cart_display') }}" class="header">Cart ({{total_quantity}} items) </a> | - <a href="{{ url_for('wishlist_display') }}" class="header">My Wishlist ({{total_quantity_wishlist}} items)</a> | + <a href="{{ url_for('basket_display') }}" class="header">Basket ({{total_quantity}}) </a>  + <a href="{{ url_for('wishlist_display') }}" class="header">My Wishlist ({{total_quantity_wishlist}})</a>  </div> diff --git a/shop/templates/login.html b/shop/templates/login.html index 0eab63061a3ce1d9ace009912ef90f1b615997fe..74bec0c864fac12e34b6b71c794920cf6aa70dfd 100644 --- a/shop/templates/login.html +++ b/shop/templates/login.html @@ -22,4 +22,4 @@ </form> -{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/shop/templates/thankyou.html b/shop/templates/thankyou.html index aefda0953f3fcc9a0dafbf7e0807e7928f4a644e..ffbe44870e65ead4b4c2443bd0a382bc89f3982b 100644 --- a/shop/templates/thankyou.html +++ b/shop/templates/thankyou.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} {% block content %} - <h1>Thank You for shopping with us We look forward to seeing you again!</h1> + <h1>Thank You for shopping with StationaryFix We look forward to seeing you again!</h1> <a class="" href="/home">Home</a> {% endblock content %} diff --git a/shop/views.py b/shop/views.py index ae3fac03ea3db4cebe92d6055231d059bff0aff6..609435fce7f1bb8e323645b6ac5f2acc3249e733 100644 --- a/shop/views.py +++ b/shop/views.py @@ -1,6 +1,6 @@ from flask_admin.contrib.sqla import ModelView import flask_login as login -from shop.models import User +from shop.models import User, Item class AdminView(ModelView): def is_accessible(self): if login.current_user.is_authenticated: