diff --git a/instance/database.db b/instance/database.db index 4ecb35b6738983767d24c447a815d93e7e3ace54..22c011408e2e6f3d1890dfc83d4423d981d9b486 100644 Binary files a/instance/database.db and b/instance/database.db differ diff --git a/store/__pycache__/itemInit.cpython-39.pyc b/store/__pycache__/itemInit.cpython-39.pyc index d40d6c4947cac6e84d17dafbee8d59b24661efa4..6285db82f9eeab9871fcf8f9d7b598d28361ebb0 100644 Binary files a/store/__pycache__/itemInit.cpython-39.pyc and b/store/__pycache__/itemInit.cpython-39.pyc differ diff --git a/store/__pycache__/models.cpython-39.pyc b/store/__pycache__/models.cpython-39.pyc index 57e3b10b75776f35990daa91d10e4d02bf88b5e1..884f468017782ad33618e82e4297248a026ead59 100644 Binary files a/store/__pycache__/models.cpython-39.pyc and b/store/__pycache__/models.cpython-39.pyc differ diff --git a/store/__pycache__/views.cpython-39.pyc b/store/__pycache__/views.cpython-39.pyc index 5b081deebbbd5c4681502ff87aac0c9903fcf826..b0a2352c864a74d0ba68ef69daaec9787d37c5ff 100644 Binary files a/store/__pycache__/views.cpython-39.pyc and b/store/__pycache__/views.cpython-39.pyc differ diff --git a/store/itemInit.py b/store/itemInit.py index 42fbff1e568f1dc7477a782e978b9e3dd82a0441..e33a547384d91c598a1670c541a0a4ac2a2aab9d 100644 --- a/store/itemInit.py +++ b/store/itemInit.py @@ -1,32 +1,40 @@ from .models import Product - +from . import db def getCreamer(): creamer = Product.query.filter_by(shorthand="creamer").first() if not creamer: - creamer = Product(name="Real Cow Dairy-Free Creamer", shorthand="creamer", price=120, envImpact=6) + creamer = Product(id="1", name="Real Cow Dairy-Free Creamer", shorthand="creamer", price=120, envImpact=6) + db.session.add(creamer) + db.session.commit() return creamer def getDread(): - creamer = Product.query.filter_by(shorthand="dread").first() - if not creamer: - creamer = Product(name="Existential Dread Relief", shorthand="dread", price=470, envImpact=3) - return creamer + dread = Product.query.filter_by(shorthand="dread").first() + if not dread: + dread = Product(id="2",name="Existential Dread Relief", shorthand="dread", price=470, envImpact=3) + db.session.add(dread) + db.session.commit() + return dread def getExistence(): - creamer = Product.query.filter_by(shorthand="existence").first() - if not creamer: - creamer = Product(name="Instant Existence", shorthand="existence", price=260, envImpact=2) - return creamer + existence = Product.query.filter_by(shorthand="existence").first() + if not existence: + existence = Product(id="3",name="Instant Existence", shorthand="existence", price=260, envImpact=2) + db.session.add(existence) + db.session.commit() + return existence def getFly(): - creamer = Product.query.filter_by(shorthand="fly").first() - if not creamer: - creamer = Product(name="Non-Stick Fly Paper", shorthand="fly", price=263, envImpact=5) - return creamer + fly = Product.query.filter_by(shorthand="fly").first() + if not fly: + fly = Product(id="4", name="Non-Stick Fly Paper", shorthand="fly", price=263, envImpact=5) + db.session.add(fly) + db.session.commit() + return fly def getProducts(string=""): diff --git a/store/models.py b/store/models.py index 5f63fca640276dfa5fd56c42d010d5fd39c28322..6de550bfa7cb1d705db8b44a97d1fde5c707051a 100644 --- a/store/models.py +++ b/store/models.py @@ -1,3 +1,5 @@ +from sqlalchemy.orm import backref + from . import db from flask_login import UserMixin @@ -21,7 +23,7 @@ class Product(db.Model): class Review(db.Model): id = db.Column(db.Integer, primary_key=True) item_id = db.Column(db.Integer, db.ForeignKey('product.id')) - user_id = db.Column(db.Integer, db.ForeignKey('user.id')) + user = db.relationship('User') description = db.Column(db.String(250)) rating = db.Column(db.Integer) @@ -31,5 +33,5 @@ class User(db.Model, UserMixin): password = db.Column(db.String(100)) username = db.Column(db.String(100), unique=True) basket = db.relationship('Basket') - reviews = db.relationship('Review') + review_id = db.Column(db.Integer, db.ForeignKey('review.id')) diff --git a/store/templates/checkout.html b/store/templates/checkout.html index de0ff122a6e22ad5e8f631a2d92e302f1f3cfe52..7ccdab2e574dfa59a4780ae9a1757c5177053169 100644 --- a/store/templates/checkout.html +++ b/store/templates/checkout.html @@ -25,7 +25,7 @@ <div class="icon-discover icon icon-cc-discover"></div> </div> <div style="margin-left: auto;margin-right:100px;margin-top:14px;height:60px"> - <input id="ccn" class='input-ccn' style="width:200px;text-align: center;margin-right: 60px;margin-top:10px" type="tel" placeholder="XXXX XXXX XXXX XXXX"/> + <input id="ccn" class='input-ccn form-control' style="width:200px;text-align: center;margin-right: 60px;margin-top:10px" type="tel" placeholder="XXXX XXXX XXXX XXXX"/> </div> <div class="btn-clear hidden-right">clear</div> </div> @@ -38,7 +38,7 @@ </div> </div> <div style="margin-left: auto;margin-right:150px;margin-top:14px;height:60px"> - <input id="exp" class='input-exp' style="width:100px;text-align: center;margin-right: 60px;margin-top:10px" type="text" placeholder="MM/YY"/> + <input id="exp" class='input-exp form-control' style="width:100px;text-align: center;margin-right: 60px;margin-top:10px" type="text" placeholder="MM/YY"/> </div> </div> </div> @@ -49,8 +49,8 @@ CVC / CCV </div> </div> - <div style="margin-left: auto;margin-right:160px;margin-top:14px;height:60px"> - <input id="cvc" class='input-cvc' style="width:100px;text-align: center;margin-right: 60px;margin-top:10px" type="number" placeholder="XXX"/> + <div style="margin-left: auto;margin-right:150px;margin-top:14px;height:60px"> + <input id="cvc" class='input-cvc form-control' style="width:100px;text-align: center;margin-right: 60px;margin-top:10px" type="number" placeholder="XXX"/> </div> </div> </div> diff --git a/store/templates/creamer.html b/store/templates/creamer.html index 5e20bb3e2bbca83c59970de91e622786216fc069..3b343d662853a96adae314890563b404c6d2c7ce 100644 --- a/store/templates/creamer.html +++ b/store/templates/creamer.html @@ -1,115 +1,9 @@ -{% extends "base.html" %} {% block title %}Home{% endblock %} {% block page %} - - <div class="container py-4 py-xl-5"> - <div class="row mb-5"> - <div class="col-md-8 col-xl-6 text-center mx-auto" style="background: #ffd200;"> - <h2 style="font-family: RamaGothicEW01;font-weight: bold;letter-spacing: 2px;font-size: 48px;text-shadow: 3px 3px #ffffff;color: #ff2e00;margin-bottom: 0px;">{{ product.name }}</h2> - </div> - </div> - <div> - <div class="main-yellow"> - <div> - - </div> - </div> - </div> - - <div class="row gy-4 row-cols-1 row-cols-md-1 row-cols-xl-1" style="margin-bottom: 25px;"> - <div class="col"> - <div class="card" style="border-radius: 0px;background: #ffd200;border-width: 0px;"> - <div class="fit-cover product-page-picture" style="display: inline;background: #ffffff;text-align: center;position: relative"> - <img class="fit-cover" style="height: auto;width: auto;max-height: 400px;max-width: 330px;top: 0;left: 0;bottom: 0;right: 0;margin: auto;position: absolute" src="../static/img/{{ product.shorthand }}.png"> - </div> - <div class="card-body p-4" style="text-align: center"> - <h4 class="card-title" style="font-family: RamaGothicEW01;font-weight: bold;color: #1728b8;">{{ (product.name).upper() }} - £{{ "{0:.2f}".format(product.price / 100) }}</h4> - <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">Some text about {{ product.shorthand }} yada yada yada it is awesome</p> - <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">Environmental Impact: {{ product.envImpact }}/10</p> - <div class="d-flex" style="text-align: center;"> - <div style="margin:auto;font-size: 32px"> - <label for="{{ product.shorthand }}"></label> - {% if user.is_authenticated %} - <form method='POST'> - <button class="btn btn-primary red-button" type="submit" name="product" value="{{ product.shorthand }}" style="background: #ff2e00;font-size: 28px;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> - </form> - {% else %} - <button class="btn btn-primary red-button" type="button" onclick='addToBasket("{{ product.shorthand }}", "{{ product.price }}", "")' style="background: #ff2e00;font-size: 28px;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> - {% endif %} - </div> - </div> - </div> - </div> - </div> - </div> - <div class="row gy-4 row-cols-1 row-cols-md-2 row-cols-xl-3" style="margin-bottom: 25px;"> - {% for review in product.reviews %} - <div class="col"> - <div class="card" style="border-radius: 0px;background: #ffd200;border-width: 0px;"> - <h2 style="font-family: RamaGothicEW01;margin-top:10px;text-align: center;font-weight: bold;letter-spacing: 2px;font-size: 24px;text-shadow: 3px 3px #ffffff;color: #ff2e00;margin-bottom: 0px;"> - Review By: - {% if users.query.filter_by(id=review.user_id).first() %} - {{ users.query.filter_by(id=review.user_id).first().name }} - {% endif %} - </h2> - <div class="card-body p-4"> - <h4 class="card-title" style="font-family: RamaGothicEW01;font-weight: bold;color: #1728b8;">{{ (product.name).upper() }} - £{{ "{0:.2f}".format(product.price / 100) }}</h4> - <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">Some text about {{ product.shorthand }} yada yada yada it is awesome</p> - <div class="d-flex" style="text-align: left;"> - <label for="{{ product.shorthand }}"></label> - {% if user.is_authenticated %} - <form method='POST'> - <button class="btn btn-primary red-button" type="submit" name="product" value="{{ products[0].shorthand }}" style="background: #ff2e00;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> - </form> - {% else %} - <button class="btn btn-primary red-button" type="button" onclick='addToBasket("{{ product.shorthand }}", "{{ product.price }}", "")' style="background: #ff2e00;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> - {% endif %} - <button class="btn btn-primary red-button" type="button" style="background: #ff2e00;border-style: none;width: 130px;position: absolute;right: 25px;border-radius: 0px;">VIEW ITEM <img src="../static/img/arrow_w.svg" style="width: 20%;margin-bottom: 2px;"></button> - </div> - </div> - </div> - </div> - {% endfor %} - </div> - </div> - - - - - {% for review in product.reviews %} - <li> - Review by - {% if users.query.filter_by(id=review.user_id).first() %} - {{ users.query.filter_by(id=review.user_id).first().name }} - {% endif %} - <br/> - Rating: {{ review.rating }} - <br/> - {{ review.description }} - </li> - {% endfor %} - <br/> - <form method="POST"> - <h3 align="center">Write a review:</h3> - <div class="form-group"> - <label for="rating">Rating:</label> - <input - type="rating" - class="form-control" - id="rating" - name="rating" - placeholder="Give a number to rate this product" - /> - </div> - <div class="form-group"> - <label for="review">Review:</label> - <input - type="review" - class="form-control" - id="review" - name="review" - placeholder="Write about this product" - /> - </div> - <br /> - <button type="submit" class="btn btn-primary">Submit</button> - </form> -{% endblock %} +{% extends "product.html" %} {% block title %}CREAMER{% endblock %} + +{% block description %} + NEED TO ADD SOME CREAM TO YOUR MEAL? DO YOU NOT WANT TO CONSUME MILK?<br> + WELL BOY DO WE HAVE THE PRODUCT FOR YOU!<br> + INTRODUCING ALPHAMART REAL COW DAIRY-FREE CREAMER! MADE WITH REAL COWS!<br> + NEVER HAVE A NON CREAMED DRINK EVER AGAIN!<br> + GOES ESPECIALLY WELL WITH ALPHAMART'S OFFICIAL COFFEE FROM HELL! +{% endblock %} \ No newline at end of file diff --git a/store/templates/home.html b/store/templates/home.html index d10d86f3d34b913b6891a787d3597d3fe519edd7..0fee7a58e6ee2ec5ce27891d9731bbbf9c4adf4b 100644 --- a/store/templates/home.html +++ b/store/templates/home.html @@ -60,7 +60,9 @@ {% else %} <button class="btn btn-primary red-button" type="button" onclick='addToBasket("{{ product.shorthand }}", "{{ product.price }}", "")' style="background: #ff2e00;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> {% endif %} - <button class="btn btn-primary red-button" type="button" style="background: #ff2e00;border-style: none;width: 130px;position: absolute;right: 25px;border-radius: 0px;">VIEW ITEM <img src="../static/img/arrow_w.svg" style="width: 20%;margin-bottom: 2px;"></button> + <button class="btn btn-primary red-button" onclick="location.href = '/{{ product.shorthand }}';" type="submit" style="background: #ff2e00;border-style: none;width: 130px;position: absolute;right: 25px;border-radius: 0px;"> + VIEW ITEM <img src="../static/img/arrow_w.svg" style="width: 20%;margin-bottom: 2px;"> + </button> </div> </div> </div> diff --git a/store/templates/product.html b/store/templates/product.html new file mode 100644 index 0000000000000000000000000000000000000000..67cf1383b469383a18ae8471f1d90a4c2e0736da --- /dev/null +++ b/store/templates/product.html @@ -0,0 +1,96 @@ +{% extends "base.html" %} {% block title %}PRODUCT PAGE{% endblock %} {% block page %} + + <div class="container py-4 py-xl-5"> + <div class="row mb-5"> + <div class="col-md-8 col-xl-6 text-center mx-auto" style="background: #ffd200;"> + <h2 style="font-family: RamaGothicEW01;font-weight: bold;letter-spacing: 2px;font-size: 48px;text-shadow: 3px 3px #ffffff;color: #ff2e00;margin-bottom: 0px;">{{ (product.name).upper() }}</h2> + </div> + </div> + + <div class="row gy-4 row-cols-1 row-cols-md-1 row-cols-xl-1" style="margin-bottom: 25px;"> + <div class="col"> + <div class="card" style="border-radius: 0px;background: #ffd200;border-width: 0px;"> + <div class="fit-cover product-page-picture" style="display: inline;background: #ffffff;text-align: center;position: relative"> + <img class="fit-cover" style="height: auto;width: auto;max-height: 400px;max-width: 330px;top: 0;left: 0;bottom: 0;right: 0;margin: auto;position: absolute" src="../static/img/{{ product.shorthand }}.png"> + </div> + <div class="card-body p-4" style="text-align: center"> + <h4 class="card-title" style="font-family: RamaGothicEW01;font-weight: bold;color: #1728b8;">{{ (product.name).upper() }} - £{{ "{0:.2f}".format(product.price / 100) }}</h4> + <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">{% block description %} description {% endblock %}</p> + <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">Environmental Impact: {{ product.envImpact }}/10</p> + <div class="d-flex" style="text-align: center;"> + <div style="margin-left:auto;margin-right:auto;margin-top:-50px;font-size: 32px"> + <label for="{{ product.shorthand }}"></label> + {% if user.is_authenticated %} + <form method='POST'> + <button class="btn btn-primary red-button" type="submit" name="product" value="{{ product.shorthand }}" style="background: #ff2e00;font-size: 28px;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> + </form> + {% else %} + <button class="btn btn-primary red-button" type="button" onclick='addToBasket("{{ product.shorthand }}", "{{ product.price }}", "")' style="background: #ff2e00;font-size: 28px;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;">ADD <img src="../static/img/cart_w.svg" style="width: 20%;"></button> + {% endif %} + </div> + </div> + </div> + </div> + </div> + </div> + <div class="row gy-4 row-cols-1 row-cols-md-2 row-cols-xl-3" style="margin-bottom: 25px;"> + {% for review in product.reviews %} + <div class="col"> + <div class="card" style="border-radius: 0px;background: #ffd200;border-width: 0px;"> + <h2 style="font-family: RamaGothicEW01;margin-top:10px;text-align: center;font-weight: bold;letter-spacing: 2px;font-size: 24px;text-shadow: 3px 3px #ffffff;color: #ff2e00;margin-bottom: 0px;"> + REVIEW BY: + {{ (review.user[0].username).upper() }} + </h2> + <div class="card-body p-4"> + <h4 class="card-title" style="font-family: RamaGothicEW01;font-weight: bold;color: #1728b8;">RATED: {{ review.rating }}/10</h4> + <p class="card-text" style="font-family: RamaGothicEW01;letter-spacing: 0px;font-size: 20px;">{{ (review.description).upper() }}</p> + <div class="d-flex" style="text-align: left;"> + <label for="{{ product.shorthand }}"></label> + {% if user == review.user[0] %} + <form method='POST'> + <button class="btn btn-primary red-button" type="submit" name="delete" value="delete" style="background: #ff2e00;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;margin: auto">DELETE</button> + </form> + {% endif %} + </div> + </div> + </div> + </div> + {% endfor %} + </div> + <div class="row mb-5"> + <div class="cold-md-8 cold-xl-6 text-center mx-auto" style="background: #ffd200;"> + <div style="max-width: 455px;"> + {% if user.is_authenticated %} + <form method="POST"> + <h3 align="center">Write a review:</h3> + <div class="form-group"> + <label for="rating">Rating:</label> + <input + type="rating" + class="form-control" + id="rating" + name="rating" + placeholder="Give a number to rate this product" + /> + </div> + <div class="form-group"> + <label for="review">Review:</label> + <input + type="review" + class="form-control" + id="review" + name="review" + placeholder="Write about this product" + /> + </div> + <button class="btn btn-primary red-button" type="submit" name="submit" value="submit" style="background: #ff2e00;border-radius: 0px;width: 130px;padding: 5px 5px;border-style: none;margin: auto">POST REVIEW</button> + </form> + {% else %} + {% endif %} + </div> + </div> + </div> + </div> + + +{% endblock %} diff --git a/store/views.py b/store/views.py index eec69087d356def99a89bb84bc2d7cbf2572ea05..8b727946a706196c9d290c81bb80dbf0bc5b0935 100644 --- a/store/views.py +++ b/store/views.py @@ -7,6 +7,13 @@ import json views = Blueprint('views', __name__) +def searchReviews(item): + reviews = getProducts(item)().reviews + for review in reviews: + if review.user[0] == current_user: + return True + return False + def checkItem(user, item): for basket in user.basket: @@ -65,19 +72,26 @@ def checkout(): def creamer(): if request.method == 'POST': - if request.form.values(): - if request.method == 'POST': + if request.form.get('delete'): + creamer = getCreamer() + for review in creamer.reviews: + if review.user[0] == current_user: + db.session.delete(review) + db.session.commit() + + elif request.form.values(): + + if not searchReviews(getCreamer().shorthand): rating = request.form.get('rating') description = request.form.get('review') - review = Review.query.filter_by(user_id=current_user.id).first() - - if not review: - new_review = Review(user_id=current_user.id, item_id=getCreamer().id, description=description, - rating=rating) - db.session.add(new_review) - else: - flash("You have already reviewed this product!", category='error') + creamer = getCreamer() + new_review = Review(user=[current_user], description=description, rating=rating) + creamer.reviews.append(new_review) + db.session.commit() + flash(new_review.user[0].name, category='success') + else: + flash("You have already reviewed this product!", category='error') else: product = getCreamer()