Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 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
9dee399
basic blog function - can add posts via addpost and view all on plant…
JodyBroad Apr 21, 2022
4fb593f
registration forms fixed
Apr 21, 2022
56ca725
minor tweaks
JodyBroad Apr 21, 2022
614e5f5
Merge pull request #10 from JodyBroad/main
JodyBroad Apr 21, 2022
5e48f72
plant form updates
Apr 21, 2022
2be34fc
Merge pull request #11 from JodyBroad/plant_forms
isabeltulloch Apr 21, 2022
eb562c7
plantform updates
JodyBroad Apr 21, 2022
afb0d46
fix merge conflicts
JodyBroad Apr 21, 2022
353a508
merge conflict
JodyBroad Apr 21, 2022
5996458
merge conflicts
JodyBroad Apr 21, 2022
b3d1bc2
merge conflict
JodyBroad Apr 21, 2022
845825e
added route for looking at individual blog posts and image
JodyBroad 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
0f59f5e
tweaked plant_care template - each post links to individual page, jus…
JodyBroad Apr 22, 2022
b2f360a
added if statements to post and plant_care to display different photos
JodyBroad Apr 22, 2022
1b74dfe
staff register bootstrap added and flash message
Jodie-Smith Apr 22, 2022
e7a3638
added url to go back to the main blog page
JodyBroad Apr 22, 2022
7688d81
fixing a typo
JodyBroad 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
46a822d
Merge pull request #12 from JodyBroad/validation
Jodie-Smith Apr 22, 2022
2bf1249
Merge pull request #13 from JodyBroad/main
JodyBroad Apr 22, 2022
8c17bf1
adding basic blog functionality
JodyBroad Apr 22, 2022
3f55de3
Merge pull request #14 from JodyBroad/blog
JodyBroad Apr 22, 2022
3bdc44f
session variables trial - logs in and assigns correct type, db valida…
JodyBroad Apr 23, 2022
a484bc7
link back to login page working
JodyBroad Apr 23, 2022
bee91a7
design tweaks
Apr 23, 2022
e6d8c95
Merge pull request #16 from JodyBroad/design_updates
nyedun22 Apr 23, 2022
ded50b3
added 3 different navs depending on session variable
JodyBroad Apr 23, 2022
d58dacc
Merge pull request #17 from JodyBroad/main
JodyBroad Apr 23, 2022
97f97f5
3 types of nav, extra dropdowns, login specific text, colour change
JodyBroad Apr 23, 2022
9667c41
log out dropdown menu option added to customer - my account
JodyBroad Apr 23, 2022
1948ba2
added login/out and register buttons and spaced them out
JodyBroad Apr 23, 2022
7731556
button spacing tweaks
JodyBroad Apr 23, 2022
bea5042
minor tweaks to login logic, resolves same password issue
JodyBroad Apr 24, 2022
42f7335
Merge pull request #18 from JodyBroad/log_in_hashed_passwords
JodyBroad Apr 24, 2022
aa6403f
minor tweaks
JodyBroad Apr 24, 2022
be583cc
tidying up routes code
JodyBroad Apr 24, 2022
9a6f2b2
Merge pull request #19 from JodyBroad/session_variables
JodyBroad Apr 24, 2022
2cff229
basic shopping cart functional, added cart/add_to_cart.html for testing
JodyBroad Apr 24, 2022
69dd6e7
lifestyle imagery added
Apr 24, 2022
4dfd9ec
Merge pull request #20 from JodyBroad/lifestyleimagery
isabeltulloch Apr 24, 2022
4cbecfd
tidying up code
JodyBroad Apr 24, 2022
81612e3
Merge pull request #21 from JodyBroad/tidy
JodyBroad Apr 24, 2022
5b017c9
fixing merge conflicts
JodyBroad Apr 24, 2022
4cf908f
minor tweaks experimenting with further session variable stuff
JodyBroad Apr 25, 2022
e3678cb
inital commit, bar bar able to search for blog posts, will add abilit…
Jodie-Smith Apr 25, 2022
462f2c6
session id for user id now works
JodyBroad Apr 25, 2022
ff22da4
delete blogpost functionality and update to nav
JodyBroad Apr 25, 2022
62dcb23
added order history - not quite functional yet
JodyBroad Apr 25, 2022
dc31925
database updates & plant form
Apr 26, 2022
e017ce9
Merge pull request #22 from JodyBroad/main
JodyBroad Apr 26, 2022
41fa014
shopping cart now pulls values from db price, nickname etc and adds t…
JodyBroad Apr 26, 2022
e1b5694
about us page improvements and styling
JodyBroad Apr 26, 2022
8c01296
Some additional working queries
Apr 26, 2022
0e8a6d0
small changes
Jodie-Smith Apr 26, 2022
00b9d6a
added custom 404 message and some tweaking the shopping cart
JodyBroad Apr 26, 2022
bc1add3
Merge pull request #23 from JodyBroad/search_bar
Jodie-Smith Apr 26, 2022
e69687c
added custom 404 message and styled
JodyBroad Apr 26, 2022
01b1e4c
validators added for special characters, email and confirm password. …
Jodie-Smith Apr 26, 2022
36a46ca
Merge branch 'main' into custom_error
Jodie-Smith Apr 26, 2022
7177a04
all errors now working staff register form, no more form validation o…
Jodie-Smith Apr 27, 2022
5083a01
getting delete blog post functional
JodyBroad Apr 27, 2022
fea1d12
tweaking blog post deletion route
JodyBroad Apr 27, 2022
359744b
tidying
JodyBroad Apr 27, 2022
0f69cf1
fixing merge conflicts
JodyBroad Apr 27, 2022
dfb16e5
further tinkering with shopping cart etc
JodyBroad Apr 28, 2022
0e05471
further tweaks to the shopping cart
JodyBroad Apr 28, 2022
97af886
last item added to basket now works on add_to_cart, cart almost funct…
JodyBroad Apr 28, 2022
cf7766e
minor cart based tweaks
JodyBroad Apr 28, 2022
ca71fef
added responsive table formatting to the cart and cart_success html
JodyBroad Apr 28, 2022
5219aeb
trying to get shopping cart functional
JodyBroad Apr 28, 2022
2495334
shopping basket working, no repeats, now with sub totals and totals b…
JodyBroad Apr 29, 2022
e40c461
minor formatting tweak
JodyBroad Apr 29, 2022
72fa636
nav update
JodyBroad Apr 29, 2022
acd9d42
Merge pull request #25 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
33def5c
deleting rogue print statement
JodyBroad Apr 29, 2022
db55047
Merge pull request #26 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
837f30f
dropdown menu complete
Apr 29, 2022
dc6a21b
fixed issue with empty shopping cart, got empty shopping cart button …
JodyBroad Apr 29, 2022
ea9a705
styling tweaks etc
JodyBroad Apr 29, 2022
ecdf42a
Merge pull request #27 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
ea54e67
tidying up the html, minor styling tweaks
JodyBroad Apr 29, 2022
b844856
Merge pull request #28 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
79ff636
added some banner images and stylings
JodyBroad Apr 29, 2022
a88b43a
Merge pull request #29 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
1bf0d2c
plant page created, minor formating still outstanding, add quantity t…
Jodie-Smith Apr 29, 2022
72f342e
merge conflicts
Apr 29, 2022
932c8ae
Merge pull request #30 from JodyBroad/filtering_queries
isabeltulloch Apr 29, 2022
a05229c
removed jsonify from reqs, updated formatting on staff_jobs.html
JodyBroad Apr 29, 2022
b9a4919
cart link added and borders removed
Jodie-Smith Apr 29, 2022
fb7c8cf
Merge pull request #31 from JodyBroad/main
JodyBroad Apr 29, 2022
6017fa2
Merge branch 'main' into plant_page
Jodie-Smith Apr 29, 2022
3d9396e
Merge pull request #32 from JodyBroad/plant_page
Jodie-Smith Apr 29, 2022
2e11aef
added formatting and bav for customer_orders and outstanding_orders
JodyBroad Apr 29, 2022
736c5db
stock list query functional and on the nav
JodyBroad Apr 29, 2022
594f978
fixing nav to show indoor/outdoor plants
JodyBroad Apr 29, 2022
8b2f3bc
Merge pull request #33 from JodyBroad/main
JodyBroad Apr 29, 2022
48f0197
nav updates, buttons on homepage now link to shop correctly as do all…
JodyBroad Apr 29, 2022
f4be0a3
Merge pull request #34 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
cfb6ebe
thumbnail images for all the shopping cart screens, also these will l…
JodyBroad Apr 29, 2022
620c8ee
Merge pull request #35 from JodyBroad/session_variables
JodyBroad Apr 29, 2022
e038d8b
fixing custom 404 page display picture size
JodyBroad Apr 30, 2022
63b648a
navbar tweaks to try to resolve alignment issues
JodyBroad Apr 30, 2022
e6cdf3c
order history query now works for customers when logged in
JodyBroad Apr 30, 2022
4b517e3
Merge pull request #37 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
20ecc79
added some extra orders in create.py and also fixed an issue with cus…
JodyBroad Apr 30, 2022
eb4b234
Merge pull request #38 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
e12488c
updated show customer orders to include Order Status
JodyBroad Apr 30, 2022
972da20
Merge pull request #39 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
fb8c5c4
login type now set using the db and not the dropdown, dropdown remove…
JodyBroad Apr 30, 2022
e5da2c2
Merge pull request #40 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
78c3e09
trying to get delete blogpost working, not quite functional yet
JodyBroad Apr 30, 2022
d22cb2f
updated nav with delete blog post option for staff
JodyBroad Apr 30, 2022
c8c33a7
made a start on placing an order functionality
JodyBroad Apr 30, 2022
f194d03
some improvements on blog post display
JodyBroad Apr 30, 2022
83f71ef
expanded content on blog post, worked on styling, updated css for hyp…
JodyBroad Apr 30, 2022
7ba2eb6
Merge pull request #41 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
ec98f88
fixed favicon
JodyBroad Apr 30, 2022
c1d37bf
Merge pull request #42 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
513a8f7
added correctly aspect ratioed header images and applied these to all…
JodyBroad Apr 30, 2022
177c418
Merge pull request #43 from JodyBroad/session_variables
JodyBroad Apr 30, 2022
5248da0
trying to get complete order functional, is close to working
JodyBroad Apr 30, 2022
abfdf08
updated background colour on buttons
JodyBroad May 1, 2022
ca783b4
Merge pull request #44 from JodyBroad/session_variables
JodyBroad May 1, 2022
b422060
shop page partially updated
May 1, 2022
cfd1c01
Merge branch 'main' of https://github.com/JodyBroad/team_yellow
May 1, 2022
5e05358
shop working
May 1, 2022
45fec63
added update email route for customers, not quite functional, added t…
JodyBroad May 1, 2022
9862071
Merge pull request #45 from JodyBroad/shop_fixing
isabeltulloch May 1, 2022
791084e
Merge pull request #46 from JodyBroad/main
JodyBroad May 1, 2022
3c0b7c6
add to cart button working, more than one item added to cart now merg…
Jodie-Smith May 1, 2022
e2855c3
checkout now works, added buttons etc, tweaked create.py
JodyBroad May 1, 2022
294d5ed
Merge pull request #47 from JodyBroad/session_variables
JodyBroad May 1, 2022
375ec79
styling tweaks
JodyBroad May 1, 2022
ccc0548
Merge pull request #48 from JodyBroad/session_variables
JodyBroad May 1, 2022
c95f446
redirect for not logged in added when triying to make a purchase logg…
Jodie-Smith May 1, 2022
bad1f04
add to cart fully functional, will next work on formatting
Jodie-Smith May 1, 2022
06ba9b3
append error in cart, need to be able to add more than one thing as a…
Jodie-Smith May 1, 2022
a4f4ecc
append error on cart fixed
Jodie-Smith May 1, 2022
4f18f72
formatting on plant page fixed
Jodie-Smith May 1, 2022
4aa70df
password added back to init.py
Jodie-Smith May 1, 2022
c1231a3
Merge pull request #49 from JodyBroad/plant_page_functionality
Jodie-Smith May 1, 2022
29a727c
picture added for Jodie in about, information not yet added
Jodie-Smith May 1, 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:password@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
212 changes: 197 additions & 15 deletions application/create.py

Large diffs are not rendered by default.

145 changes: 144 additions & 1 deletion application/forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,153 @@
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

# need form to do email newsletter sign up

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


def validate_username(form, field):
excluded_chars = " *?!'^+%&/()=}][{$#"
for char in form.username.data:
if char in excluded_chars:
raise ValidationError(
f'Character {char} is not allowed in username. Please do not use any of the following characters: {excluded_chars}')

# 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), validate_username])
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('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')
# submit
submit = SubmitField('Sign Up')



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), validate_username])
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 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()])
plant_nickname = StringField('Plant Nickname', validators=[DataRequired()])
plant_info = StringField('General Plant Info', validators=[DataRequired()])
care_tip_1 = StringField('First Care Tip', validators=[DataRequired()])
care_tip_2 = StringField('Second Care Tip')
care_tip_3 = StringField('Third Care Tip')
image_1 = StringField('Image Link', validators=[DataRequired()])
image_2 = StringField('Image Link')
image_3 = StringField('Image Link')
tech_description = StringField('Women in tech description', validators=[DataRequired()])
submit = SubmitField('Register Plant')


# add a new blog post
class NewBlogPostForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
author = StringField('Author', validators=[DataRequired()])
post_content = StringField('Post Content', validators=[DataRequired()])

submit = SubmitField('Add post')

# delete blog post
class DeleteBlogPostForm(FlaskForm):
id = IntegerField('ID of the post you want to delete', validators=[DataRequired()])

submit = SubmitField('Delete post')

# log in form
class LogInForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
type = SelectField('Type', choices=[('1', 'Staff'), ('2', 'Customer')])

submit = SubmitField('Log in')

# add to cart
class AddToCartForm(FlaskForm):
product = SelectField('Species', choices=[(1, 'Boston Fern'), (2, 'Aloe Vera'), (3, 'Parlour Palm')])
# product = SelectField('Species', choices=['Boston Fern', 'Aloe Vera', 'Parlour Palm'])
quantity = IntegerField('Quantity', validators=[DataRequired()])
# price =
submit = SubmitField('Add to cart')

# create a search form
class SearchForm(FlaskForm):
searched = StringField('Searched', validators=[DataRequired()])
submit = SubmitField('Submit')


class OrderForm(FlaskForm):
# basically as the fields we need to make a new db record are already in the cart values or can be autopopulated,
# so think you would just use this form as the confirmation button
# submit
submit = SubmitField('Place Order')

class UpdateEmailForm(FlaskForm):
new_email = StringField('New email address', validators=[DataRequired()])
# submit
submit = SubmitField('Update Email')

# Victoria's code
class BasicForm(FlaskForm):
first_name = StringField('First Name')
last_name = StringField('Last Name')
submit = SubmitField('Add Name')



158 changes: 151 additions & 7 deletions application/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,162 @@
from application import db # import the sqlalchemy object (db) created for our app
from application import db # import the sqlalchemy object (db) created for our app

# Blog posts
class BlogPosts(db.Model):
id = db.Column(db.Integer, primary_key=True)
author = db.Column(db.String(50), nullable=False)
date_posted = db.Column(db.Date, nullable=False)
title = db.Column(db.String(50), nullable=False)
post_content = db.Column(db.String(1000), nullable=False)



# Newsletter signup
class Newsletter(db.Model):
id = db.Column(db.Integer, primary_key=True)
newsletter_email = db.Column(db.String(120), nullable=False)

# PersonType linking to Person
class PersonType(db.Model):
id = db.Column(db.Integer, primary_key=True)
person_type_description = db.Column(db.String(50), nullable=False)
# not a field in the table, but PersonType table links back to Person(can use to set permissions
# in later iteration)
person_type = db.relationship('Person', backref='person_type')


# UserLogin linking to Person
class UserLogin(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50), nullable=False)
password = db.Column(db.String(50), nullable=False)
# not field in table but relationship between userlogin and person
user_login = db.relationship('Person', backref='user_login')


# address linking to person
class Address(db.Model):
id = db.Column(db.Integer, primary_key=True)
address_line_one = db.Column(db.String(50), nullable=False)
address_line_two = db.Column(db.String(50), nullable=True)
address_line_three = db.Column(db.String(50), nullable=True)
address_line_four = db.Column(db.String(50), nullable=True)
postcode = db.Column(db.String(50), nullable=False)
# relationship between address and customer table - several people may have the same address
address = db.relationship('Person', backref='address')


# Staff Info - allows us to record extra info about staff, but also gives them staff ID number to use to assign
# to orders for packing etc
class StaffInfo(db.Model):
id = db.Column(db.Integer, primary_key=True)
job_title = db.Column(db.String(50), nullable=False)
date_of_birth = db.Column(db.Date, nullable=False)
staff_info = db.relationship('Person', backref='staff_info')



# Person linking to address userlogin and orderheader
class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(30), nullable=False)
last_name = db.Column(db.String(30), nullable=False)
cars = db.relationship('Car', backref='person')
email = db.Column(db.String(120), nullable=False)
# address_id is the Foreign Key linking to the Address table
address_id = db.Column(db.Integer, db.ForeignKey('address.id'), nullable=False)
phone_number = db.Column(db.String(30), nullable=False)
# user_login_id is linking back for username and password purposes
user_login_id = db.Column(db.Integer, db.ForeignKey('user_login.id'), nullable=False)
person_type_id = db.Column(db.Integer, db.ForeignKey('person_type.id'), nullable=False)
staff_info_id = db.Column(db.Integer, db.ForeignKey('staff_info.id'), nullable=True)
# not a field in the table, but OrderHeader table links back to PersonID
person_id = db.relationship('OrderHeader', backref='person')


class Car(db.Model):
class OrderStatus(db.Model):
id = db.Column(db.Integer, primary_key=True)
status_description = db.Column(db.String(50), nullable=False)
# not a field in the table, but OrderStatus table links back to OrderHeader
order_status = db.relationship('OrderHeader', backref='order_status')


class Category(db.Model):
id = db.Column(db.Integer, primary_key=True)
category_description = db.Column(db.String(50), nullable=False)
# not a field in the table, but Category table links back to Product
category = db.relationship('Product', backref='category')


class PlantType(db.Model):
id = db.Column(db.Integer, primary_key=True)
plant_type_description = db.Column(db.String(50), nullable=False)
# not a field in the table, but PlantType table links back to Product
plant_type = db.relationship('Product', backref='plant_type')


class Size(db.Model):
id = db.Column(db.Integer, primary_key=True)
size_description = db.Column(db.String(50), nullable=False)
# not a field in the table, but Size table links back to Product
size = db.relationship('Product', backref='size')


class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
species = db.Column(db.String(50), nullable=False)
# is this the right data type to store number to 2 decimal places?
price = db.Column(db.Integer, nullable=False)
stock = db.Column(db.Integer, nullable=False)
category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False)
plant_type_id = db.Column(db.Integer, db.ForeignKey('plant_type.id'), nullable=False)
size_id = db.Column(db.Integer, db.ForeignKey('size.id'), nullable=False)
plant_nickname = db.Column(db.String(50), nullable=False)
general_info = db.Column(db.String(200), nullable=False)
care_tip1 = db.Column(db.String(100), nullable=False)
care_tip2 = db.Column(db.String(100), nullable=True)
care_tip3 = db.Column(db.String(100), nullable=True)
img_link1 = db.Column(db.String(200), nullable=False)
img_link2 = db.Column(db.String(200), nullable=True)
img_link3 = db.Column(db.String(200), nullable=True)
tech_description = db.Column(db.String(400), nullable=False)
# not a field in the table, but OrderLine table links back to Product
product = db.relationship('OrderLine', backref='product')

class OrderHeader(db.Model):
id = db.Column(db.Integer, primary_key=True)
number_plate = db.Column(db.String(7), nullable=False)
colour = db.Column(db.String(10), nullable=False)
make = db.Column(db.String(20), nullable=False)
model = db.Column(db.String(20), nullable=False)
person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=False)
# not totally sure how we do dates, check this
order_date = db.Column(db.Date, nullable=False)
status_id = db.Column(db.Integer, db.ForeignKey('order_status.id'), nullable=False)
# also what is best data type for price data?
total_cost = db.Column(db.Integer)
# staff_id = db.Column(db.Integer, db.ForeignKey('StaffInfo.id'), nullable=False)
# staff_id = db.Column(db.Integer, db.ForeignKey('person.staff_info_id'), nullable=False)
# not a field in the table, but OrderLine table links back to OrderHeader
order_header = db.relationship('OrderLine', backref='order_header')


class OrderLine(db.Model):
id = db.Column(db.Integer, primary_key=True)
order_header_id = db.Column(db.Integer, db.ForeignKey('order_header.id'), nullable=False)
product_id = db.Column(db.Integer, db.ForeignKey('product.id'), nullable=False)
quantity = db.Column(db.Integer, nullable=False)
# also what is best data type for price data?
price_paid = db.Column(db.Integer)


# Victoria's code:

# class Person(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# first_name = db.Column(db.String(30), nullable=False)
# last_name = db.Column(db.String(30), nullable=False)
# cars = db.relationship('Car', backref='person')
#
#
# class Car(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# number_plate = db.Column(db.String(7), nullable=False)
# colour = db.Column(db.String(10), nullable=False)
# make = db.Column(db.String(20), nullable=False)
# model = db.Column(db.String(20), nullable=False)
# person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=False)
Loading