-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapp.py
94 lines (81 loc) · 3.25 KB
/
myapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from flask import Flask, render_template,request
import psycopg2
import os
app = Flask(__name__)
def database_connection():
connect = psycopg2.connect("dbname=digitalmusic user=postgres password=########", host="127.0.0.1", port="5432")
return connect
@app.route("/", methods=['GET', 'POST'])
def homeresults():
if request.method == 'POST':
sql_query = request.form['sql_query']
#sql = f'select * from albums where artist={sql_query}'
if(sql_query[0]=='s'):
connect = database_connection()
cursor = connect.cursor()
cursor.execute(sql_query)
results = cursor.fetchall()
#connect.commit()
cursor.close()
connect.close()
return render_template('homepage.html',results=results,cur=cursor)
else:
connect = database_connection()
cursor = connect.cursor()
cursor.execute(sql_query)
#results = cursor.fetchall()
connect.commit()
cursor.close()
connect.close()
#return render_template('homepage.html',results=results,cur=cursor)
return render_template('homepage.html')
else:
return render_template('homepage.html')
@app.route("/albums", methods=['GET','POST'])
def albums():
if request.method == 'POST':
sql_query = request.form['sql_query']
#text = '{sql_query}'
sql = f"""select * from album where artistid = (select artistid from artist where name = '%s')""" %(sql_query)
connect = database_connection()
cursor = connect.cursor()
cursor.execute(sql)
results = cursor.fetchall()
cursor.close()
connect.close()
return render_template('albums.html',results=results,cur=cursor)
else:
return render_template('albums.html')
@app.route("/shop", methods=['GET','POST'])
def shop():
if request.method == 'POST':
firstname = request.form['firstname']
lastname= request.form['lastname']
#print(request.form)
address= request.form['address']
postalcode= request.form['postalcode']
phonenumber= request.form['phonenumber']
email= request.form['email']
albumname = request.form['albumname']
#customerid = 60
#print(firstname, lastname)
#text = '{sql_query}'
#sql = f"""select * from album where artistid = (select artistid from artist where name = {sql_query})"""
sql = f""" insert into customer(firstname , lastname, address, postalcode,phone,email) values ('%s','%s','%s','%s','%s','%s')""" %(firstname,lastname,address,postalcode,phonenumber,email)
connect = database_connection()
cursor = connect.cursor()
cursor.execute(sql)
#results = cursor.fetchall()
#results = f"""Hurray! Your Oder for {albumname} has been recieved"""
connect.commit()
cursor.close()
connect.close()
results = f"""We have recived your order for %s""" %(albumname)
return render_template('shopsuccess.html',results = results)
else:
return render_template('shop.html')
@app.route("/team")
def team():
return render_template('team.html')
if __name__ == "__main__":
app.run()