diff --git a/CSS/CSS-in-class-grid-layout.html b/CSS/CSS-in-class-grid-layout.html new file mode 100644 index 0000000..bf8abeb --- /dev/null +++ b/CSS/CSS-in-class-grid-layout.html @@ -0,0 +1,67 @@ + + + + + + Felines in a Grid + + + + +
+

Felines in a Grid

+ +
+ +
+

In Other News

+
+ +
+
+ +
+
+ +
+
+ +
+

Our Finest Felines

+
+ Steve +

Steve

+
+
+ Dr. Franklin +

Dr. Franklin

+
+
+ Mr. Lickums +

Mr. Lickums

+
+
+ Roxanne +

Roxanne

+
+
+ Felix +

Felix

+
+
+ Bubbles +

Bubbles

+
+
+ + + + \ No newline at end of file diff --git a/CSS/grid-style.css b/CSS/grid-style.css new file mode 100644 index 0000000..297343b --- /dev/null +++ b/CSS/grid-style.css @@ -0,0 +1,153 @@ +/*----------------- CSS RESET ------------------*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} + +/*----------------- CSS RESET ------------------*/ + +body { + font-size: 18px; +} + +header, footer { + width: 100%; + background: #4d94ff; + color: #ffffff; + box-sizing: border-box; + height: 50px; + line-height: 50px; + text-align: center; +} + +header { + display: inline-block; +} + +footer { +/* float: left;*/ + margin-top: 2em; + clear: both; +} + +nav { + width: 50%; + margin-left: 25%; +} + +img { + max-width: 100%; + max-height: 100%; + border: 1px solid #adadad; +} + +h2 { + font-size: 1.5em; +} + +h3 { + font-size: 1.33em; + font-weight: bold; + padding: 20px; +} + +a { + text-decoration: none; +} + +#site-title { + float: left; + width: 25%; + text-align: center; +} + +.nav-button { + color: #ffffff; + display: inline-block; + background: none; + height: 100%; + width: 150px; + border-left: 1px solid #ffffff; + border-right: 1px solid #ffffff; + margin-left: -5px; +} + +.nav-button:hover { + background: #80b3ff; +} + +a.nav-button:visited { + color: #ffffff; +} + + +/*START HERE*/ + +.other-news-container { + float: left; + width: 25%; +} + +.main-container { + float: right; + width: 75%; + text-align: center; +} + +.ib-grid-item { + box-sizing: border-box; + display: inline-block; + width: 33%; + margin-left: auto; + margin-bottom: 10%; +} + +.ib-grid-item img { + max-height: 66.67%; + max-width: 66.67%; +} + +.other-news-item { + box-sizing: border-box; + padding: 1em; +} diff --git a/flask/orm-tutorial/models-tutorial/app.db b/flask/orm-tutorial/models-tutorial/app.db index 41839c5..ae71be1 100644 Binary files a/flask/orm-tutorial/models-tutorial/app.db and b/flask/orm-tutorial/models-tutorial/app.db differ diff --git a/flask/orm-tutorial/models-tutorial/app/forms.py b/flask/orm-tutorial/models-tutorial/app/forms.py index 5724699..4f3c417 100644 --- a/flask/orm-tutorial/models-tutorial/app/forms.py +++ b/flask/orm-tutorial/models-tutorial/app/forms.py @@ -2,8 +2,23 @@ from wtforms import StringField, IntegerField from flask_wtf.html5 import EmailField from wtforms.validators import DataRequired +from wtforms.ext.sqlalchemy.fields import QuerySelectField class CustomerForm(Form): company = StringField('company', validators=[DataRequired()]) email = EmailField('email', validators=[DataRequired()]) # Add additional Address fields here + first_name = StringField('first_name', validators=[DataRequired()]) + last_name = StringField('last_name', validators=[DataRequired()]) + phone = StringField('phone', validators=[DataRequired()]) + + street_name = StringField('street_name', 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): + total_spent = StringField('total_spent', validators=[DataRequired()]) + num_parts_ordered = StringField('num_parts_ordered', validators=[DataRequired()]) + customer_id = StringField('customer_id', validators=[DataRequired()]) diff --git a/flask/orm-tutorial/models-tutorial/app/models.py b/flask/orm-tutorial/models-tutorial/app/models.py index 2f53581..eab370a 100644 --- a/flask/orm-tutorial/models-tutorial/app/models.py +++ b/flask/orm-tutorial/models-tutorial/app/models.py @@ -1,15 +1,42 @@ from app import db +orders = db.Table('orders', + db.Column('order_id', db.Integer, db.ForeignKey('order.id')), + db.Column('customer_id', db.Integer, db.ForeignKey('customer.id')) +) class Customer(db.Model): id = db.Column(db.Integer, primary_key=True) company = db.Column(db.String(120), unique=False) - email = db.Column(db.String(120)) + email = db.Column(db.String(120), unique=False) # You need to a relationship to Address table here # see http://flask-sqlalchemy.pocoo.org/2.1/models/#one-to-many-relationships + first_name = db.Column(db.String(120), unique=False) + last_name = db.Column(db.String(120), unique=False) + phone = db.Column(db.String(10), unique=False) + addresses = db.relationship('Address', backref='customer', cascade='all, delete-orphan', lazy='dynamic') + orders = db.relationship('Order', secondary=orders, backref=db.backref('customer', lazy='dynamic')) def __repr__(self): - return '' % self.email + return '' % self.id # Your Address code should go here -# class Address(db.Model): +class Address(db.Model): + id = db.Column(db.Integer, primary_key=True) + street_name = db.Column(db.String(120), unique=False) + city = db.Column(db.String(20), unique=False) + state = db.Column(db.String(5), unique=False) + country = db.Column(db.String(60), unique=False) + zip_code = db.Column(db.String(20), unique=False) + customer_id = db.Column(db.Integer, db.ForeignKey('customer.id')) + + def __repr__(self): + return '
' % self.id + +class Order(db.Model): + id = db.Column(db.Integer, primary_key=True) + num_parts_ordered = db.Column(db.Integer, unique=False) + total_spent = db.Column(db.Integer, unique=False) + + def __repr__(self): + return '
' % self.id diff --git a/flask/orm-tutorial/models-tutorial/app/static/styles/styles.css b/flask/orm-tutorial/models-tutorial/app/static/styles/styles.css new file mode 100644 index 0000000..f38c63d --- /dev/null +++ b/flask/orm-tutorial/models-tutorial/app/static/styles/styles.css @@ -0,0 +1,3 @@ +select { + display: inline-block; +} \ No newline at end of file diff --git a/flask/orm-tutorial/models-tutorial/app/templates/customer.html b/flask/orm-tutorial/models-tutorial/app/templates/customer.html index d7b457a..64e537d 100644 --- a/flask/orm-tutorial/models-tutorial/app/templates/customer.html +++ b/flask/orm-tutorial/models-tutorial/app/templates/customer.html @@ -10,18 +10,50 @@

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) }}

+

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

+

+ Customer phone:
+ {{ form.phone(size=20) }}
+

- +

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

+

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

+

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

+

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

+

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

diff --git a/flask/orm-tutorial/models-tutorial/app/templates/home.html b/flask/orm-tutorial/models-tutorial/app/templates/home.html index 6b447ec..bb70e76 100644 --- a/flask/orm-tutorial/models-tutorial/app/templates/home.html +++ b/flask/orm-tutorial/models-tutorial/app/templates/home.html @@ -5,6 +5,7 @@

Welcome to ACME Aircraft Parts

@@ -12,16 +13,47 @@

These are all of our awesome customers:

+ + + + + {% for customer in customers %} - + {% for address in customer.addresses.all() %} + + + + + + {% endfor %} + + {% endfor %} +
First NameLast Name Company EmailPhoneCityZip Code
{{ customer.first_name }}{{ customer.last_name }} {{ customer.company }} {{ customer.email }}{{ customer.phone }}{{ address.city }}{{ address.zip_code }}
+
+
+

Orders from Customers:

+ + + + + + + + + {% for order in orders %} + + + + {% for order in order.customer.all() %} + + {% endfor %} {% endfor %}
Number of PartsTotal SpentCustomer ID
{{ order.num_parts_ordered }}{{ order.total_spent }}{{ order.id }}
diff --git a/flask/orm-tutorial/models-tutorial/app/templates/orderform.html b/flask/orm-tutorial/models-tutorial/app/templates/orderform.html new file mode 100644 index 0000000..904f1eb --- /dev/null +++ b/flask/orm-tutorial/models-tutorial/app/templates/orderform.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} +{% block content %} +
+
+
+ Home +
+

Add Order to Database

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

+ Number of Parts:
+ {{ form.num_parts_ordered(size=60) }}
+

+

+ Money Spent:
+ {{ form.total_spent(size=60) }}
+

+

+ Customer IDs (seperate by ","):
+ {{ form.customer_id(size=60) }}
+

+
+
+

+
+
+
+{% endblock %} diff --git a/flask/orm-tutorial/models-tutorial/app/views.py b/flask/orm-tutorial/models-tutorial/app/views.py index e49db4f..10597e7 100644 --- a/flask/orm-tutorial/models-tutorial/app/views.py +++ b/flask/orm-tutorial/models-tutorial/app/views.py @@ -1,7 +1,6 @@ from flask import render_template, redirect, request from app import app, models, db -from .forms import CustomerForm - +from .forms import CustomerForm, OrderForm @app.route('/') def index(): @@ -9,19 +8,48 @@ def index(): @app.route('/create_customer', methods=['GET', 'POST']) def create_customer(): - form = CustomerForm() - if form.validate_on_submit(): + customerForm = CustomerForm() + if customerForm.validate_on_submit(): customer = models.Customer( - company = form.company.data, - email = form.email.data) + first_name = customerForm.first_name.data, + last_name = customerForm.last_name.data, + company = customerForm.company.data, + email = customerForm.email.data, + phone = customerForm.phone.data) # you will need to add Address here + address = models.Address( + street_name = customerForm.street_name.data, + city = customerForm.city.data, + state = customerForm.state.data, + country = customerForm.country.data, + zip_code = customerForm.zip_code.data, + customer = customer) db.session.add(customer) + db.session.add(address) db.session.commit() return redirect('/customers') - return render_template('customer.html', form=form) + return render_template('customer.html', form=customerForm) @app.route('/customers') def display_customer(): customers = models.Customer.query.all() - return render_template('home.html', - customers=customers) + orders = models.Order.query.all() + #orderCustomer = models.orders.query.all() + return render_template('home.html', customers=customers, orders=orders) + +@app.route('/create_order', methods=['GET', 'POST']) +def create_order(): + orderForm = OrderForm() + if orderForm.validate_on_submit(): + order = models.Order( + num_parts_ordered = orderForm.num_parts_ordered.data, + total_spent = orderForm.total_spent.data) + customerids = orderForm.customer_id.data.split(',') + + for customer_id in customerids: + customer = models.Customer.query.filter_by(id=customer_id).first() + customer.orders.append(order) + db.session.add(order) + db.session.commit() + return redirect('/customers') + return render_template('orderform.html', form=orderForm) diff --git a/flask/orm-tutorial/models-tutorial/config.py b/flask/orm-tutorial/models-tutorial/config.py index a995426..8843c41 100644 --- a/flask/orm-tutorial/models-tutorial/config.py +++ b/flask/orm-tutorial/models-tutorial/config.py @@ -3,6 +3,6 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository') - +SQLALCHEMY_TRACK_MODIFICATIONS = True WTF_CSRF_ENABLED = True SECRET_KEY = 'you-will-never-guess' diff --git a/flask/orm-tutorial/models-tutorial/run.py b/flask/orm-tutorial/models-tutorial/run.py index 5d2f714..facc445 100644 --- a/flask/orm-tutorial/models-tutorial/run.py +++ b/flask/orm-tutorial/models-tutorial/run.py @@ -1,2 +1,2 @@ from app import app -app.run(debug=True, host="0.0.0.0", port=8081) +app.run(debug=True, host="0.0.0.0", port=5000) diff --git a/javascript/grid-style-completed.css b/javascript/grid-style-completed.css new file mode 100644 index 0000000..c7a8db3 --- /dev/null +++ b/javascript/grid-style-completed.css @@ -0,0 +1,160 @@ +/*----------------- CSS RESET ------------------*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} + +/*----------------- CSS RESET ------------------*/ + +body { + font-size: 18px; +} + +header, footer { + width: 100%; + background: #4d94ff; + color: #ffffff; + box-sizing: border-box; + height: 50px; + line-height: 50px; + text-align: center; +} + +header { + display: inline-block; +} + +footer { +/* float: left;*/ + margin-top: 2em; + clear: both; +} + +button { + display: block; + width: 50%; + height: 50px; + margin-left: 25%; +} + +nav { + width: 50%; + margin-left: 25%; +} + +img { + max-width: 100%; + max-height: 100%; + border: 1px solid #adadad; +} + +h2 { + font-size: 1.5em; +} + +h3 { + font-size: 1.33em; + font-weight: bold; + padding: 20px; +} + +a { + text-decoration: none; +} + +#site-title { + float: left; + width: 25%; + text-align: center; +} + +.nav-button { + color: #ffffff; + display: inline-block; + background: none; + height: 100%; + width: 150px; + border-left: 1px solid #ffffff; + border-right: 1px solid #ffffff; + margin-left: -4px; +} + +.nav-button:hover { + background: #80b3ff; +} + +a.nav-button:visited { + color: #ffffff; +} + +/*START HERE*/ + +.sidebar { + display: inline-block; + float: left; + width: 25%; + text-align: center; +} + +.interaction-buttons { + text-align: center; +} + +.main-container { + float: left; + width: 75%; + text-align: center; +} + +.ib-grid-item { + display: inline-block; + box-sizing: border-box; + width: 33%; + margin-bottom: 10%; + margin-left: -5px; +} + +.ib-grid-item img { + max-width: 66.67%; + max-height: 66.67%; +} \ No newline at end of file diff --git a/javascript/javascript-in-class-exercises.html b/javascript/javascript-in-class-exercises.html new file mode 100644 index 0000000..51a27b0 --- /dev/null +++ b/javascript/javascript-in-class-exercises.html @@ -0,0 +1,76 @@ + + + + + + Felines in a Grid + + + + +
+

Felines in a Grid

+ +
+ + + +
+

Our Finest Felines

+
+ Steve +

Steve

+
+
+ Dr. Franklin +

Dr. Franklin

+
+
+ Mr. Lickums +

Mr. Lickums

+
+
+ Roxanne +

Roxanne

+
+
+ Felix +

Felix

+
+
+ Bubbles +

Bubbles

+
+
+ +
+ Back to top + | © Felines in a Grid 2016. All rights reserved. +
+ + + + + + + + + \ No newline at end of file diff --git a/javascript/js-basics.js b/javascript/js-basics.js new file mode 100644 index 0000000..117f5a7 --- /dev/null +++ b/javascript/js-basics.js @@ -0,0 +1,74 @@ +// JavaScript in-class exercises for IO Lab 2/5/2016 + + +// Pop-up the site's title +function displaySiteTitle() { + var siteTitle = document.getElementById('site-title'); + alert("This site's title is: " + siteTitle.innerHTML); +} + +// Change around a few cat names +function changeEvenNames() { + var newNames = ['George', 'Roberta', 'Phoenix']; + var cats = document.getElementsByClassName('ib-grid-item'); + + for (var i=0; i < cats.length; i++) { + if (i % 2 == 0) { + var catName = cats[i].getElementsByTagName('p')[0]; + catName.innerHTML = newNames[i/2]; + } + } +} + +// Add an event listener to a button +window.onload = function() { + +} + +// Switch page background between white and grey +var colorSwitch = true; +function switchBodyBackgroundColor() { + var body = document.getElementsByTagName('body')[0]; + + if (colorSwitch) { + colorSwitch = false; + body.style.backgroundColor = 'gray'; + } else { + colorSwitch = true; + body.style.backgroundColor = 'white'; + } +} + +// Remove the first cat in the grid +function removeFirstCat() { + +} + +// Add Dr. Franklin to the end of the list +function addCats() { + +} + +// Swap the position of the sidebar and main container, increase the width of each grid item to 50%, and change the font +function changeGridLayout() { + +} + + +// Create 3 'cat' objects and insert them into the DOM +// Instructions +// 1. Include 'alt' and 'src' as keys within each of the 3 objects - values should correspond to the cat's name and img source (you can re-use name and URLs from the existing cat elements in the HTML) +// 2. Put these 3 objects into an array - you can do this programmatically or hard-coded +// 3. Create a handler for the 'Cats from Obj' button in the HTML (use the function below) +function populateFromObj() { + + // 1. Iterate through each 'cat' object in the list you created above + // 2. For each obj: + // a) create a new div element with class 'ib-grid-item' + // b) create a new img element + // c) set the 'src' and 'alt' attributes on the img with the corresponding values from the object + // d) create a new p element + // e) set the p element's innerHTML to the 'alt' value of the object + // f) append the img and p elements to the div from step a + // g) append the div element to the parent container +} \ No newline at end of file