diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4aeb6bf Binary files /dev/null and b/.DS_Store differ diff --git a/Assignment/.DS_Store b/Assignment/.DS_Store new file mode 100644 index 0000000..5456940 Binary files /dev/null and b/Assignment/.DS_Store differ diff --git a/Assignment/HW5_SQL/.DS_Store b/Assignment/HW5_SQL/.DS_Store new file mode 100644 index 0000000..a2e36a6 Binary files /dev/null and b/Assignment/HW5_SQL/.DS_Store differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/.DS_Store b/Assignment/HW5_SQL/HW5_Starter_Code/.DS_Store new file mode 100644 index 0000000..8b9dd98 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/.DS_Store differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/__pycache__/config.cpython-35.pyc b/Assignment/HW5_SQL/HW5_Starter_Code/__pycache__/config.cpython-35.pyc new file mode 100644 index 0000000..172ae63 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/__pycache__/config.cpython-35.pyc differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app.db b/Assignment/HW5_SQL/HW5_Starter_Code/app.db new file mode 100644 index 0000000..a5e2f48 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/app.db differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/__init__.cpython-35.pyc b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..9bf5235 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/forms.cpython-35.pyc b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/forms.cpython-35.pyc new file mode 100644 index 0000000..fccf18d Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/forms.cpython-35.pyc differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/models.cpython-35.pyc b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000..0b03b26 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/models.cpython-35.pyc differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/views.cpython-35.pyc b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..95138a5 Binary files /dev/null and b/Assignment/HW5_SQL/HW5_Starter_Code/app/__pycache__/views.cpython-35.pyc differ diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/forms.py b/Assignment/HW5_SQL/HW5_Starter_Code/app/forms.py index 452f61b..f3db217 100755 --- a/Assignment/HW5_SQL/HW5_Starter_Code/app/forms.py +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/forms.py @@ -3,10 +3,18 @@ from flask_wtf.html5 import EmailField from wtforms.validators import DataRequired -class CustomerForm(Form): - company = StringField('company', validators=[DataRequired()]) - email = EmailField('email', validators=[DataRequired()]) - # Add additional Address fields here +class CustomerForm(Form): + first_name = StringField('first_name', validators=[DataRequired()]) + last_name = StringField('last_name', validators=[DataRequired()]) + company = StringField('company', validators=[DataRequired()]) + email = EmailField('email', validators=[DataRequired()]) + phone = StringField('phone', validators=[DataRequired()]) + street_address = StringField('street_address', validators=[DataRequired()]) + city = StringField('city', validators=[DataRequired()]) + state = StringField('state', validators=[DataRequired()]) + country = StringField('country', validators=[DataRequired()]) + zip_code = StringField('zip_code', validators=[DataRequired()]) class OrderForm(Form): - # Add order input form fields here + name_of_part = StringField('name_of_part', validators=[DataRequired()]) + manufacturer_of_part = StringField('manufacturer_of_part', validators=[DataRequired()]) diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/models.py b/Assignment/HW5_SQL/HW5_Starter_Code/app/models.py index 07d1938..ee8c3b4 100755 --- a/Assignment/HW5_SQL/HW5_Starter_Code/app/models.py +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/models.py @@ -1,13 +1,37 @@ import sqlite3 as sql -def insert_data(): - # SQL statement to insert into database goes here +def insert_data(first_name, last_name, company, email, phone, street_address, city, state, country, zip_code): + # SQL statement to insert into database goes here + with sql.connect("app.db") as con: + cur = con.cursor() + cur.execute("INSERT INTO customer (first_name, last_name, company, email, phone) VALUES (?,?,?,?,?)", (first_name, last_name, company, email, phone)) + con.commit() + new_cur = con.cursor() + new_cur.execute("INSERT INTO address (street_address, city, state, country, zip_code) VALUES (?,?,?,?,?)", (street_address, city, state, country, zip_code)) + con.commit() + +def insert_orders( name_of_part, manufacturer_of_part): + # SQL statement to insert into database + with sql.connect("app.db") as con: + cur = con.cursor() + cur.execute("INSERT INTO orders ( name_of_part, manufacturer_of_part) VALUES (?,?)", (name_of_part, manufacturer_of_part)) + con.commit() def retrieve_customers(): - # SQL statement to query database goes here + # SQL statement to query database goes here + with sql.connect("app.db") as con: + con.row_factory = sql.Row + cur = con.cursor() + result = cur.execute("select * from customer").fetchall() + print(result) + return result def retrieve_orders(): - # SQL statement to query database goes here - + # SQL statement to query database goes here + with sql.connect("app.db") as con: + cur = con.cursor() + result = cur.execute("select * from orders").fetchall() + print(result) + return result ##You might have additional functions to access the database diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/customer.html b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/customer.html index 7b7ef62..0a09e37 100755 --- a/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/customer.html +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/customer.html @@ -10,6 +10,14 @@

Add Customer to Our Database

{{ form.hidden_tag() }}
+

+ First Name:
+ {{ form.first_name(size=120) }}
+

+

+ Last Name:
+ {{ form.last_name(size=120) }}
+

Company name:
{{ form.company(size=120) }}
@@ -17,12 +25,34 @@

Add Customer to Our Database

Customer email:
{{ form.email(size=120) }}
- +

+

+ Phone Number:
+ {{ form.phone(size=120) }}

- +

+ Street Address:
+ {{ form.street_address(size=120) }}
+

+

+ City:
+ {{ form.city(size=120) }}
+

+

+ State:
+ {{ form.state(size=120) }}
+

+

+ Country:
+ {{ form.country(size=120) }}
+

+

+ Zip Code:
+ {{ form.zip_code(size=120) }}
+

diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/home.html b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/home.html index 612900a..6f576c7 100755 --- a/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/home.html +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/home.html @@ -12,24 +12,40 @@

These are all of our awesome customers:

+ + + - {% for customer in customers %} + {% for cu in customer %} - - - + + + + + + {% endfor %}
First NameLast NamePhone Company Email
{{ customer['company'] }}{{ customer['email'] }}{{ cu['first_name'] }}{{ cu['last_name'] }}{{ cu['phone'] }}{{ cu['company'] }}{{ cu['email'] }}Add an Order

Orders from Customers:

- + + + + + + {% for or in orders %} + + + + + + {% endfor %} +
Name of PartManufacturer of Part
{{ or[1]}}{{ or[2]}}
diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/orders.html b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/orders.html new file mode 100644 index 0000000..c6bdd6c --- /dev/null +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/templates/orders.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% block content %} +
+
+
+ Home +
+

Add to Cart

+
+ {{ form.hidden_tag() }} +
+
+

+ Name of Part:
+ {{ form.name_of_part(size=120) }}
+

+

+ Manufacturer of Part:
+ {{ form.manufacturer_of_part(size=120) }}
+

+
+

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/app/views.py b/Assignment/HW5_SQL/HW5_Starter_Code/app/views.py index 90c544a..6380800 100755 --- a/Assignment/HW5_SQL/HW5_Starter_Code/app/views.py +++ b/Assignment/HW5_SQL/HW5_Starter_Code/app/views.py @@ -1,7 +1,8 @@ from flask import render_template, redirect, request from app import app, models, db -from .forms import CustomerForm +from .forms import CustomerForm, OrderForm # Access the models file to use SQL functions +from .models import * @app.route('/') @@ -12,20 +13,38 @@ def index(): def create_customer(): form = CustomerForm() if form.validate_on_submit(): - # Get data from the form # Send data from form to Database - return redirect('/customers') + first_name = form.first_name.data + last_name = form.last_name.data + company = form.company.data + email = form.email.data + phone = form.phone.data + street_address = form.street_address.data + city = form.city.data + state = form.state.data + country = form.country.data + zip_code = form.zip_code.data + insert_data(first_name, last_name, company, email, phone, street_address, city, state, country, zip_code), + return redirect('/customer') return render_template('customer.html', form=form) -@app.route('/customers') +@app.route('/customer') def display_customer(): # Retreive data from database to display + cu = retrieve_customers() + orders = models.retrieve_orders() + print(cu) return render_template('home.html', - customers=customers) + customer=cu, orders=orders) @app.route('/create_order/', methods=['GET', 'POST']) def create_order(value): # Get data from the form # Send data from form to Database - return redirect('/customers') - return render_template('order.html', form=orderForm) + form = OrderForm() + if form.validate_on_submit(): + name_of_part = form.name_of_part.data + manufacturer_of_part = form.manufacturer_of_part.data + insert_orders(name_of_part, manufacturer_of_part), + return redirect('/customer') + return render_template('orders.html', form=form) diff --git a/Assignment/HW5_SQL/HW5_Starter_Code/schema.sql b/Assignment/HW5_SQL/HW5_Starter_Code/schema.sql index f06fbdb..f9ddc90 100644 --- a/Assignment/HW5_SQL/HW5_Starter_Code/schema.sql +++ b/Assignment/HW5_SQL/HW5_Starter_Code/schema.sql @@ -1,2 +1,40 @@ -- Insert code to create Database Schema -- This will create your .db database file for use +drop table if exists customer; +drop table if exists address; +drop table if exists orders; +drop table if exists customer_order; + +create table customer ( + customer_id integer primary key, + first_name text not null, + last_name text not null, + company text not null, + email text not null, + phone text not null +); + +create table address ( + id integer primary key, + street_address varchar(200) not null, + city text not null, + state text not null, + country text not null, + zip_code varchar(11) not null, + customer_id integer, + foreign key(customer_id) references customer(customer_id) +); + +create table orders ( + order_id integer primary key, + name_of_part text not null, + manufacturer_of_part text not null +); + +create table customer_order ( + id integer primary key, + order_id integer, + customer_id integer, + foreign key(order_id) references orders(order_id), + foreign key(customer_id) references customer(customer_id) +); \ No newline at end of file diff --git a/Labs/.DS_Store b/Labs/.DS_Store new file mode 100644 index 0000000..8713378 Binary files /dev/null and b/Labs/.DS_Store differ diff --git a/Labs/Lab-SQLite.zip b/Labs/Lab-SQLite.zip new file mode 100644 index 0000000..398682c Binary files /dev/null and b/Labs/Lab-SQLite.zip differ diff --git a/Labs/Lab-SQLite/.DS_Store b/Labs/Lab-SQLite/.DS_Store new file mode 100644 index 0000000..8a712f6 Binary files /dev/null and b/Labs/Lab-SQLite/.DS_Store differ diff --git a/Labs/Lab-SQLite/Untitled.rtf b/Labs/Lab-SQLite/Untitled.rtf new file mode 100644 index 0000000..5be5d02 --- /dev/null +++ b/Labs/Lab-SQLite/Untitled.rtf @@ -0,0 +1,8 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1504 +{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;} +{\colortbl;\red255\green255\blue255;\red0\green0\blue0;\red255\green255\blue255;} +{\*\expandedcolortbl;\csgray\c100000;\csgray\c0;\csgray\c100000;} +\margl1440\margr1440\vieww10800\viewh8400\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0 + +\f0\fs22 \cf2 \cb3 \CocoaLigature0 sqlite3 app.db < schema.sql} diff --git a/Labs/Lab-SQLite/app.db b/Labs/Lab-SQLite/app.db new file mode 100644 index 0000000..a61b799 Binary files /dev/null and b/Labs/Lab-SQLite/app.db differ diff --git a/Labs/Lab-SQLite/app/__init__.py b/Labs/Lab-SQLite/app/__init__.py new file mode 100755 index 0000000..353d3af --- /dev/null +++ b/Labs/Lab-SQLite/app/__init__.py @@ -0,0 +1,8 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy + +app = Flask(__name__) +app.config.from_object('config') +db = SQLAlchemy(app) + +from app import views, models diff --git a/Labs/Lab-SQLite/app/__init__.pyc b/Labs/Lab-SQLite/app/__init__.pyc new file mode 100644 index 0000000..7773f19 Binary files /dev/null and b/Labs/Lab-SQLite/app/__init__.pyc differ diff --git a/Labs/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc b/Labs/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..8082b4e Binary files /dev/null and b/Labs/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Labs/Lab-SQLite/app/forms.py b/Labs/Lab-SQLite/app/forms.py new file mode 100755 index 0000000..a0d42b1 --- /dev/null +++ b/Labs/Lab-SQLite/app/forms.py @@ -0,0 +1,9 @@ +from flask.ext.wtf import Form +from wtforms import StringField, IntegerField +from flask_wtf.html5 import EmailField +from wtforms.validators import DataRequired + +class CustomerForm(Form): + company = StringField('company', validators=[DataRequired()]) + email = EmailField('email', validators=[DataRequired()]) + diff --git a/Labs/Lab-SQLite/app/forms.pyc b/Labs/Lab-SQLite/app/forms.pyc new file mode 100644 index 0000000..669b7b7 Binary files /dev/null and b/Labs/Lab-SQLite/app/forms.pyc differ diff --git a/Labs/Lab-SQLite/app/models.py b/Labs/Lab-SQLite/app/models.py new file mode 100755 index 0000000..3b6d032 --- /dev/null +++ b/Labs/Lab-SQLite/app/models.py @@ -0,0 +1,24 @@ +# squlite3 app.db < schema.sql creates an app.db that contians table + +import sqlite3 as sql + +def insert_customer(company,email): + # SQL statement to insert into database goes here + with sql.connect("app.db") as con: + cur = con.cursor() + # Python recognizes the variables we want to enter as '?' + cur.execute("INSERT INTO customers (company,email) VALUES (?,?)", (company,email)) + con.commit() + +# con = sql.connect("app.db") +# blah blah +# con.commit() +# con.close() + +def retrieve_customers(): + # SQL statement to query database goes here + with sql.connect("app.db") as con: + con.row_factory = sql.Row + cur = con.cursor() + result = cur.execute("select * from customers").fetchall() + return result diff --git a/Labs/Lab-SQLite/app/models.pyc b/Labs/Lab-SQLite/app/models.pyc new file mode 100644 index 0000000..6184eb3 Binary files /dev/null and b/Labs/Lab-SQLite/app/models.pyc differ diff --git a/Labs/Lab-SQLite/app/templates/base.html b/Labs/Lab-SQLite/app/templates/base.html new file mode 100755 index 0000000..db51f24 --- /dev/null +++ b/Labs/Lab-SQLite/app/templates/base.html @@ -0,0 +1,14 @@ + + + {% if title %} + {{ title }} - ACME + {% else %} + Welcome to ACME Aircraft Parts + {% endif %} + + + + + {% block content %}{% endblock %} + + diff --git a/Labs/Lab-SQLite/app/templates/customer.html b/Labs/Lab-SQLite/app/templates/customer.html new file mode 100755 index 0000000..fb6cbc3 --- /dev/null +++ b/Labs/Lab-SQLite/app/templates/customer.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} +{% block content %} +
+
+
+ Home +
+

Add Customer to Our Database

+
+ {{ form.hidden_tag() }} +
+
+ +

+ company name:
+ {{form.company(size=120)}}
+

+

+ Customer email:
+ {{form.email(size=120)}}
+

+
+
+
+ +
+

+
+
+
+{% endblock %} diff --git a/Labs/Lab-SQLite/app/templates/home.html b/Labs/Lab-SQLite/app/templates/home.html new file mode 100755 index 0000000..8c09256 --- /dev/null +++ b/Labs/Lab-SQLite/app/templates/home.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% block content %} +
+
+

Welcome to ACME Aircraft Parts

+ +
+
+

These are all of our awesome customers:

+ + + + + + + + + {% for customer in customers %} + + + + {% endfor %} +
CompanyEmail
{{customer['company']}}
+
+
+
+{% endblock %} diff --git a/Labs/Lab-SQLite/app/views.py b/Labs/Lab-SQLite/app/views.py new file mode 100755 index 0000000..ce19c16 --- /dev/null +++ b/Labs/Lab-SQLite/app/views.py @@ -0,0 +1,29 @@ +from flask import render_template, redirect, request +from app import app, models, db +from .forms import CustomerForm +from models import * +# Access the models file to use SQL functions + + +@app.route('/') +def index(): + return redirect('/create_customer') + +@app.route('/create_customer', methods=['GET', 'POST']) +def create_customer(): + form = CustomerForm() + if form.validate_on_submit(): + # Get data from the form + # Send data from form to Database + company = form.company.data + email = form.email.data + insert_customer(company,email) + return redirect('/customers') + return render_template('customer.html', form=form) + +@app.route('/customers') +def display_customer(): + #Retreive data from database to display + customers = retrieve_customers() + return render_template('home.html', + customers=customers) diff --git a/Labs/Lab-SQLite/app/views.pyc b/Labs/Lab-SQLite/app/views.pyc new file mode 100644 index 0000000..38f8e5c Binary files /dev/null and b/Labs/Lab-SQLite/app/views.pyc differ diff --git a/Labs/Lab-SQLite/config.py b/Labs/Lab-SQLite/config.py new file mode 100755 index 0000000..bbbb224 --- /dev/null +++ b/Labs/Lab-SQLite/config.py @@ -0,0 +1,9 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +# Will be used for ORM Lab +# SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') +# SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository') + +WTF_CSRF_ENABLED = True +SECRET_KEY = 'you-will-never-guess' diff --git a/Labs/Lab-SQLite/config.pyc b/Labs/Lab-SQLite/config.pyc new file mode 100644 index 0000000..59af7fd Binary files /dev/null and b/Labs/Lab-SQLite/config.pyc differ diff --git a/Labs/Lab-SQLite/requirements.txt b/Labs/Lab-SQLite/requirements.txt new file mode 100755 index 0000000..bfbaf81 --- /dev/null +++ b/Labs/Lab-SQLite/requirements.txt @@ -0,0 +1,10 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.1 +Flask-WTF==0.12 +itsdangerous==0.24 +Jinja2==2.8 +MarkupSafe==0.23 +SQLAlchemy==1.0.12 +Werkzeug==0.11.4 +wheel==0.29.0 +WTForms==2.1 diff --git a/Labs/Lab-SQLite/run.py b/Labs/Lab-SQLite/run.py new file mode 100755 index 0000000..5d2f714 --- /dev/null +++ b/Labs/Lab-SQLite/run.py @@ -0,0 +1,2 @@ +from app import app +app.run(debug=True, host="0.0.0.0", port=8081) diff --git a/Labs/Lab-SQLite/schema.sql b/Labs/Lab-SQLite/schema.sql new file mode 100644 index 0000000..6785dd9 --- /dev/null +++ b/Labs/Lab-SQLite/schema.sql @@ -0,0 +1,9 @@ +-- Insert code to create Database Schema +-- This will create your .db database file for use +# Any table that's already existing, drop: +drop table if exists customers; +create table customers ( + customer_id integer primary key, + company text not null, + email text not null +); \ No newline at end of file diff --git a/Labs/Pokemon.db b/Labs/Pokemon.db new file mode 100644 index 0000000..0921557 Binary files /dev/null and b/Labs/Pokemon.db differ diff --git a/Labs/lab-SQL/Pokemon.db b/Labs/lab-SQL/Pokemon.db index 7fbc93f..50ec70c 100644 Binary files a/Labs/lab-SQL/Pokemon.db and b/Labs/lab-SQL/Pokemon.db differ