diff --git a/.gitignore b/.gitignore index 68bc17f9ff2104a9d7b6777058bb4c343ca72609..fd4a2301e0a483e835f13a3fbd6105f8216dbe96 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# Ignore VS Code specific settings. +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 80fcbec49d25b1d69c405f616d6a78aed860dc52..213382726a14a86d67cf483c293cf026ee315613 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Ensure all dependencies are installed by running the command ``pip install -r re # Project Organisattion Python has a concept of "modules" to allow the seperation of files into more manageable chunks. In this project the files are stored in a subdirectory called ``store`` meaning the files/modules inside are imported by specifying something along the lines of ``store.forms``. This keeps everything organised and seperated making it easier to work on tasks in isolation. +To ensure a consistent code style Python [black](https://pypi.org/project/black/) is used. Setup differs depending on IDE, but to set it up in VSCode do the following: +1. Go to VS Code's settings. +2. Search for "python formatting provider", and set it to "black." +3. (Optional) Search for "format on save", and enable. This will change the settings globally, not just the project. ## Static Static content, e.g. images, css, are stored in the static folder. diff --git a/run.py b/run.py index 5516c6c39469a69fa6254e0fa42bf5fca92b79c5..83d2e705885cf10dd5e4718e1072e85a337caa8f 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ from store import app -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file +if __name__ == "__main__": + app.run(debug=True) diff --git a/seed_database.py b/seed_database.py index 65311d223150224c607d6e39632526295697abe4..a1e3e03147afe051383b2adfbee2f6078c0f5447 100644 --- a/seed_database.py +++ b/seed_database.py @@ -4,58 +4,84 @@ import csv from datetime import datetime from store.models import * -items = [] # A list of items, where each item is a list that contains an id, description, price, and date sold. -with open('example_data/Online Store Project Items for Sale.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') - next(reader, None) # Skip headers +items = ( + [] +) # A list of items, where each item is a list that contains an id, description, price, and date sold. +with open( + "example_data/Online Store Project Items for Sale.csv", newline="" +) as csvfile: + reader = csv.reader(csvfile, delimiter=",", quotechar="|") + next(reader, None) # Skip headers for row in reader: items.append(row) # Add sale date to items. The CSV is in the same order as the previous. -with open('example_data/Online Store Items Sales.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') - next(reader, None) # Skip headers +with open("example_data/Online Store Items Sales.csv", newline="") as csvfile: + reader = csv.reader(csvfile, delimiter=",", quotechar="|") + next(reader, None) # Skip headers for index, row in enumerate(reader): - date = row[1] # Date is stored in the first column, zeroth column is the item ID. - if date != '': - date = datetime.strptime(date, '%d/%m/%Y').date() - items[index].append(date) # The first item in the row is the id, we want just the sale date which is in index 1. - else: # If an item is unsold it won't have a date. + date = row[ + 1 + ] # Date is stored in the first column, zeroth column is the item ID. + if date != "": + date = datetime.strptime(date, "%d/%m/%Y").date() + items[index].append( + date + ) # The first item in the row is the id, we want just the sale date which is in index 1. + else: # If an item is unsold it won't have a date. items[index].append(None) -item_sets = [] # A list of items sets, where each item set is a list that contains the set id, description, quantitity, and then a variable amount of items. -with open('example_data/Online Store Project Sets of Items for Sale.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') - next(reader, None) # Skip headers +item_sets = ( + [] +) # A list of items sets, where each item set is a list that contains the set id, description, quantitity, and then a variable amount of items. +with open( + "example_data/Online Store Project Sets of Items for Sale.csv", newline="" +) as csvfile: + reader = csv.reader(csvfile, delimiter=",", quotechar="|") + next(reader, None) # Skip headers for row in reader: item_sets.append(row) -repositories = [] # A list of repositories, where a repository is a list of item ids. -for character in ['A', 'B']: - with open(f'example_data/Online Store Project Items for Sale ALTERNATIVE SHOP {character}.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') +repositories = [] # A list of repositories, where a repository is a list of item ids. +for character in ["A", "B"]: + with open( + f"example_data/Online Store Project Items for Sale ALTERNATIVE SHOP {character}.csv", + newline="", + ) as csvfile: + reader = csv.reader(csvfile, delimiter=",", quotechar="|") repository = [] - next(reader, None) # Skip headers + next(reader, None) # Skip headers for row in reader: - repository.append(row[0]) # We only want the ID, and because csv A exists just to mess with me I have to account for an unnecesary column. + repository.append( + row[0] + ) # We only want the ID, and because csv A exists just to mess with me I have to account for an unnecesary column. repositories.append(repository) ### SEED DATABASE ### from store import db, app from store.models import Item, ItemSet, Repository, User + with app.app_context(): - db.drop_all() # Start the database anew, will completely remove existing information - db.create_all() # Will create all the tables using models.py + db.drop_all() # Start the database anew, will completely remove existing information + db.create_all() # Will create all the tables using models.py # Add admin for testing - user = User.create_user(username='admin', password='password', email='admin@website.com', phone_number='8383838', securityQ1='rainbow') - user.userType='admin' # Because of how flasks works, once a row is created it can be further altered via its objects and changes saved on db.session.commit(). + user = User.create_user( + username="admin", + password="password", + email="admin@website.com", + phone_number="8383838", + securityQ1="rainbow", + ) + user.userType = "admin" # Because of how flasks works, once a row is created it can be further altered via its objects and changes saved on db.session.commit(). # Generate item sets. This needs to come before items as some of them will be in an item set. flask_item_sets = [] for item_set in item_sets: # Items will be added to the sets later. - flask_item_set = ItemSet(id = item_set[0], description = item_set[1], price = item_set[3]) + flask_item_set = ItemSet( + id=item_set[0], description=item_set[1], price=item_set[3] + ) flask_item_sets.append(flask_item_set) # Create repositories. @@ -66,19 +92,27 @@ with app.app_context(): # Populate tables. for item in items: - flask_item = Item(id = item[0], description = item[1], price = item[2], date_sold = item[3]) # Need to create a flask Item first to add to repositories and item sets, this is what's in the master repository. - + flask_item = Item( + id=item[0], description=item[1], price=item[2], date_sold=item[3] + ) # Need to create a flask Item first to add to repositories and item sets, this is what's in the master repository. + # Initialise repositories. - for index, repository in enumerate(repositories): # We need the index so we can access the flask object representing the repository in flask_repositories. - if item[0] in repository: # Check if item ID is in repo. - flask_repositories[index].items.append(flask_item) # Add the item to the collection in repository object, creating a many to many relationship. + for index, repository in enumerate( + repositories + ): # We need the index so we can access the flask object representing the repository in flask_repositories. + if item[0] in repository: # Check if item ID is in repo. + flask_repositories[index].items.append( + flask_item + ) # Add the item to the collection in repository object, creating a many to many relationship. # Initialise item set, using mostly the same logic as the prior loop. for index, item_set in enumerate(item_sets): item_id = item[0] - item_set_ids = item_set[4:7] # Every element after index 4 is an item in item_set generated from the the csv. + item_set_ids = item_set[ + 4:7 + ] # Every element after index 4 is an item in item_set generated from the the csv. if item_id in item_set_ids: flask_item_sets[index].items.append(flask_item) db.session.add(flask_item) - db.session.commit() # Apply changes + db.session.commit() # Apply changes diff --git a/store/__init__.py b/store/__init__.py index 42924950689c5d982f8fd53fb6c4e839bee75dd7..7a6c3c75cb8f02c4e0cf03b913fd23c9a6b051b1 100644 --- a/store/__init__.py +++ b/store/__init__.py @@ -2,8 +2,10 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) -app.config['SECRET_KEY'] = 'dev' # Must be changed for production build. -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' +app.config["SECRET_KEY"] = "dev" # Must be changed for production build. +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///site.db" db = SQLAlchemy(app) -from store import routes # This is required for pages to resolve correctly, as otherwise flask does not know what to use. \ No newline at end of file +from store import ( + routes, +) # This is required for pages to resolve correctly, as otherwise flask does not know what to use. diff --git a/store/forms.py b/store/forms.py index 712ad60ada598b43267b6854c5fb6c035414f5d6..515b338da418ad71623ed8eb9d6a68075fae313f 100644 --- a/store/forms.py +++ b/store/forms.py @@ -1,4 +1,4 @@ import wtforms from flask_wtf import FlaskForm -from wtforms import StringField # Basic example. -from wtforms.validators import DataRequired # Basic example. +from wtforms import StringField # Basic example. +from wtforms.validators import DataRequired # Basic example. diff --git a/store/models.py b/store/models.py index 025907a5b5746d3ba4a2309e6c7052c6551f8dc8..b5dec8b1e0ae7881ad1cb9178be20e8ebd646813 100644 --- a/store/models.py +++ b/store/models.py @@ -1,57 +1,83 @@ # https://flask-sqlalchemy.palletsprojects.com/en/2.x/models/ -#from flask import current_app +# from flask import current_app from store import db from flask_login import UserMixin from werkzeug.security import generate_password_hash, check_password_hash # Helper tables for many to many relationships, see https://flask-sqlalchemy.palletsprojects.com/en/2.x/models/#many-to-many-relationships. -items = db.Table('Items', - db.Column('item_id', db.Integer, db.ForeignKey('item.id'), primary_key=True), - db.Column('repository_id', db.Integer, db.ForeignKey('repository.id'), primary_key=True) +items = db.Table( + "Items", + db.Column("item_id", db.Integer, db.ForeignKey("item.id"), primary_key=True), + db.Column( + "repository_id", db.Integer, db.ForeignKey("repository.id"), primary_key=True + ), ) -itemSets = db.Table('ItemSets', - db.Column('item_id', db.Integer, db.ForeignKey('item.id'), primary_key=True), - db.Column('item_set_id', db.Integer, db.ForeignKey('item_set.id'), primary_key=True) +itemSets = db.Table( + "ItemSets", + db.Column("item_id", db.Integer, db.ForeignKey("item.id"), primary_key=True), + db.Column( + "item_set_id", db.Integer, db.ForeignKey("item_set.id"), primary_key=True + ), ) -# The subset of items held by each different shop. + class Repository(db.Model): + """The subset of items held by each different shop.""" + id = db.Column(db.Integer, primary_key=True) - items = db.relationship('Item', secondary=items, lazy='subquery', - backref=db.backref('Repositories', lazy=True)) + items = db.relationship( + "Item", + secondary=items, + lazy="subquery", + backref=db.backref("Repositories", lazy=True), + ) def __repr__(self): return f"id: {self.id}, items: {self.items}" -# The master list of items for sale. + class Item(db.Model): + """The master list of items for sale.""" + id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(256), nullable=False) - price = db.Column(db.Integer, nullable=False) # In pounds, as we're not dividing or multiplying this will not matter in calculations. - date_sold = db.Column(db.Date, nullable=True) # Null if unsold. + price = db.Column( + db.Integer, nullable=False + ) # In pounds, as we're not dividing or multiplying this will not matter in calculations. + date_sold = db.Column(db.Date, nullable=True) # Null if unsold. def __repr__(self): return f"id: {self.id}, description: {self.description}, price: {self.price}, date_sold: {self.date_sold}" -# The subset of items in a collection. + class ItemSet(db.Model): + """The subset of items in a collection.""" + id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(256), nullable=False) - price = db.Column(db.Integer, nullable=False) # In pounds, as we're not dividing or multiplying this will not matter in calculations. Do we neccesarily need this? It could be calculated dynamically from the items held. - items = db.relationship('Item', secondary=itemSets, lazy='subquery', - backref=db.backref('ItemSets', lazy=True)) - + price = db.Column( + db.Integer, nullable=False + ) # In pounds, as we're not dividing or multiplying this will not matter in calculations. Do we neccesarily need this? It could be calculated dynamically from the items held. + items = db.relationship( + "Item", + secondary=itemSets, + lazy="subquery", + backref=db.backref("ItemSets", lazy=True), + ) + def __repr__(self): return f"id: {self.id}, description: {self.description}, items: {self.items}" - -# database for user register it will be added more cullomns in the future -# that is a basic implementation to check if it works -# Freddy implemented that -#UserMixin is to inherit flask-login implementetion -class User( db.Model, UserMixin): + + +class User(db.Model, UserMixin): + """database for user register it will be added more cullomns in the future + that is a basic implementation to check if it works + Freddy implemented that + UserMixin is to inherit flask-login implementetion""" + user_id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(256), nullable=False, unique=True) email = db.Column(db.String(256), nullable=False) @@ -59,16 +85,28 @@ class User( db.Model, UserMixin): password_hash = db.Column(db.String(256), nullable=False) securityQ1 = db.Column(db.String(30), nullable=False) userType = db.Column(db.String(20), default="standard") - @classmethod - def create_user(cls, username: str, password: str,email: str , phone_number: str, securityQ1 : str ) : + def create_user( + cls, + username: str, + password: str, + email: str, + phone_number: str, + securityQ1: str, + ): password_hash = generate_password_hash(password) - user = cls(username=username, password_hash= password_hash, email=email, phone_number=phone_number, securityQ1 = securityQ1) + user = cls( + username=username, + password_hash=password_hash, + email=email, + phone_number=phone_number, + securityQ1=securityQ1, + ) db.session.add(user) db.session.commit() return user - + @classmethod def update_passwords(cls, user_id: int, password: str): user = cls.query.get(user_id) @@ -81,14 +119,13 @@ class User( db.Model, UserMixin): user = cls.query.get(user_id) user.securityQ1 = securityQ1 db.session.commit() - + @classmethod def update_username(cls, user_id: int, username: str): user = cls.query.get(user_id) user.username = username db.session.commit() - @classmethod def update_email(cls, user_id: int, email: str): user = cls.query.get(user_id) @@ -102,39 +139,35 @@ class User( db.Model, UserMixin): db.session.commit() def is_active(self) -> bool: - return True - + return True def get_userDetails(self): lis = [self.username, self.email, self.phone_number] return lis - def get_id(self): return str(self.user_id) - + def check_password(self, password: str) -> bool: return check_password_hash(self.password_hash, password) - + def securityverification(self, securityQ1: str) -> bool: if self.securityQ1 == securityQ1: return True else: return False - + def checkIfUserExist(self, username: str) -> bool: if self.username == username: return True else: return False - - def __repr__(self) -> str: return f"User(user_id={self.user_id}, username='{self.username}')" - -class Adresses( db.Model): + +class Adresses(db.Model): order_id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer) country = db.Column(db.String(256), nullable=False) @@ -145,8 +178,25 @@ class Adresses( db.Model): contactEmail = db.Column(db.String(50), nullable=False) @classmethod - def create_Adresses(cls, user_id: int, country: str, homeNumber: str , streetName: str, city : str,phoneNumber : str, contactEmail : str ) : - adresses = cls(user_id=user_id, country= country, homeNumber=homeNumber, streetName=streetName, city = city, phoneNumber=phoneNumber, contactEmail = contactEmail) + def create_Adresses( + cls, + user_id: int, + country: str, + homeNumber: str, + streetName: str, + city: str, + phoneNumber: str, + contactEmail: str, + ): + adresses = cls( + user_id=user_id, + country=country, + homeNumber=homeNumber, + streetName=streetName, + city=city, + phoneNumber=phoneNumber, + contactEmail=contactEmail, + ) db.session.add(adresses) db.session.commit() - return adresses \ No newline at end of file + return adresses diff --git a/store/site.db b/store/site.db deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/store/templates/base.html b/store/templates/base.html index 33d83dad77f99d47eac4b4d62044384d8a328ae8..481bdea26646c79be9b4592dd5bf8db7038123c6 100644 --- a/store/templates/base.html +++ b/store/templates/base.html @@ -1,58 +1,61 @@ <!DOCTYPE html> <html lang="en"> + <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <title>{% block title %}{% endblock%}</title> - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"> <!-- Load the CSS. --> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"> <!-- Load the CSS. --> </head> <body> - <header class="header"> - <h1 class="logo" href="{{ url_for('index')}}">ANTIQUES ONLINE</h1> - </header> - - <nav class="navbar"> - <ul class="navbar-list"> - <li><a href="{{ url_for('basket')}}">Basket</a></li> - <li><a href="{{ url_for('items')}}">Items</a></li> - <li><a href="{{ url_for('itemSets')}}">Item Sets</a></li> - - {% if current_user.is_authenticated %} - <li><a href="{{ url_for('account')}}">Account</a></li> - <li><a href="{{ url_for('logout')}}">Logout</a></li> - <li><a class="welcome">Welcome, {{ current_user.username }}!</a></li> - {% else %} - <li><a href="{{ url_for('login')}}">Login</a></li> - <li><a href="{{ url_for('register')}}">Register</a></li> - {% endif %} - - <li class="search"> - <form> - <button type="submit"><i class="fa fa-search"></i></button> - <input type="text" placeholder="Search..."> - </form> - </li> - </ul> - </nav> - - {% with messages = get_flashed_messages() %} - {% if messages %} - <ul class="flashes"> - {% for message in messages %} - <li class="error">{{ message }}</li> - {% endfor %} - </ul> - {% endif %} - {% endwith %} - - {% block content %} - - {% endblock %} <!-- Where HTML will go when extended. --> - - <footer class="footer"> - <p>Contact Info: mail@mail.com - <br> - Phone Number 0000 000 0000</p> - </footer> + <header class="header"> + <h1 class="logo" href="{{ url_for('index')}}">ANTIQUES ONLINE</h1> + </header> + + <nav class="navbar"> + <ul class="navbar-list"> + <li><a href="{{ url_for('basket')}}">Basket</a></li> + <li><a href="{{ url_for('items')}}">Items</a></li> + <li><a href="{{ url_for('itemSets')}}">Item Sets</a></li> + + {% if current_user.is_authenticated %} + <li><a href="{{ url_for('account')}}">Account</a></li> + <li><a href="{{ url_for('logout')}}">Logout</a></li> + <li><a class="welcome">Welcome, {{ current_user.username }}!</a></li> + {% else %} + <li><a href="{{ url_for('login')}}">Login</a></li> + <li><a href="{{ url_for('register')}}">Register</a></li> + {% endif %} + + <li class="search"> + <form> + <button type="submit"><i class="fa fa-search"></i></button> + <input type="text" placeholder="Search..."> + </form> + </li> + </ul> + </nav> + + {% with messages = get_flashed_messages() %} + {% if messages %} + <ul class="flashes"> + {% for message in messages %} + <li class="error">{{ message }}</li> + {% endfor %} + </ul> + {% endif %} + {% endwith %} + + {% block content %} + + {% endblock %} <!-- Where HTML will go when extended. --> + + <footer class="footer"> + <p>Contact Info: mail@mail.com + <br> + Phone Number 0000 000 0000 + </p> + </footer> </body> -</html> + +</html> \ No newline at end of file diff --git a/store/templates/itemSets.html b/store/templates/itemSets.html index 79da0a3c35e9143448b207b73dfcd303b797d0bd..5881baed0a8a0d8d58b4cd98df9ca7e29c8fbb8c 100644 --- a/store/templates/itemSets.html +++ b/store/templates/itemSets.html @@ -3,5 +3,5 @@ {% block title %} Item Sets | Antiques Online {% endblock %} {% block content %} - + {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/ChangeEmail.html b/store/templates/userContent/ChangeEmail.html index db4e0422c9ffd20770f01b349157a35a4ab588bd..286607e15a5f3ae62959e4d623c44a6dcd9d5bea 100644 --- a/store/templates/userContent/ChangeEmail.html +++ b/store/templates/userContent/ChangeEmail.html @@ -1,28 +1,21 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Reset code {% endblock %} - - +{% block title %} Reset code {% endblock %} <form method="POST" action="{{ url_for('ChangeEmail') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Change E-mail</h1> - <div class="container"> - <h1>Change E-mail</h1> - - <label for="password"><b>Password verification</b></label> - <input type="password" placeholder="Enter Password" name="password" id="password" required> + <label for="password"><b>Password verification</b></label> + <input type="password" placeholder="Enter Password" name="password" id="password" required> - - <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> - <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <label for="NewEmail"><b>New E-mail</b></label> - <input type="NewEmail" placeholder="Enter new E-mail" name="NewEmail" id="NewEmail" required> + <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> + <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <input class="button" type="submit" value="Change E-mail" > + <label for="NewEmail"><b>New E-mail</b></label> + <input type="NewEmail" placeholder="Enter new E-mail" name="NewEmail" id="NewEmail" required> - </div> - - </form> + <input class="button" type="submit" value="Change E-mail"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/ChangePhNumber.html b/store/templates/userContent/ChangePhNumber.html index ec7cf88676b9adfe25c08ed3dafff689590db54e..ed35cc62e5f7359ea8c199afc4d45afae1ecf557 100644 --- a/store/templates/userContent/ChangePhNumber.html +++ b/store/templates/userContent/ChangePhNumber.html @@ -1,28 +1,21 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Reset code {% endblock %} - - +{% block title %} Reset code {% endblock %} <form method="POST" action="{{ url_for('ChangePhNumber') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Change Number</h1> - <div class="container"> - <h1>Change Number</h1> - - <label for="password"><b>Password verification</b></label> - <input type="password" placeholder="Enter Password" name="password" id="password" required> + <label for="password"><b>Password verification</b></label> + <input type="password" placeholder="Enter Password" name="password" id="password" required> - - <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> - <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <label for="NewNumber"><b> Enter New Number</b></label> - <input type="NewNumber" placeholder="Enter new Number" name="NewNumber" id="NewNumber" required> + <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> + <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <input class="button" type="submit" value="Change Number" > + <label for="NewNumber"><b> Enter New Number</b></label> + <input type="NewNumber" placeholder="Enter new Number" name="NewNumber" id="NewNumber" required> - </div> - - </form> + <input class="button" type="submit" value="Change Number"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/ChangeUsername.html b/store/templates/userContent/ChangeUsername.html index b2799c2121b677386685988dd62055564071350d..d576cad986a38723a3e0fa2cb1504e26c238d80c 100644 --- a/store/templates/userContent/ChangeUsername.html +++ b/store/templates/userContent/ChangeUsername.html @@ -1,28 +1,21 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Reset code {% endblock %} - - +{% block title %} Reset code {% endblock %} <form method="POST" action="{{ url_for('ChangeUsername') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Change Username</h1> - <div class="container"> - <h1>Change Username</h1> - - <label for="password"><b>Password verification</b></label> - <input type="password" placeholder="Enter Password" name="password" id="password" required> + <label for="password"><b>Password verification</b></label> + <input type="password" placeholder="Enter Password" name="password" id="password" required> - - <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> - <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <label for="NewUsername"><b>New username</b></label> - <input type="NewUsername" placeholder="Enter new Username" name="NewUsername" id="NewUsername" required> + <label for="securityQ1"><b>what is your favourite colour, for verification porpuses/b></label> + <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <input class="button" type="submit" value="Change username" > + <label for="NewUsername"><b>New username</b></label> + <input type="NewUsername" placeholder="Enter new Username" name="NewUsername" id="NewUsername" required> - </div> - - </form> + <input class="button" type="submit" value="Change username"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/account.html b/store/templates/userContent/account.html index 56425de045f39bc4dcb2b748b42ca801e21970c2..b97dd74b67fc08c52978d95a9b399f38fe9eabbe 100644 --- a/store/templates/userContent/account.html +++ b/store/templates/userContent/account.html @@ -1,12 +1,12 @@ {%extends 'base.html' %} {% block content %} - {% block title %} Account{% endblock %} - <h1>account Information</h1> - <ul> - <li><a href="{{ url_for('accountDetails', user_id=current_user.id)}}">View my Account details</a></li> - <li><a href="{{ url_for('orders', user_id=current_user.id)}}">View Orders</a></li> - <li><a href="{{ url_for('addresses', user_id=current_user.id)}}">View shipping address</a></li> - <li><a href="{{ url_for('Payment', user_id=current_user.id)}}">View your payment method</a></li> - </ul> -{% endblock %} +{% block title %} Account{% endblock %} +<h1>account Information</h1> +<ul> + <li><a href="{{ url_for('accountDetails', user_id=current_user.id)}}">View my Account details</a></li> + <li><a href="{{ url_for('orders', user_id=current_user.id)}}">View Orders</a></li> + <li><a href="{{ url_for('addresses', user_id=current_user.id)}}">View shipping address</a></li> + <li><a href="{{ url_for('Payment', user_id=current_user.id)}}">View your payment method</a></li> +</ul> +{% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/accountDetails.html b/store/templates/userContent/accountDetails.html index b0a4082b9dcec17a8fe625b3a5e1784781e31d72..b1645cb90da97e758bc3a200eb0eabf695d8df49 100644 --- a/store/templates/userContent/accountDetails.html +++ b/store/templates/userContent/accountDetails.html @@ -1,34 +1,28 @@ {%extends 'base.html' %} {% block content %} - - <h1>Account Details</h1> <h1>Welcome, {{ user.username }}</h1> <table style="width:100%"> - <tr> - <th>Your username is:</th> - <th>{{ user.username }}</th> - <th><a href="{{ url_for('ChangeUsername')}}">change your username</a></th> - - </tr> - <tr> - <td>Your email address is:</td> - <td>{{ user.email }}</td> - <td><a href="{{ url_for('ChangeEmail')}}">Change email address</a></td> - </tr> - <tr> - <th>Your Phone Number is:</th> - <td>{{ user.phone_number }}</td> - <td><a href="{{ url_for('ChangePhNumber')}}">change phone number</a></td> - </tr> - </table> - + <tr> + <th>Your username is:</th> + <th>{{ user.username }}</th> + <th><a href="{{ url_for('ChangeUsername')}}">change your username</a></th> + + </tr> + <tr> + <td>Your email address is:</td> + <td>{{ user.email }}</td> + <td><a href="{{ url_for('ChangeEmail')}}">Change email address</a></td> + </tr> + <tr> + <th>Your Phone Number is:</th> + <td>{{ user.phone_number }}</td> + <td><a href="{{ url_for('ChangePhNumber')}}">change phone number</a></td> + </tr> +</table> {% endblock %} - - - <!-- {% block title %} Account{% endblock %} <h1>Account Details</h1> diff --git a/store/templates/userContent/address.html b/store/templates/userContent/address.html index 542a90495a38726e21cafe4bfe44a20800784c1d..03936caa458eb7a2b363aa783e89cbb5d5e0936d 100644 --- a/store/templates/userContent/address.html +++ b/store/templates/userContent/address.html @@ -1,37 +1,30 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Add shipping address | Antiques Online {% endblock %} - - +{% block title %} Add shipping address | Antiques Online {% endblock %} <form method="POST" action="{{ url_for('addAdress') }}" style="float: center; text-align: center;"> - <div class="container"> - <h1>Add shipping address</h1> - - <label for="country"><b>Enter country</b></label> - <input type="country" placeholder="Enter country" value= "United Kingdom" name="country" id="country" required> - - <label for="homeNumber"><b>Enter home Number</b></label> - <input type="homeNumber" placeholder="Enter home Number" name="homeNumber" id="homeNumber" required> + <div class="container"> + <h1>Add shipping address</h1> + + <label for="country"><b>Enter country</b></label> + <input type="country" placeholder="Enter country" value="United Kingdom" name="country" id="country" required> - <label for="streetName"><b>Enter street name</b></label> - <input type="streetName" placeholder="Enter street name" name="streetName" id="streetName" required> + <label for="homeNumber"><b>Enter home Number</b></label> + <input type="homeNumber" placeholder="Enter home Number" name="homeNumber" id="homeNumber" required> - <label for="city"><b>Enter town or city </b></label> - <input type="city" placeholder="Enter town or city" name="city" id="city" required> + <label for="streetName"><b>Enter street name</b></label> + <input type="streetName" placeholder="Enter street name" name="streetName" id="streetName" required> - <label for="phoneNumber"><b>Enter phone number </b></label> - <input type="phoneNumber" placeholder="Enter phone number" value= "{{current_user.phone_number}}" name="phoneNumber" id="phoneNumber" required> + <label for="city"><b>Enter town or city </b></label> + <input type="city" placeholder="Enter town or city" name="city" id="city" required> - <label for="contactEmail"><b>Enter contact e-mail </b></label> - <input type="contactEmail" placeholder="Enter contact e-mail " value= "{{current_user.email}}" name="contactEmail" id="contactEmail" required> + <label for="phoneNumber"><b>Enter phone number </b></label> + <input type="phoneNumber" placeholder="Enter phone number" value="{{current_user.phone_number}}" name="phoneNumber" id="phoneNumber" required> - - <input class="button" type="submit" value="submit" > + <label for="contactEmail"><b>Enter contact e-mail </b></label> + <input type="contactEmail" placeholder="Enter contact e-mail " value="{{current_user.email}}" name="contactEmail" id="contactEmail" required> - </div> - - </form> + <input class="button" type="submit" value="submit"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/admin.html b/store/templates/userContent/admin.html index 164081783bdf12c550f14aa529839795b97b7b13..dec9ae5c92aafa455f90a6505556298cd575ad05 100644 --- a/store/templates/userContent/admin.html +++ b/store/templates/userContent/admin.html @@ -1,10 +1,10 @@ {%extends 'base.html' %} {% block content %} - {% block title %} Account{% endblock %} - <h1>Admin usertype account Information</h1> - <ul> - <li><a href="{{ url_for('accountDetails')}}">View my Account details</a></li> - <li><a href="{{ url_for('view_address')}}">View my shipping address</a></li> - </ul> +{% block title %} Account{% endblock %} +<h1>Admin usertype account Information</h1> +<ul> + <li><a href="{{ url_for('accountDetails')}}">View my Account details</a></li> + <li><a href="{{ url_for('view_address')}}">View my shipping address</a></li> +</ul> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/login.html b/store/templates/userContent/login.html index 3a1118bad7982f342c1d4439d8dd9439106aa6d7..77241a82029f45277a52d073336676476f48c132 100644 --- a/store/templates/userContent/login.html +++ b/store/templates/userContent/login.html @@ -1,41 +1,34 @@ - - {%extends 'base.html' %} {% block title %} Login | Antiques Online {% endblock %} {% block content %} - <form method="POST" action="{{ url_for('login') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Login</h1> + <table class="loginTable"> + <tr> + <td><label for="username">Username</label></td> + <td><input type="username" placeholder="Enter Username..." name="username" id="username" required></td> + </tr> + <tr> + <td><label for="password">Password</label></td> + <td><input type="password" placeholder="Enter Password..." name="password" id="password" required></td> + </tr> + <tr> + <td><label for="securityQ1">Favourite Colour</label></td> + <td><input type="securityQ1" placeholder="Enter Favourite Colour..." name="securityQ1" id="securityQ1" required> + </td> + </tr> + <tr> + <td></td> + <td><a href="{{ url_for('reset_password')}}">I Forgot my Password!</a></td> + </tr> + <tr> + <td></td> + <td><a href="{{ url_for('reset_security1')}}">I Forgot my Favourite Color!</a></td> + </tr> + </table> - <div class="container"> - <h1>Login</h1> - <table class="loginTable"> - <tr> - <td><label for="username">Username</label></td> - <td><input type="username" placeholder="Enter Username..." name="username" id="username" required></td> - </tr> - <tr> - <td><label for="password">Password</label></td> - <td><input type="password" placeholder="Enter Password..." name="password" id="password" required></td> - </tr> - <tr> - <td><label for="securityQ1">Favourite Colour</label></td> - <td><input type="securityQ1" placeholder="Enter Favourite Colour..." name="securityQ1" id="securityQ1" required></td> - </tr> - <tr> - <td></td> - <td><a href="{{ url_for('reset_password')}}">I Forgot my Password!</a></td> - </tr> - <tr> - <td></td> - <td><a href="{{ url_for('reset_security1')}}">I Forgot my Favourite Color!</a></td> - </tr> - </table> - - <input class="button" type="submit" value="Login" > - - </div> - - - - </form> + <input class="button" type="submit" value="Login"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/register.html b/store/templates/userContent/register.html index 525ee6119def1483972b219cb88af99b72f5d2e3..e4cca00426c38740b655c7aa2681eb1cf2d71a97 100644 --- a/store/templates/userContent/register.html +++ b/store/templates/userContent/register.html @@ -1,43 +1,39 @@ {%extends 'base.html' %} {% block title %} Register | Antiques Online {% endblock %} {% block content %} - <form method="POST" action="{{ url_for('register') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Register</h1> - <div class="container"> - - <h1>Register</h1> - - {% if error %} - <p class=error><strong>Error:</strong> {{ error }} + {% if error %} + <p class=error><strong>Error:</strong> {{ error }} {% endif %} - - <table class="loginTable"> - <tr> - <td><label for="username">Username:</label></td> - <td><input type="username" placeholder="Enter Username..." name="username" id="username" required></td> - </tr> - <tr> - <td><label for="email">E-mail Address:</label></td> - <td><input type="email" placeholder="Enter E-mail..." name="email" id="email" required></td> - </tr> - <tr> - <td><label for="phone_number">Phone Number:</label></td> - <td><input type="phone_number" placeholder="Enter Phone Number..." name="phone_number" id="phone_number" required></td> - </tr> - <tr> - <td><label for="securityQ1">Favourite Color:</label></td> - <td><input type="securityQ1" placeholder="Enter a Colour..." name="securityQ1" id="securityQ1" required></td> - </tr> - <tr> - <td><label for="password">Password:</label></td> - <td><input type="password" placeholder="Enter Password..." name="password" id="password" required></td> - </tr> - </table> - - <input class="button" type="submit" value="Register" > - </div> - - </form> + <table class="loginTable"> + <tr> + <td><label for="username">Username:</label></td> + <td><input type="username" placeholder="Enter Username..." name="username" id="username" required></td> + </tr> + <tr> + <td><label for="email">E-mail Address:</label></td> + <td><input type="email" placeholder="Enter E-mail..." name="email" id="email" required></td> + </tr> + <tr> + <td><label for="phone_number">Phone Number:</label></td> + <td><input type="phone_number" placeholder="Enter Phone Number..." name="phone_number" id="phone_number" + required></td> + </tr> + <tr> + <td><label for="securityQ1">Favourite Color:</label></td> + <td><input type="securityQ1" placeholder="Enter a Colour..." name="securityQ1" id="securityQ1" required></td> + </tr> + <tr> + <td><label for="password">Password:</label></td> + <td><input type="password" placeholder="Enter Password..." name="password" id="password" required></td> + </tr> + </table> + + <input class="button" type="submit" value="Register"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/reset_password.html b/store/templates/userContent/reset_password.html index 74f003d0f5c6614adfb87e028cebb4fcdc7fac22..c0e144aeb32890ce14000c12a23f1aa162576f9f 100644 --- a/store/templates/userContent/reset_password.html +++ b/store/templates/userContent/reset_password.html @@ -1,21 +1,14 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Reset code {% endblock %} - - +{% block title %} Reset code {% endblock %} <form method="POST" action="{{ url_for('reset_password') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>email verify</h1> - <div class="container"> - <h1>email verify</h1> - - <label for="email"><b>Enter your email</b></label> - <input type="email" placeholder="Enter your email" name="email" id="email" required> - - <input class="button" type="submit" value="Reset Password" > + <label for="email"><b>Enter your email</b></label> + <input type="email" placeholder="Enter your email" name="email" id="email" required> - </div> - - </form> + <input class="button" type="submit" value="Reset Password"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/reset_password_confirm.html b/store/templates/userContent/reset_password_confirm.html index 72ece7e626eef6394d74583945a70ffa0661b74d..4cd7a4cdc196b75a303950384175cab8edd6337d 100644 --- a/store/templates/userContent/reset_password_confirm.html +++ b/store/templates/userContent/reset_password_confirm.html @@ -1,26 +1,18 @@ - {%extends 'base.html' %} {% block content %} - {% block title %} Verify reset Password {% endblock %} - - - <form method="POST" action="{{ url_for('reset_password_confirm') }}" style="float: center; text-align: center;"> +{% block title %} Verify reset Password {% endblock %} +<form method="POST" action="{{ url_for('reset_password_confirm') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Reset Password</h1> - <div class="container"> - - <h1>Reset Password</h1> - - - <label for="password"><b>Password</b></label> - <input type="password" placeholder="Enter Password" name="password" id="password" required> + <label for="password"><b>Password</b></label> + <input type="password" placeholder="Enter Password" name="password" id="password" required> - - <label for="confirm_password"><b>confirm password</b></label> - <input type="confirm_password" placeholder="confirm password" name="confirm_password" id="confirm_password" required> + <label for="confirm_password"><b>confirm password</b></label> + <input type="confirm_password" placeholder="confirm password" name="confirm_password" id="confirm_password" + required> - <input class="button" type="submit" value="confirm password" > - - </div> - - </form> + <input class="button" type="submit" value="confirm password"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/reset_security1.html b/store/templates/userContent/reset_security1.html index 0e723fe8c5b7cbf4d3c2934f06d5037341c85084..fd2bacaf68adddb347b6ec49ff166bd7e778f02f 100644 --- a/store/templates/userContent/reset_security1.html +++ b/store/templates/userContent/reset_security1.html @@ -1,21 +1,14 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Reset code {% endblock %} - - +{% block title %} Reset code {% endblock %} <form method="POST" action="{{ url_for('reset_security1') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>email verify</h1> - <div class="container"> - <h1>email verify</h1> - - <label for="email"><b>Enter your email</b></label> - <input type="email" placeholder="Enter your email" name="email" id="email" required> - - <input class="button" type="submit" value="Reset security answer" > + <label for="email"><b>Enter your email</b></label> + <input type="email" placeholder="Enter your email" name="email" id="email" required> - </div> - - </form> + <input class="button" type="submit" value="Reset security answer"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/user.html b/store/templates/userContent/user.html index c4bf183b1831e148004d5f3724cd2f685fe44bfa..eff6f6a4e4f1f2b5560892c22b8d9dfa49a26855 100644 --- a/store/templates/userContent/user.html +++ b/store/templates/userContent/user.html @@ -1,10 +1,9 @@ {%extends 'base.html' %} - {% block content %} - {% block title %} Account{% endblock %} - <h1>Standard usertype account Information</h1> - <ul> - <li><a href="{{ url_for('accountDetails', user_id=current_user.id)}}">View my Account details</a></li> - <li><a href="{{ url_for('addAdress', user_id=current_user.id)}}">Add shipping address</a></li> - </ul> -{% endblock %} +{% block title %} Account{% endblock %} +<h1>Standard usertype account Information</h1> +<ul> + <li><a href="{{ url_for('accountDetails', user_id=current_user.id)}}">View my Account details</a></li> + <li><a href="{{ url_for('addAdress', user_id=current_user.id)}}">Add shipping address</a></li> +</ul> +{% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/verify_code.html b/store/templates/userContent/verify_code.html index 8022e304107099c7cc09f1ed38b5a652e99f9c61..bc1214ed594c1bfbc4bab1a918bf3e23d7dc8baa 100644 --- a/store/templates/userContent/verify_code.html +++ b/store/templates/userContent/verify_code.html @@ -1,21 +1,15 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Verify reset Password {% endblock %} - - +{% block title %} Verify reset Password {% endblock %} <form method="POST" action="{{ url_for('verify_code') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Login</h1> - <div class="container"> - <h1>Login</h1> - - <label for="verification_code"><b>Enter your code </b></label> - <input type="verification_code" placeholder="Enter your code " name="verification_code" id="verification_code" required> - - <input class="button" type="submit" value="Reset Password" > + <label for="verification_code"><b>Enter your code </b></label> + <input type="verification_code" placeholder="Enter your code " name="verification_code" id="verification_code" + required> - </div> - - </form> + <input class="button" type="submit" value="Reset Password"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/verify_code_security1.html b/store/templates/userContent/verify_code_security1.html index 094a2fcc177eb802f7465f495a8d9a0e4136fd5a..c54d763fadff499f70aec951d63044cf4536d79b 100644 --- a/store/templates/userContent/verify_code_security1.html +++ b/store/templates/userContent/verify_code_security1.html @@ -1,21 +1,15 @@ - - {%extends 'base.html' %} {% block content %} - {% block title %} Verify reset Password {% endblock %} - - +{% block title %} Verify reset Password {% endblock %} <form method="POST" action="{{ url_for('verify_code_security1') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Reset security answer</h1> - <div class="container"> - <h1>Reset security answer</h1> - - <label for="verification_code"><b>Enter your code </b></label> - <input type="verification_code" placeholder="Enter your code " name="verification_code" id="verification_code" required> - - <input class="button" type="submit" value="Reset security answer" > + <label for="verification_code"><b>Enter your code </b></label> + <input type="verification_code" placeholder="Enter your code " name="verification_code" id="verification_code" + required> - </div> - - </form> + <input class="button" type="submit" value="Reset security answer"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/verify_code_security1_confirm.html b/store/templates/userContent/verify_code_security1_confirm.html index dc526cdbdfc15f30f5f49b8b4f53b71f4d51c45a..c3f5889fbbf3b5b3a90e2705f7a9651c4d19252a 100644 --- a/store/templates/userContent/verify_code_security1_confirm.html +++ b/store/templates/userContent/verify_code_security1_confirm.html @@ -1,26 +1,20 @@ - {%extends 'base.html' %} {% block content %} - {% block title %} Verify reset Password {% endblock %} +{% block title %} Verify reset Password {% endblock %} +<form method="POST" action="{{ url_for('verify_code_security1_confirm') }}" style="float: center; text-align: center;"> + <div class="container"> + <h1>Reset security question</h1> + - - <form method="POST" action="{{ url_for('verify_code_security1_confirm') }}" style="float: center; text-align: center;"> + <label for="securityQ1"><b>what is your favourite colour</b></label> + <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - <div class="container"> - - <h1>Reset security question</h1> - - - <label for="securityQ1"><b>what is your favourite colour</b></label> - <input type="securityQ1" placeholder="Enter a colour" name="securityQ1" id="securityQ1" required> - - <label for="confirm_securityQ1"><b>confirm answer</b></label> - <input type="confirm_securityQ1" placeholder="confirm answer" name="confirm_securityQ1" id="confirm_securityQ1" required> + <label for="confirm_securityQ1"><b>confirm answer</b></label> + <input type="confirm_securityQ1" placeholder="confirm answer" name="confirm_securityQ1" id="confirm_securityQ1" + required> - <input class="button" type="submit" value="confirm password" > - - </div> - - </form> + <input class="button" type="submit" value="confirm password"> + </div> +</form> {% endblock %} \ No newline at end of file diff --git a/store/templates/userContent/view_address.html b/store/templates/userContent/view_address.html index 3abc3f25a6485c83f90e71cb5b755c432d493a6b..30edd8286ffaf775d1cf69f3b42232973166d25d 100644 --- a/store/templates/userContent/view_address.html +++ b/store/templates/userContent/view_address.html @@ -1,27 +1,26 @@ {% extends 'base.html' %} - {% block content %} - <h1>Saved Addresses</h1> - <table class="table"> - <thead> - <tr> - <th>Street</th> - <th>City</th> - <th>State</th> - <th>Postal Code</th> - <th>Country</th> - </tr> - </thead> - <tbody> - {% for address in addresses %} - <tr> - <td>{{ address.street }}</td> - <td>{{ address.city }}</td> - <td>{{ address.state }}</td> - <td>{{ address.postal_code }}</td> - <td>{{ address.country }}</td> - </tr> - {% endfor %} - </tbody> - </table> +<h1>Saved Addresses</h1> +<table class="table"> + <thead> + <tr> + <th>Street</th> + <th>City</th> + <th>State</th> + <th>Postal Code</th> + <th>Country</th> + </tr> + </thead> + <tbody> + {% for address in addresses %} + <tr> + <td>{{ address.street }}</td> + <td>{{ address.city }}</td> + <td>{{ address.state }}</td> + <td>{{ address.postal_code }}</td> + <td>{{ address.country }}</td> + </tr> + {% endfor %} + </tbody> +</table> {% endblock %} \ No newline at end of file diff --git a/store/utility.py b/store/utility.py index c906accb867c6bfeb7c4c5ebf77ff9eda1cc0184..7a6ed88685c0fffeba8e96594678dc7cb4b025b5 100644 --- a/store/utility.py +++ b/store/utility.py @@ -23,20 +23,24 @@ def get_sold_items(): def get_items(): return Item.query.all() + def get_item_by_id(item_id): item = Item.query.get(item_id) if item is not None: return item else: - #TODO error handling + # TODO error handling pass def get_item_sets(): return ItemSet.query.all() + def add_similar_item_to_set(nothing): pass + + # Search the description of all items to find similar. # This is intended for use in replacing items in an items, # and works best when description is close to the target. @@ -48,8 +52,13 @@ def get_similar_items(description): found = [] for descriptable in to_search: # This relies on the fact both Item and Items sets have a description column. - if (SequenceMatcher(None, description.lower(), descriptable.description.lower()).ratio() > 0.4 # This ratio comparison needs to be fine tuned. - and descriptable.date_sold == None): + if ( + SequenceMatcher( + None, description.lower(), descriptable.description.lower() + ).ratio() + > 0.4 # This ratio comparison needs to be fine tuned. + and descriptable.date_sold == None + ): found.append(descriptable) return found @@ -65,6 +74,7 @@ def remove_item(item): # get_similar_items() # TODO: Need to get Item object to pass to add similar item to set # db.session.Item.query() + # Search desciption for matching substring. # This is most useful for a user keyword search. def get_by_keyword(substring): @@ -75,6 +85,7 @@ def get_by_keyword(substring): found.append(descriptable) return found + # Search desciption for matching substring. # This is most useful for a user keyword search. @@ -113,6 +124,3 @@ def add_item(description, price, date_sold=None): item = Item(description=description, price=price, date_sold=date_sold) db.session.add(item) db.session.commit() - - - diff --git a/unit_tests.py b/unit_tests.py index c710ce22671ec79e6b290c143fc05a39768cdba0..07818c5eaf548ae67cabb496f0c833c6ac95be87 100644 --- a/unit_tests.py +++ b/unit_tests.py @@ -1,4 +1,5 @@ from store import app + # An instance of the database needs to exist to unit test, # as the database is seeded from file this can be used as a test database. # It would probably be best to create a variant of it here, but for now @@ -54,15 +55,16 @@ class TestUtility(unittest.TestCase): def test_get_similar_items(self): results = get_similar_items("Chinese Porcelaine Vases set") is_search_too_wide = any( - "chinese" not in descriptable.description.lower() for descriptable in results) + "chinese" not in descriptable.description.lower() + for descriptable in results + ) self.assertEqual(len(results) > 0 and not is_search_too_wide, True) def add_item_to_database(self): item = ["Vase with golden trimming", 12] add_item(item[0], item[1]) - added_item = Item.query.filter_by( - description="Vase with golden trimming").all() + added_item = Item.query.filter_by(description="Vase with golden trimming").all() self.assertEqual(item[0], added_item.description)