Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
893e653
testing
JodyBroad Apr 13, 2022
5af0a73
update SQL table to team_yellow
JodyBroad Apr 15, 2022
2bbd898
add bootstrap and basic nav to layout, set home and about to extend f…
JodyBroad Apr 15, 2022
d42ef73
html pages added, css styling still needed for each individual page
Jodie-Smith Apr 15, 2022
1b91266
responsive navigation
JodyBroad Apr 15, 2022
2266ee1
Merge pull request #1 from JodyBroad/responsive_navigation
JodyBroad Apr 17, 2022
6695bc9
add crytography to requirements.txt
JodyBroad Apr 17, 2022
2b4ede7
updated comment
JodyBroad Apr 17, 2022
d5897e5
Merge pull request #2 from JodyBroad/intial_models
JodyBroad Apr 17, 2022
6e338ee
add models and one create statement to test model functionality
JodyBroad Apr 17, 2022
29e6d2e
Merge pull request #3 from JodyBroad/initial_models
JodyBroad Apr 18, 2022
5f72bb1
forms added for registration, login, staff login, plant submit, regis…
Jodie-Smith Apr 18, 2022
4d3c45b
data
Apr 18, 2022
0b22f04
Merge pull request #4 from JodyBroad/create_data
nyedun22 Apr 18, 2022
32e9e46
basic forms added, will try to add validation
Jodie-Smith Apr 18, 2022
00e6129
Merge pull request #5 from JodyBroad/forms
Jodie-Smith Apr 18, 2022
6a2ffa4
changes to routes and html files
Apr 19, 2022
4d834b8
Tuesdays updates
Apr 19, 2022
0ca44d9
Merge pull request #6 from JodyBroad/routes_update
isabeltulloch Apr 19, 2022
9b6493a
changed background colour
Apr 20, 2022
610cb85
Merge pull request #7 from JodyBroad/initial_css
nyedun22 Apr 20, 2022
01c4ada
restructured database, models, create working
JodyBroad Apr 20, 2022
c41b375
Merge pull request #8 from JodyBroad/db_restructure
JodyBroad Apr 20, 2022
e5bd3bf
added newsletter sign up table and fixed dates on orderheader
JodyBroad Apr 21, 2022
f034797
add staff info table with job title and date of birth
JodyBroad Apr 21, 2022
6773c77
add blog posts table and some initial content
JodyBroad Apr 21, 2022
7f170c6
email signup form on home page now functional
JodyBroad Apr 21, 2022
8aaf8c0
customer registration form almost functional
JodyBroad Apr 21, 2022
ff09df1
register new staff almost functional
JodyBroad Apr 21, 2022
a77e902
adding product photos for plant pages 5-10 to images folder
JodyBroad Apr 21, 2022
1792fa7
Merge pull request #9 from JodyBroad/forms_routes_fix
JodyBroad Apr 21, 2022
4fb593f
registration forms fixed
Apr 21, 2022
5e48f72
plant form updates
Apr 21, 2022
2be34fc
Merge pull request #11 from JodyBroad/plant_forms
isabeltulloch Apr 21, 2022
4783c0d
initial validation commit
Jodie-Smith Apr 22, 2022
2a84a19
added some bootstrap to registration, still cannot get email and conf…
Jodie-Smith Apr 22, 2022
1b74dfe
staff register bootstrap added and flash message
Jodie-Smith Apr 22, 2022
0ff7f36
plant form validations added
Jodie-Smith Apr 22, 2022
f7fa682
plant name field removed from form
Jodie-Smith Apr 22, 2022
b46fd0d
css minor change
Jodie-Smith Apr 22, 2022
19c3cb1
comments added to explain things that are still not working, however,…
Jodie-Smith Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if __name__ == '__main__':
# app.run(debug=True, host='0.0.0.0')
app.run(debug=True)
app.run(debug=True, port=5001)


# mvc Model View Controller
Expand Down
Binary file added application/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Object is Python classes
# Relational is MySQL
# SQLAlchemy is the MAPPING layer between them
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:password@localhost/flask_team_a"
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:@localhost/team_yellow"
# app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://username:password@host/database_name"
# app.config['SQLALCHEMY_DATABASE_URI']=('mysql+pymysql://' + getenv('MYSQL_USER') + ':' + getenv('MYSQL_PASSWORD') + '@' + getenv('MYSQL_HOST') + '/' + getenv('MYSQL_DB'))
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
Expand Down
203 changes: 188 additions & 15 deletions application/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,204 @@
# the database
# NOTE! The database MUST exist before we try to connect to it

# add one extra table for newsletter signup - just email

from application import db
from application.models import Person, Car
# from application.models import Person, Car # Victoria's code
from application.models import BlogPosts, Newsletter, PersonType, UserLogin, Address, StaffInfo, Person, OrderStatus, \
Category, PlantType, Size,\
Product, OrderHeader, OrderLine

# Staff,Customer,
# these are the 12 tables we want to create in order:
# PersonType, UserLogin, Address, Person, OrderStatus, Category, PlantType, Size, Product,
# OrderHeader, OrderLine

# create our database schema
# db.create_all()

db.drop_all()
db.create_all()

testPerson1 = Person(first_name='Julie',last_name='Dooley')
testPerson2 = Person(first_name='Victoria',last_name='Lloyd')
# will need to use the db.session.add() code below to add the data - use lists as Victoria has below to make it easier?
# then need db.session.commit() to actually save it to the database
# once this code is populated, running it seperately should make everything appear in the database!


# Blogposts table
blog1 = BlogPosts(author='The Plant Doctor', date_posted='2022-01-01', title='Welcome', post_content='Hi, we are the '
'Plant Emporium, what an exciting time to be alive')
blog2 = BlogPosts(author='Master of the Retail Outlet', date_posted='2022-01-10', title='Exciting News', post_content='The shop is now officially open! Come and see us to get your plant fix, we have some gorgeous stock and are happy to help you choose')
blog3 = BlogPosts(author='The Plant Doctor', date_posted='2022-01-10', title='Plant Clinic', post_content='We are now going to be running Sad Plant Fridays - post your ailing plants to Twitter #SadPlantFridays or email us at jody@theplantemporium.com and our resident Plant Doctor will diagnose the issue and more importantly, offer a solution!')
blogs = [blog1, blog2, blog3]

# Newsletter signup table
news1 = Newsletter(newsletter_email='ted.lasso@afc_richmond.co.uk')
news2 = Newsletter(newsletter_email='rebecca_welton@gmail.com')
news3 = Newsletter(newsletter_email='keeley_jones@gmail.com')
news4 = Newsletter(newsletter_email='roy.kent@afc_richmond.co.uk')
news5 = Newsletter(newsletter_email='sam.obisanya@afc_richmond.co.uk')
news = [news1, news2, news3, news4, news5]

# PersonType table
person_type1 = PersonType(person_type_description='Staff')
person_type2 = PersonType(person_type_description='Customer')
person_types = [person_type1, person_type2]

# user login without person type
user1 = UserLogin(username='tedlikesplants', password='1buyingaPLANT!')
user2 = UserLogin(username='rebecca_w', password='Panda42')
user3 = UserLogin(username='keeley.jones', password='passworDx4')
user4 = UserLogin(username='roy.kent', password='Richmond12')
user5 = UserLogin(username='sam_obisanya', password='FootballandPlants1')
user6 = UserLogin(username='natasha', password='staffaccess4')
user7 = UserLogin(username='jodie', password='staffaccess4')
user8 = UserLogin(username='jody', password='staffaccess4')
user9 = UserLogin(username='isabel', password='staffaccess4')
users = [user1, user2, user3, user4, user5, user6, user7, user8, user9]


# address table
address1 = Address(address_line_one='AFC Richmond Club House', address_line_two='Nelson Road',
address_line_three='London', postcode='TW9 4RP')
address2 = Address(address_line_one='49 Kings Road', address_line_two='Chelsea', address_line_three='London',
postcode='SW3 5TT')
address3 = Address(address_line_one='4 Portland Terrace', address_line_two='The Green', address_line_three='Richmond',
postcode='TW9 1QQ')
address4 = Address(address_line_one='The Plant Emporium', address_line_two='Sky Studios', postcode='TW7 5QD')
addresses = [address1, address2, address3, address4]


# staff info table
staff1 = StaffInfo(job_title='Plant purchaser', date_of_birth='1994-06-23')
staff2 = StaffInfo(job_title='Website wrangler', date_of_birth='1998-09-12')
staff3 = StaffInfo(job_title='Plant doctor', date_of_birth='1984-05-26')
staff4 = StaffInfo(job_title='Master of the retail outlet', date_of_birth='1999-08-16')
staff = [staff1, staff2, staff3, staff4]

# person table
person1 = Person(first_name='Ted', last_name='Lasso', email='ted.lasso@afc_richmond.co.uk', address_id=1,
phone_number='07384957162', user_login_id=1, person_type_id=2)
person2 = Person(first_name='Rebecca', last_name='Welton', email='rebecca_welton@gmail.com', address_id=1,
phone_number='07492750173', user_login_id=2, person_type_id=2)
person3 = Person(first_name='Keeley', last_name='Jones', email='keeley_jones@gmail.com', address_id=2,
phone_number='07553630090', user_login_id=3, person_type_id=2)
person4 = Person(first_name='Roy', last_name='Kent', email='roy.kent@afc_richmond.co.uk', address_id=3,
phone_number='07554124856', user_login_id=4, person_type_id=2)
person5 = Person(first_name='Sam', last_name='Obisanya', email='sam.obisanya@afc_richmond.co.uk', address_id=1,
phone_number='07889578112', user_login_id=5, person_type_id=2)
person6 = Person(first_name='Natasha', last_name='Edun', email='natasha@plantemporium.com', address_id=4,
phone_number='07777777777',user_login_id=6, person_type_id=1, staff_info_id=1)
person7 = Person(first_name='Jodie', last_name='Smith', email='jodie@plantemporium.com', address_id=4,
phone_number='07777777777', user_login_id=7, person_type_id=1, staff_info_id=2)
person8 = Person(first_name='Jody', last_name='Broad', email='jody@plantemporium.com', address_id=4,
phone_number='07777777777', user_login_id=8, person_type_id=1, staff_info_id=3)
person9 = Person(first_name='Isabel', last_name='Tulloch', email='isabel@plantemporium.com', address_id=4,
phone_number='07777777777', user_login_id=9, person_type_id=1, staff_info_id=4)
persons = [person1, person2, person3, person4, person5, person6, person7, person8, person9]


# order status
status1 = OrderStatus(status_description='Ordered')
status2 = OrderStatus(status_description='Processing')
status3 = OrderStatus(status_description='Shipped')
status4 = OrderStatus(status_description='Collected')
status5 = OrderStatus(status_description='Returned')
status = [status1, status2, status3, status4, status5]

car1 = Car(number_plate='JU21DOO', person_id=1, colour='Red', make="Ferrari", model='V12')
car2 = Car(number_plate='JU20XXX', person_id=1, colour='Black', make="Mercedes-Benz", model='CLS')
car3 = Car(number_plate='VL21LLO', person_id=2, colour='Grey', make="Ford", model='Focus')

cars = [car1, car2, car3]
# car4 = Car(number_plate='BART21', person_id=3)
# category
category1 = Category(category_description='Indoor')
category2 = Category(category_description='Outdoor')
categories = [category1, category2]


# plant type table
plant1 = PlantType(plant_type_description='Cacti/Succulent')
plant2 = PlantType(plant_type_description='Hanging')
plant3 = PlantType(plant_type_description='Flowering')
plant4 = PlantType(plant_type_description='Palms')
plant5 = PlantType(plant_type_description='Ferns')
plant_types = [plant1, plant2, plant3, plant4, plant5]


# size
size1 = Size(size_description='Tiny')
size2 = Size(size_description='Small')
size3 = Size(size_description='Medium')
size4 = Size(size_description='Tall')
sizes = [size1, size2, size3, size4]

# product table
product1 = Product(species='Boston Fern', price=12, stock=8, category_id=1, plant_type_id=5, size_id=1)
product2 = Product(species='Aloe Vera', price=4, stock=10, category_id=1, plant_type_id=1, size_id=2)
product3 = Product(species='Parlour Palm', price=8.99, stock=3, category_id=1, plant_type_id=4, size_id=2)
product4 = Product(species='Anthurium', price=20, stock=5, category_id=1, plant_type_id=3, size_id=3)
product5 = Product(species='Swiss Cheese Plant', price=85.5, stock=1, category_id=1, plant_type_id=4, size_id=4)
product6 = Product(species='Sweet Orange Tree', price=65, stock=4, category_id=2, plant_type_id=3, size_id=4)
product7 = Product(species='Climbing Rose', price=30, stock=3, category_id=2, plant_type_id=3, size_id=3)
product8 = Product(species='Fatsia Japonica', price=55, stock=2, category_id=2, plant_type_id=5, size_id=3)
product9 = Product(species='Hydrangea Macrophylla', price=29.99, stock=5, category_id=2, plant_type_id=4, size_id=2)
product10 = Product(species='Alstroemeria', price=27, stock=8, category_id=2, plant_type_id=4, size_id=1)
products = [product1, product2, product3, product4, product5, product6, product7, product8, product9, product10]


# OrderHeader linking to person only (as customer)
order1 = OrderHeader(person_id=1, order_date='2022-04-09', status_id=1, total_cost=54.00)
order2 = OrderHeader(person_id=2, order_date='2022-04-10', status_id=4, total_cost=26.97)
order3 = OrderHeader(person_id=3, order_date='2022-04-12', status_id=3, total_cost=197.97)
order4 = OrderHeader(person_id=4, order_date='2022-04-16', status_id=4, total_cost=20.00)
order5 = OrderHeader(person_id=1, order_date='2022-04-19', status_id=4, total_cost=195.00)
plant_orders = [order1, order2, order3, order4, order5]


# orderLine
order_line1 = OrderLine(order_header_id=1, product_id=10, quantity=2, price_paid=54.00)
order_line2 = OrderLine(order_header_id=2, product_id=3, quantity=1, price_paid=26.97)
order_line3 = OrderLine(order_header_id=3, product_id=5, quantity=2, price_paid=171.00)
order_line4 = OrderLine(order_header_id=3, product_id=4, quantity=4, price_paid=80.00)
order_line5 = OrderLine(order_header_id=4, product_id=2, quantity=2, price_paid=8.00)
order_line6 = OrderLine(order_header_id=4, product_id=1, quantity=1, price_paid=12.00)
order_line7 = OrderLine(order_header_id=5, product_id=6, quantity=3, price_paid=195.00)
order_lines = [order_line1, order_line2, order_line3, order_line4, order_line5, order_line6, order_line7]

db.session.add_all(blogs)
db.session.add_all(news)
db.session.add_all(person_types)
db.session.add_all(users)
db.session.add_all(addresses)
db.session.add_all(staff)
db.session.add_all(persons)
db.session.add_all(status)
db.session.add_all(categories)
db.session.add_all(plant_types)
db.session.add_all(sizes)
db.session.add_all(products)
db.session.add_all(plant_orders)
db.session.add_all(order_lines)


db.session.add(testPerson1)
db.session.add(testPerson2)
# db.session.add(car1)
# db.session.add(car2)
# db.session.add(car3)

db.session.add_all(cars)
# db.session.add(car4)
db.session.commit()

# Victoria's Code:

# testPerson1 = Person(first_name='Julie', last_name='Dooley')
# testPerson2 = Person(first_name='Victoria', last_name='Lloyd')
#
# car1 = Car(number_plate='JU21DOO', person_id=1, colour='Red', make="Ferrari", model='V12')
# car2 = Car(number_plate='JU20XXX', person_id=1, colour='Black', make="Mercedes-Benz", model='CLS')
# car3 = Car(number_plate='VL21LLO', person_id=2, colour='Grey', make="Ford", model='Focus')
#
# cars = [car1, car2, car3]
# # car4 = Car(number_plate='BART21', person_id=3)
#
# db.session.add(testPerson1)
# db.session.add(testPerson2)
# # db.session.add(car1)
# # db.session.add(car2)
# # db.session.add(car3)
#
# db.session.add_all(cars)
# # db.session.add(car4)
# db.session.commit()
116 changes: 115 additions & 1 deletion application/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,121 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms import StringField, SubmitField, PasswordField, BooleanField, DateField, IntegerField, SelectField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError, input_required

# need form to do email newsletter sign up

class EmailSignUpForm(FlaskForm):
email = StringField('Email')
submit = SubmitField('Sign Up')


# new form needs to link to userlogin person and address tables for registering customers (is set in the route to set the
# persontype to '2' which is customer
class CustomerRegistrationForm(FlaskForm):
# userlogin elements
username = StringField('Username', validators=[DataRequired(), Length(min=2, max=30)])
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('confirm_password', message="Passwords must match")]) #Equal to validator not working, will still submit even if passwords do not match

# person elements
first_name = StringField('First Name', validators=[DataRequired(), Length(min=2, max=30)])
last_name = StringField('Last Name', validators=[DataRequired(), Length(min=2, max=30)])
email = StringField('Email', validators=[DataRequired(), Email(message='Please supply a valid email')]) #email validator not working, form will still submit even if no @ or . is present in field.

# address elements
address_line_one = StringField('Address Line 1', validators=[DataRequired()])
address_line_two = StringField('Address Line 2')
address_line_three = StringField('Address Line 3')
postcode = StringField('Postcode', validators=[DataRequired()])
phone_number = StringField('Phone Number')
# submit
submit = SubmitField('Sign Up')

# Custom error created to raise error when special characters are used in username, however, error not raising when tested"
def validate_username(self, username):
# self.username = username
excluded_chars = " *?!'^+%&/()=}][{$#"
for char in self.username.data:
if char in excluded_chars:
raise ValidationError(
f'Character {char} is not allowed in username.')

# added here: first name, last name
# commented out: username, needs to be added in create.py
# class RegistrationForm(FlaskForm):
# first_name = StringField('First Name')
# last_name = StringField('Last Name')
# # username = StringField('Username')
# email = StringField('Email')
# # password = PasswordField('Password')
# submit = SubmitField('Sign Up')
# # address elements
# address_line_one = StringField('Address Line 1')
# address_line_two = StringField('Address Line 2')
# address_line_three = StringField('Address Line 3')
# postcode = StringField('Postcode')


class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email(message='Please supply a valid email')])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')


# as staff are now a type of person, this form gets a bit more complicated, needs to link to userlogin, address,
# person and staff info tables to be functional (can set persontype to '1' which is staff in the routes)
class StaffRegistrationForm(FlaskForm):
# userlogin elements
username = StringField('Username', validators=[DataRequired(), Length(min=2, max=30)])
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('confirm_password',
message="Passwords must match")])

# person elements
first_name = StringField('First Name', validators=[DataRequired(), Length(min=2, max=30)])
last_name = StringField('Last Name', validators=[DataRequired(), Length(min=2, max=30)])
email = StringField('Email', validators=[DataRequired(), Email(message='Please supply a valid email')])

# address elements
address_line_one = StringField('Address Line 1', validators=[DataRequired()])
address_line_two = StringField('Address Line 2')
address_line_three = StringField('Address Line 3')
postcode = StringField('Postcode', validators=[DataRequired()])
phone_number = StringField('Phone Number')

# staff info elements
job_title = StringField('Job title', validators=[DataRequired()])
date_of_birth = DateField('Date of birth', validators=[DataRequired()])
# submit
submit = SubmitField('Register New Staff Member')


# class StaffForm(FlaskForm):
# first_name = StringField('First Name')
# last_name = StringField('Last Name')
# email = StringField('Email')
# password = PasswordField('Password')
# remember = BooleanField('Remember Me')
# submit = SubmitField('Login')


# IN PROGRESS - PLANT FORM
class PlantForm(FlaskForm):
# plant_name = StringField('Plant Name', validators=[DataRequired()])
#removed plant_name field as not sure it was necessary, can add again if needed. Had to completely remove from html file as form would not work with it commented out, was still picking up on the website after submitting the form"
plant_species = StringField('Plant Species', validators=[DataRequired()])
plant_type = SelectField('Type', choices=[('1', 'Cacti/Succulent'), ('2', 'Hanging'), ('3', 'Flowering'), ('4', 'Palms'), ('5', 'Ferns')], validators=[DataRequired()])
plant_category = SelectField('Categories', choices=[('1', 'Indoor'), ('2', 'Outdoor')])
plant_price = IntegerField('Plant Price', validators=[DataRequired()])
plant_stock = IntegerField('Number Being Added To Stock', validators=[DataRequired()])
plant_size = SelectField('Size', choices=[('1', 'Tiny'), ('2', 'Small'), ('3', 'Medium'), ('4', 'Tall')], validators=[DataRequired()])
submit = SubmitField('Register Plant')




# Victoria's code
class BasicForm(FlaskForm):
first_name = StringField('First Name')
last_name = StringField('Last Name')
Expand Down
Loading