From 15f428f154823a7da89a9e95d80935877ca1ad50 Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Fri, 19 Feb 2016 15:47:52 -0800 Subject: [PATCH 1/4] hw5-skeleton --- javascript/hw5-skeleton.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 javascript/hw5-skeleton.js diff --git a/javascript/hw5-skeleton.js b/javascript/hw5-skeleton.js new file mode 100755 index 0000000..dbd277e --- /dev/null +++ b/javascript/hw5-skeleton.js @@ -0,0 +1,27 @@ +// Event hander for calling the SoundCloud API using the user's search query +function callAPI(query) { + $.get("https://api.soundcloud.com/tracks?client_id=b3179c0738764e846066975c2571aebb", + {'q': query, + 'limit': '200'}, + function(data) { + // PUT IN YOUR CODE HERE TO PROCESS THE SOUNDCLOUD API'S RESPONSE OBJECT + // HINT: CREATE A SEPARATE FUNCTION AND CALL IT HERE + },'json' + ); +} + +// 'Play' button event handler - play the track in the Stratus player +function changeTrack(url) { + // Remove any existing instances of the Stratus player + $('#stratus').remove(); + + // Create a new Stratus player using the clicked song's permalink URL + $.stratus({ + key: "b3179c0738764e846066975c2571aebb", + auto_play: true, + align: "bottom", + links: url + }); +} + + From 0a85df183e6ab126d8a32de59072e2de5f70b6ee Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 4 Mar 2016 07:04:46 +0000 Subject: [PATCH 2/4] adding gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a295864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__ From 2f1729cc309733f6c69a101f65a21dbb424fad0b Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 4 Mar 2016 07:06:14 +0000 Subject: [PATCH 3/4] adding flask ORM tutorial --- flask/app.db | Bin 0 -> 5120 bytes flask/app/__init__.py | 8 ++++++++ flask/app/forms.py | 7 +++++++ flask/app/models.py | 14 ++++++++++++++ flask/app/templates/base.html | 16 ++++++++++++++++ flask/app/templates/customer.html | 20 ++++++++++++++++++++ flask/app/templates/home.html | 29 +++++++++++++++++++++++++++++ flask/app/views.py | 25 +++++++++++++++++++++++++ flask/config.py | 8 ++++++++ flask/readme.md | 17 +++++++++++++++++ flask/requirements.txt | 10 ++++++++++ flask/run.py | 2 ++ flask/update_database.py | 3 +++ 13 files changed, 159 insertions(+) create mode 100644 flask/app.db create mode 100644 flask/app/__init__.py create mode 100644 flask/app/forms.py create mode 100644 flask/app/models.py create mode 100644 flask/app/templates/base.html create mode 100644 flask/app/templates/customer.html create mode 100644 flask/app/templates/home.html create mode 100644 flask/app/views.py create mode 100644 flask/config.py create mode 100644 flask/readme.md create mode 100644 flask/requirements.txt create mode 100644 flask/run.py create mode 100644 flask/update_database.py diff --git a/flask/app.db b/flask/app.db new file mode 100644 index 0000000000000000000000000000000000000000..9e480eca3f05f63f88e89a024f79bc5f8b5f3029 GIT binary patch literal 5120 zcmeH|%TB^T6o%(gZjCI|AYnnAjS+&k>e84{NTbApQo)23DKJX07o{bUB|MlfVd5L; z&Np!3v`H6AB(6+^ImtP5=FBvi|C`RtRb4eaN^YE?rF-NE2mnG*Bm@8uXC7f5n!pm@ zLxW*5r;UT%H5HZnptb5%alWSQkpUGNIIy}hxb!zE` zIa9sVDpgr)k#nU*az-zh*{oISO@-uwFY;o3Ux=p5SqKcfM<3k>lO2qL74-JlJ(+<5$P`KrHSF7g)3=MAAoYht zrWWBBfZti*#tCo&3qW84OK|oYKx?>=_;&vJ`@aC&%_S@;0sj6k>Be)}oWL9czkmNf E0r<_%WB>pF literal 0 HcmV?d00001 diff --git a/flask/app/__init__.py b/flask/app/__init__.py new file mode 100644 index 0000000..353d3af --- /dev/null +++ b/flask/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/flask/app/forms.py b/flask/app/forms.py new file mode 100644 index 0000000..9df763c --- /dev/null +++ b/flask/app/forms.py @@ -0,0 +1,7 @@ +from flask.ext.wtf import Form +from wtforms import StringField, BooleanField +from wtforms.validators import DataRequired + +class CustomerForm(Form): + company = StringField('company', validators=[DataRequired()]) + email = StringField('email', validators=[DataRequired()]) diff --git a/flask/app/models.py b/flask/app/models.py new file mode 100644 index 0000000..74ccebf --- /dev/null +++ b/flask/app/models.py @@ -0,0 +1,14 @@ +from app import db + + +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), unique=True) + + def __init__(self, company, email): + self.company = company + self.email = email + + def __repr__(self): + return '' % self.email diff --git a/flask/app/templates/base.html b/flask/app/templates/base.html new file mode 100644 index 0000000..ceb39d1 --- /dev/null +++ b/flask/app/templates/base.html @@ -0,0 +1,16 @@ + + + {% if title %} + {{ title }} - ACME + {% else %} + Welcome to ACME Aircraft Parts + {% endif %} + + + + + + + {% block content %}{% endblock %} + + diff --git a/flask/app/templates/customer.html b/flask/app/templates/customer.html new file mode 100644 index 0000000..7389fa0 --- /dev/null +++ b/flask/app/templates/customer.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} +{% block content %} +
+
+

Add Customer to Our Database

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

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

+

+ Please enter the user email:
+ {{ form.email(size=120) }}
+

+

+
+
+
+{% endblock %} diff --git a/flask/app/templates/home.html b/flask/app/templates/home.html new file mode 100644 index 0000000..55793aa --- /dev/null +++ b/flask/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 }}{{ customer.email }}
+
+
+
+{% endblock %} diff --git a/flask/app/views.py b/flask/app/views.py new file mode 100644 index 0000000..5b28a22 --- /dev/null +++ b/flask/app/views.py @@ -0,0 +1,25 @@ +from flask import render_template, redirect, request +from app import app, models, db +from .forms import CustomerForm + + +@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(): + new_customer = models.Customer(form.company.data, + form.email.data) + db.session.add(new_customer) + db.session.commit() + return redirect('/customers') + return render_template('customer.html', form=form) + +@app.route('/customers') +def display_customer(): + customers = models.Customer.query.all() + return render_template('home.html', + customers=customers) diff --git a/flask/config.py b/flask/config.py new file mode 100644 index 0000000..a995426 --- /dev/null +++ b/flask/config.py @@ -0,0 +1,8 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +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/flask/readme.md b/flask/readme.md new file mode 100644 index 0000000..23b7434 --- /dev/null +++ b/flask/readme.md @@ -0,0 +1,17 @@ +# Models Lab/Homework +Please work in your final project groups, this will help you get to know each other's strengths and weaknesses. If you are working on your final project alone, feel free to pair up with someone else or ask to join another group. + +The goal for this lab is to get you comfortable translating your database models into actual code. We will be using [ORMs](https://en.wikipedia.org/wiki/Object-relational_mapping) to help us. The particular ORM that we will be using is SQLAlchemy (the flask implementation is called Flask-SQLAlchemy). + +We'll walk through the example together in class which will give you an idea of how this all works together. Your goal for this lab and homework is to create the remaining models, forms, and routes to complete v1 of the exercise from last week. + +You must create the following tables: +* customer +* address + +You will need to create a one-to-many relationship between the customer and address table. Use the documentation [here](http://flask-sqlalchemy.pocoo.org/2.1/models/#one-to-many-relationships) for reference. + +## Helpful Documentation +- [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/2.1/) +- [Accessing SQLite3 Command Shell](https://www.sqlite.org/cli.html) +- [Flask-WTF](https://flask-wtf.readthedocs.org/en/latest/) (flask plugin for creating forms easily) diff --git a/flask/requirements.txt b/flask/requirements.txt new file mode 100644 index 0000000..bfbaf81 --- /dev/null +++ b/flask/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/flask/run.py b/flask/run.py new file mode 100644 index 0000000..5d2f714 --- /dev/null +++ b/flask/run.py @@ -0,0 +1,2 @@ +from app import app +app.run(debug=True, host="0.0.0.0", port=8081) diff --git a/flask/update_database.py b/flask/update_database.py new file mode 100644 index 0000000..b15e4da --- /dev/null +++ b/flask/update_database.py @@ -0,0 +1,3 @@ +from app import db +db.drop_all() +db.create_all() From 3b6c912f889b35461504a20069032c256807083a Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 4 Mar 2016 22:12:38 +0000 Subject: [PATCH 4/4] adding orm-tutorial --- flask/app.db | Bin 5120 -> 0 bytes flask/app/forms.py | 7 ---- flask/app/models.py | 14 -------- flask/app/templates/customer.html | 20 ------------ flask/orm-tutorial/models-tutorial/app.db | Bin 0 -> 9216 bytes .../models-tutorial}/app/__init__.py | 0 .../orm-tutorial/models-tutorial/app/forms.py | 9 ++++++ .../models-tutorial/app/models.py | 15 +++++++++ .../models-tutorial}/app/templates/base.html | 2 -- .../app/templates/customer.html | 30 ++++++++++++++++++ .../models-tutorial}/app/templates/home.html | 2 ++ .../models-tutorial}/app/views.py | 8 +++-- .../models-tutorial}/config.py | 0 flask/orm-tutorial/models-tutorial/readme.md | 21 ++++++++++++ .../models-tutorial}/requirements.txt | 0 .../{ => orm-tutorial/models-tutorial}/run.py | 0 .../models-tutorial}/update_database.py | 0 flask/readme.md | 17 ---------- 18 files changed, 82 insertions(+), 63 deletions(-) delete mode 100644 flask/app.db delete mode 100644 flask/app/forms.py delete mode 100644 flask/app/models.py delete mode 100644 flask/app/templates/customer.html create mode 100644 flask/orm-tutorial/models-tutorial/app.db rename flask/{ => orm-tutorial/models-tutorial}/app/__init__.py (100%) create mode 100644 flask/orm-tutorial/models-tutorial/app/forms.py create mode 100644 flask/orm-tutorial/models-tutorial/app/models.py rename flask/{ => orm-tutorial/models-tutorial}/app/templates/base.html (71%) create mode 100644 flask/orm-tutorial/models-tutorial/app/templates/customer.html rename flask/{ => orm-tutorial/models-tutorial}/app/templates/home.html (88%) rename flask/{ => orm-tutorial/models-tutorial}/app/views.py (71%) rename flask/{ => orm-tutorial/models-tutorial}/config.py (100%) create mode 100644 flask/orm-tutorial/models-tutorial/readme.md rename flask/{ => orm-tutorial/models-tutorial}/requirements.txt (100%) rename flask/{ => orm-tutorial/models-tutorial}/run.py (100%) rename flask/{ => orm-tutorial/models-tutorial}/update_database.py (100%) delete mode 100644 flask/readme.md diff --git a/flask/app.db b/flask/app.db deleted file mode 100644 index 9e480eca3f05f63f88e89a024f79bc5f8b5f3029..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5120 zcmeH|%TB^T6o%(gZjCI|AYnnAjS+&k>e84{NTbApQo)23DKJX07o{bUB|MlfVd5L; z&Np!3v`H6AB(6+^ImtP5=FBvi|C`RtRb4eaN^YE?rF-NE2mnG*Bm@8uXC7f5n!pm@ zLxW*5r;UT%H5HZnptb5%alWSQkpUGNIIy}hxb!zE` zIa9sVDpgr)k#nU*az-zh*{oISO@-uwFY;o3Ux=p5SqKcfM<3k>lO2qL74-JlJ(+<5$P`KrHSF7g)3=MAAoYht zrWWBBfZti*#tCo&3qW84OK|oYKx?>=_;&vJ`@aC&%_S@;0sj6k>Be)}oWL9czkmNf E0r<_%WB>pF diff --git a/flask/app/forms.py b/flask/app/forms.py deleted file mode 100644 index 9df763c..0000000 --- a/flask/app/forms.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask.ext.wtf import Form -from wtforms import StringField, BooleanField -from wtforms.validators import DataRequired - -class CustomerForm(Form): - company = StringField('company', validators=[DataRequired()]) - email = StringField('email', validators=[DataRequired()]) diff --git a/flask/app/models.py b/flask/app/models.py deleted file mode 100644 index 74ccebf..0000000 --- a/flask/app/models.py +++ /dev/null @@ -1,14 +0,0 @@ -from app import db - - -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), unique=True) - - def __init__(self, company, email): - self.company = company - self.email = email - - def __repr__(self): - return '' % self.email diff --git a/flask/app/templates/customer.html b/flask/app/templates/customer.html deleted file mode 100644 index 7389fa0..0000000 --- a/flask/app/templates/customer.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "base.html" %} -{% block content %} -
-
-

Add Customer to Our Database

-
- {{ form.hidden_tag() }} -

- Please enter the company name:
- {{ form.company(size=120) }}
-

-

- Please enter the user email:
- {{ form.email(size=120) }}
-

-

-
-
-
-{% endblock %} diff --git a/flask/orm-tutorial/models-tutorial/app.db b/flask/orm-tutorial/models-tutorial/app.db new file mode 100644 index 0000000000000000000000000000000000000000..41839c5d7dc60a4b2c021d493facebb3bac8fa5a GIT binary patch literal 9216 zcmeI1L2uJA6vyp2TWL@)pst#xN#=lPRLW>~nKXgg6>n5@8B1HFouaJqXdr1INhNmd zz6xi)0#`l&5|@c1y>a5Y19oV{wo1KB9B7}T=Vw31()<4sCraEtY`HO~Cqd}jG2KKe z!Wh*kMF^FJWhbTze@~e7X~Ah@hA*S?SjmwKq~b9mPsmq1RzBg6_`5u2%u9#J1%8^g z7u5@TUv8*<^i0hZ*4FTu72C%iw;d8rZgcwRS)mFi<%j`fC79QZu6{?3)*mu7RnZXVGW?1&a! zCpmTZz+}xmL&l1irs>pVyUb)pgSBZIPbO*lD7Ta;tgqvdpU6l@Q?FhTl167J=>`5f zdvH3Xg8R1XO+~MZ5c%B2nL<8~&$3BA!-$8{lq-42$UnAz~LXF_nuhamOYGvq;JV|tct9OxT(~fs1))UksqRh0tA4-e?;KEqM}lz74+Wr zId|y39meh;vOVv#=Joxg_eebCRl38wkuJffey_uz{IWwj<}nc9eM(4w`@f5C8%|00;m9AOHk_01%i-K<)+J5|$CR UEKKh6U*78%T_`{R2+SLS-|?FD' % self.email + +# Your Address code should go here +# class Address(db.Model): diff --git a/flask/app/templates/base.html b/flask/orm-tutorial/models-tutorial/app/templates/base.html similarity index 71% rename from flask/app/templates/base.html rename to flask/orm-tutorial/models-tutorial/app/templates/base.html index ceb39d1..db51f24 100644 --- a/flask/app/templates/base.html +++ b/flask/orm-tutorial/models-tutorial/app/templates/base.html @@ -7,8 +7,6 @@ {% endif %} - - {% block content %}{% endblock %} diff --git a/flask/orm-tutorial/models-tutorial/app/templates/customer.html b/flask/orm-tutorial/models-tutorial/app/templates/customer.html new file mode 100644 index 0000000..d7b457a --- /dev/null +++ b/flask/orm-tutorial/models-tutorial/app/templates/customer.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} +{% block content %} +
+
+ +

Add Customer to Our Database

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

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

+

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

+
+
+
+ +
+

+
+
+
+{% endblock %} diff --git a/flask/app/templates/home.html b/flask/orm-tutorial/models-tutorial/app/templates/home.html similarity index 88% rename from flask/app/templates/home.html rename to flask/orm-tutorial/models-tutorial/app/templates/home.html index 55793aa..6b447ec 100644 --- a/flask/app/templates/home.html +++ b/flask/orm-tutorial/models-tutorial/app/templates/home.html @@ -17,6 +17,8 @@

These are all of our awesome customers:

{% for customer in customers %} + {{ customer.company }} {{ customer.email }} diff --git a/flask/app/views.py b/flask/orm-tutorial/models-tutorial/app/views.py similarity index 71% rename from flask/app/views.py rename to flask/orm-tutorial/models-tutorial/app/views.py index 5b28a22..e49db4f 100644 --- a/flask/app/views.py +++ b/flask/orm-tutorial/models-tutorial/app/views.py @@ -11,9 +11,11 @@ def index(): def create_customer(): form = CustomerForm() if form.validate_on_submit(): - new_customer = models.Customer(form.company.data, - form.email.data) - db.session.add(new_customer) + customer = models.Customer( + company = form.company.data, + email = form.email.data) + # you will need to add Address here + db.session.add(customer) db.session.commit() return redirect('/customers') return render_template('customer.html', form=form) diff --git a/flask/config.py b/flask/orm-tutorial/models-tutorial/config.py similarity index 100% rename from flask/config.py rename to flask/orm-tutorial/models-tutorial/config.py diff --git a/flask/orm-tutorial/models-tutorial/readme.md b/flask/orm-tutorial/models-tutorial/readme.md new file mode 100644 index 0000000..f5a8d70 --- /dev/null +++ b/flask/orm-tutorial/models-tutorial/readme.md @@ -0,0 +1,21 @@ +# Models Lab/Homework +The goal for this lab is to get you comfortable translating your database models into actual code. We will be using [ORMs](https://en.wikipedia.org/wiki/Object-relational_mapping) to help us. The particular ORM that we will be using is SQLAlchemy (the flask implementation is called [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/2.1/)). + +We'll walk through the example together in class which will give you an idea of how this all works together. Your goal for this lab and homework is to create the remaining models, forms, and routes to complete v2 of the exercise from last week. + +This means that you must: +* Create the following tables and the appropriate relationships: + * customer + * address + * order + * Remember to run update_database.py whenever you make changes to any models. + * This will update the database with your changes. However, **it will delete any data in the database**. +* Create the forms, templates, routes, etc necessary to input this data into the database. +* Create a view to showcase the data into your database (see the current implementation of "home.html" for example) + +The following documentation will help answer any questions you may have. + +## Helpful Documentation +- [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/2.1/) +- [Accessing SQLite3 Command Shell](https://www.sqlite.org/cli.html) +- [Flask-WTF](https://flask-wtf.readthedocs.org/en/latest/) (flask plugin for creating forms easily) diff --git a/flask/requirements.txt b/flask/orm-tutorial/models-tutorial/requirements.txt similarity index 100% rename from flask/requirements.txt rename to flask/orm-tutorial/models-tutorial/requirements.txt diff --git a/flask/run.py b/flask/orm-tutorial/models-tutorial/run.py similarity index 100% rename from flask/run.py rename to flask/orm-tutorial/models-tutorial/run.py diff --git a/flask/update_database.py b/flask/orm-tutorial/models-tutorial/update_database.py similarity index 100% rename from flask/update_database.py rename to flask/orm-tutorial/models-tutorial/update_database.py diff --git a/flask/readme.md b/flask/readme.md deleted file mode 100644 index 23b7434..0000000 --- a/flask/readme.md +++ /dev/null @@ -1,17 +0,0 @@ -# Models Lab/Homework -Please work in your final project groups, this will help you get to know each other's strengths and weaknesses. If you are working on your final project alone, feel free to pair up with someone else or ask to join another group. - -The goal for this lab is to get you comfortable translating your database models into actual code. We will be using [ORMs](https://en.wikipedia.org/wiki/Object-relational_mapping) to help us. The particular ORM that we will be using is SQLAlchemy (the flask implementation is called Flask-SQLAlchemy). - -We'll walk through the example together in class which will give you an idea of how this all works together. Your goal for this lab and homework is to create the remaining models, forms, and routes to complete v1 of the exercise from last week. - -You must create the following tables: -* customer -* address - -You will need to create a one-to-many relationship between the customer and address table. Use the documentation [here](http://flask-sqlalchemy.pocoo.org/2.1/models/#one-to-many-relationships) for reference. - -## Helpful Documentation -- [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/2.1/) -- [Accessing SQLite3 Command Shell](https://www.sqlite.org/cli.html) -- [Flask-WTF](https://flask-wtf.readthedocs.org/en/latest/) (flask plugin for creating forms easily)