Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab x #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

lab x #216

Show file tree
Hide file tree
Changes from all commits
Commits
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 not shown.
Binary file modified Labs/lab-SQL/Lab-SQLite/app.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions Labs/lab-SQL/Lab-SQLite/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

class CustomerForm(Form):
company = StringField('company', validators=[DataRequired()])
email = EmailField('email', validators=[DataRequired()])

email = EmailField('email', validators=[DataRequired()])
11 changes: 10 additions & 1 deletion Labs/lab-SQL/Lab-SQLite/app/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
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
10 changes: 9 additions & 1 deletion Labs/lab-SQL/Lab-SQLite/app/templates/customer.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ <h2>Add Customer to Our Database</h2>
<div class="divider"></div>
<div class="section">
<!--add input fields-->
<p>
Company name:<br>
{{form.company(size=120)}}<br>
</p>
<p>
Customer email:<br>
{{form.email(size=120)}}<br>
</p>
</div>
<div class="divider"></div>
<div class="section">
Expand All @@ -20,4 +28,4 @@ <h2>Add Customer to Our Database</h2>
</form>
</div>
</div>
{% endblock %}
{% endblock %}
8 changes: 7 additions & 1 deletion Labs/lab-SQL/Lab-SQLite/app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ <h3>These are all of our awesome customers:</h3>
</tr>
</thead>
<!-- code to display all user -->
{% for customer in customers %}
<tr>
<td> {{customer['company']}} </td>
<td> {{customer['email']}} </td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
5 changes: 5 additions & 0 deletions Labs/lab-SQL/Lab-SQLite/app/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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


Expand All @@ -14,11 +15,15 @@ def create_customer():
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
customers = models.retrieve_customers()
return render_template('home.html',
customers=customers)
7 changes: 7 additions & 0 deletions Labs/lab-SQL/Lab-SQLite/schema.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
-- 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 non null
);
Binary file modified Labs/lab-SQL/Pokemon.db
Binary file not shown.