diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1-instructions.docx b/Labs/Lab8-Flask_Simple_Form/lab-flask1-instructions.docx new file mode 100644 index 0000000..0d2c42a Binary files /dev/null and b/Labs/Lab8-Flask_Simple_Form/lab-flask1-instructions.docx differ diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1.zip b/Labs/Lab8-Flask_Simple_Form/lab-flask1.zip new file mode 100644 index 0000000..9f51ded Binary files /dev/null and b/Labs/Lab8-Flask_Simple_Form/lab-flask1.zip differ diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__init__.py b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__init__.py new file mode 100755 index 0000000..1335f75 --- /dev/null +++ b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__init__.py @@ -0,0 +1,4 @@ +from flask import Flask + +myapp = Flask(__name__) +from app import views diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/__init__.cpython-35.pyc b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..3edcb6d Binary files /dev/null and b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/views.cpython-35.pyc b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..422e4f1 Binary files /dev/null and b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/__pycache__/views.cpython-35.pyc differ diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/views.py b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/views.py new file mode 100755 index 0000000..e674a1a --- /dev/null +++ b/Labs/Lab8-Flask_Simple_Form/lab-flask1/app/views.py @@ -0,0 +1,9 @@ +from app import myapp +from flask import request,render_template + +@myapp.route('/') +@myapp.route('/index') +def index(): + print("This is a log ..comes on your console") + return "Hello - this the page for your form !!" + diff --git a/Labs/Lab8-Flask_Simple_Form/lab-flask1/runserver.py b/Labs/Lab8-Flask_Simple_Form/lab-flask1/runserver.py new file mode 100755 index 0000000..20545ec --- /dev/null +++ b/Labs/Lab8-Flask_Simple_Form/lab-flask1/runserver.py @@ -0,0 +1,2 @@ +from app import myapp +myapp.run(debug=True) diff --git a/Labs/Lab9-Flask_Survey/Flask Lab 2.docx b/Labs/Lab9-Flask_Survey/Flask Lab 2.docx new file mode 100644 index 0000000..61f5f2f Binary files /dev/null and b/Labs/Lab9-Flask_Survey/Flask Lab 2.docx differ diff --git a/Labs/Lab9-Flask_Survey/Flask Lab 2.txt b/Labs/Lab9-Flask_Survey/Flask Lab 2.txt new file mode 100644 index 0000000..661dc9b --- /dev/null +++ b/Labs/Lab9-Flask_Survey/Flask Lab 2.txt @@ -0,0 +1,46 @@ +Flask Lab 2 +In this lab weÕll be implementing a simple survey web app using Flask. +The general concepts weÕll be covering are: +* Routing +* Templating +* Passing Parameters +* Sessions +We will walk through this lab in class and for homework you should redesign the questions and the survey and get creative. Also, make the e-mail link work and send the survey results to us! +Requirements +1. Download the flaskLab2.zip file from bCourses>Files>Labs +Creating a login page +2. Open the Ôlogin.htmlÕ template in your text editor +a. Make this file an extension of the Ôbase.htmlÕ template +b. Use the existing form and create form inputs that capture the userÕs name and email +c. Make sure the HTML in this file is replacing the block called ÔcontentÕ in the Ôbase.htmlÕ template +d. Make the form submit to the Ô/loginÕ endpoint +Creating a session +3. Open the Ôviews.pyÕ file in your text editor +a. Find the route for Ô/loginÕ +b. Within the Ôlogin()Õ function, if the request method is POST +i. set the sessionÕs ÔusernameÕ key to whatever the user entered for their username +ii. Redirect the user to the ÔindexÕ route +Extending and reusing content from the Ôbase.htmlÕ template for the Ôsurvey.htmlÕ template +4. Open the Ôsurvey.htmlÕ template in your text editor +a. Make this file an extension of the Ôbase.htmlÕ template +b. The HTML in this file for the form with the id of ÔlogoutÕ is currently replacing the entire contents of the
tag in the Ôbase.htmlÕ template. Using the super() function, pull in the original contents of the
tag from the Ôbase.htmlÕ template +c. Make sure the HTML in this file from the

and down is replacing the block called ÔcontentÕ in the Ôbase.htmlÕ template +Creating an Ajax request with the userÕs form inputs from Ôsurvey.htmlÕ +5. Open the Ôinteraction.jsÕ script in your text editor +a. Notice that the button from the Ôsurvey.htmlÕ template with the id Ôsubmit-surveyÕ has a click event binding +b. Also notice that there are variable declarations for each of the form input fields +c. Create a $.post() Ajax request within this ÔclickÕ event handler +i. The url for this Ajax request should point to Ôsubmit-surveyÕ +ii. The data parameter of this Ajax request should be an object whose key-value pairs correspond to the variables for each form input field +iii. The success function for this Ajax request should set the innerHTML of document.body.parentNode to the response data object +Rendering the survey results via Flask +6. Go back to the Ôviews.pyÕ file in your text editor +a. Find the route for Ô/submit-surveyÕ +b. YouÕll notice that an empty object has been assigned to the variable name ÔsurveyResponseÕ +c. YouÕll also notice that Ôfe-beforeÕ and Ôfe-afterÕ keys in the ÔsurveyResponseÕ object have been assigned values that correspond to values in the data object we passed in from step 5 above. +i. Assign the keys ÔcolorÕ, ÔfoodÕ, and ÔvacationÕ for the ÔsurveyResponseÕ object to corresponding values from the passed-in data object in a similar fashion +7. You should now be able to do the following: +a. Log into this simple survey web app with a username and email +b. Take the survey +c. See the survey results displayed + diff --git a/Labs/Lab9-Flask_Survey/flaskLab2.zip b/Labs/Lab9-Flask_Survey/flaskLab2.zip new file mode 100644 index 0000000..29f66dc Binary files /dev/null and b/Labs/Lab9-Flask_Survey/flaskLab2.zip differ diff --git a/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc new file mode 100644 index 0000000..5689024 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app.db b/Labs/lab-SQL/Lab-SQLite/app.db index a61b799..2a28894 100644 Binary files a/Labs/lab-SQL/Lab-SQLite/app.db and b/Labs/lab-SQL/Lab-SQLite/app.db differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..e373d42 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc new file mode 100644 index 0000000..19edfb1 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000..9145f4e Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..5501c75 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/models.py b/Labs/lab-SQL/Lab-SQLite/app/models.py index 9be98c2..2d28700 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/models.py +++ b/Labs/lab-SQL/Lab-SQLite/app/models.py @@ -1,7 +1,19 @@ import sqlite3 as sql -def insert_customer(): + +def insert_customer(company, email): # SQL statement to insert into database goes here + with sql.connect("app.db") as con: + cur = con.cursor() + cur.execute( + "INSERT INTO customers (company, email) VALUES (?, ?)", (company, email)) + con.commit() + 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-SQL/Lab-SQLite/app/templates/customer.html b/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html index 6e74a14..36c49b4 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html +++ b/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html @@ -11,6 +11,12 @@

Add Customer to Our Database

+

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

+

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

diff --git a/Labs/lab-SQL/Lab-SQLite/app/templates/home.html b/Labs/lab-SQL/Lab-SQLite/app/templates/home.html index e2216db..8f06a97 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/templates/home.html +++ b/Labs/lab-SQL/Lab-SQLite/app/templates/home.html @@ -17,6 +17,14 @@

These are all of our awesome customers:

+ + {% for customer in customers %} + + {{ customer['company']}} + {{ customer['email']}} + + {% endfor %} +
diff --git a/Labs/lab-SQL/Lab-SQLite/app/views.py b/Labs/lab-SQL/Lab-SQLite/app/views.py index 4fc2de6..da7cde1 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/views.py +++ b/Labs/lab-SQL/Lab-SQLite/app/views.py @@ -8,17 +8,23 @@ 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 + models.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 + # Retreive data from database to display + customers = models.retrieve_customers() return render_template('home.html', - customers=customers) + customers=customers) diff --git a/Labs/lab-SQL/Lab-SQLite/schema.sql b/Labs/lab-SQL/Lab-SQLite/schema.sql index f06fbdb..aa10b84 100644 --- a/Labs/lab-SQL/Lab-SQLite/schema.sql +++ b/Labs/lab-SQL/Lab-SQLite/schema.sql @@ -1,2 +1,8 @@ -- Insert code to create Database Schema -- This will create your .db database file for use +drop table if exists customers; +create table customers ( + customer_id integer primary key, + company text not null, + email text not null +); diff --git a/Labs/lab-SQL/Pokemon.db b/Labs/lab-SQL/Pokemon.db index 7fbc93f..0dd44fa 100644 Binary files a/Labs/lab-SQL/Pokemon.db and b/Labs/lab-SQL/Pokemon.db differ