-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
294 lines (252 loc) · 10.2 KB
/
app.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
from os import path
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///dote.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
# Index Page Table
class Login(db.Model): #type: ignore
sno = db.Column(db.Integer, primary_key = True, autoincrement = True)
fullname = db.Column(db.String(50), nullable = True)
email = db.Column(db.String(50), nullable = True)
password = db.Column(db.String(50), nullable = True)
def __repr__(self) -> str:
return f"{self.fullname} - {self.email} - {self.password}"
# Feedback Page Table
class Feedback(db.Model): #type: ignore
sno = db.Column(db.Integer, primary_key = True, autoincrement = True)
fname = db.Column(db.String(20), nullable = True)
lname = db.Column(db.String(20), nullable = True)
phone = db.Column(db.Integer, nullable = True)
emailID = db.Column(db.String(50), nullable = True)
message = db.Column(db.Text, nullable = True)
address = db.Column(db.String(500), nullable = True)
def __repr__(self) -> str:
return f"""
Name: {self.fname} {self.lname} -
Phone {self.phone} -
Email: {self.emailID} -
Message: {self.message} -
Address: {self.address}
"""
# Checkout Page Table
class Checkout(db.Model): #type: ignore
sno = db.Column(db.Integer, primary_key = True, autoincrement = True)
name = db.Column(db.String(50), nullable = True)
phone = db.Column(db.Integer, nullable = True)
address = db.Column(db.String(500), nullable = True)
product = db.Column(db.String(100), nullable = True)
def __repr__(self) -> str:
return f"{self.name} - {self.phone} - {self.address} - {self.product}"
# Index Page / Sign-up Page
@app.route("/")
@app.route("/sign-up", methods=["GET","POST"])
def signup():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("sign_up.html", allLogin = allLogin)
app.add_url_rule("/sign_up", "signup", signup)
# Log In Page
@app.route("/login", methods=["GET","POST"])
def login():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("login.html", allLogin = allLogin)
app.add_url_rule("/login", "login", login)
# Homepage
@app.route("/homepage", methods=["GET","POST"])
def homepage():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("homepage.html", allLogin = allLogin)
app.add_url_rule("/homepage", "homepage", homepage)
# Products Page
def products():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
if request.method == "POST":
fname = request.form["fname"]
lname = request.form["lname"]
emailID = request.form["emailID"]
phone = request.form["phone"]
message = request.form["message"]
feedback = Feedback(fname = fname, lname = lname, emailID = emailID, phone = phone, message = message)
db.session.add(feedback)
db.session.commit()
allLogin = Login.query.all()
allFeedback = Feedback.query.all()
return render_template("/products.html", allLogin = allLogin, allFeedback = allFeedback)
app.add_url_rule("/products", "products", products)
# Contact Page
@app.route("/contact", methods=["GET","POST"])
def contact():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
if request.method == "POST":
fname = request.form["fname"]
lname = request.form["lname"]
emailID = request.form["emailID"]
phone = request.form["phone"]
message = request.form["message"]
feedback = Feedback(fname = fname, lname = lname, emailID = emailID, phone = phone, message = message)
db.session.add(feedback)
db.session.commit()
allLogin = Login.query.all()
allFeedback = Feedback.query.all()
return render_template("/contact.html", allLogin = allLogin, allFeedback = allFeedback)
app.add_url_rule("/contact", "contact", contact)
# About Page
def aboutus():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("/aboutus.html", allLogin = allLogin)
app.add_url_rule("/aboutus", "about", aboutus)
# Google Page
def google():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("/googledetails.html", allLogin = allLogin)
app.add_url_rule("/googledetails", "google", google)
# iPhone Page
def iphone():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("/iphonedetails.html", allLogin = allLogin)
app.add_url_rule("/iphonedetails", "iphone", iphone)
# Oneplus Page
def oneplus():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("/oneplusdetails.html", allLogin = allLogin)
app.add_url_rule("/oneplusdetails", "oneplus", oneplus)
# Cart Page
def cart_page():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
allLogin = Login.query.all()
return render_template("/cart-page.html", allLogin = allLogin )
app.add_url_rule("/cart-page", "cart_page", cart_page)
# Checkout Page
@app.route("/checkout", methods=["GET","POST"])
def checkout():
if request.method == "POST":
fullname = request.form["fullname"]
email = request.form["email"]
password = request.form["password"]
login = Login(fullname = fullname, email = email, password = password)
db.session.add(login)
db.session.commit()
if request.method == "POST":
name = request.form["name"]
phone = request.form["phone"]
address = request.form["address"]
product = 'Oneplus 10r Skin'
checkout = Checkout(name = name, phone = phone, address = address, product = product)
db.session.add(checkout)
db.session.commit()
allLogin = Login.query.all()
allCheckout = Checkout.query.all()
return render_template("/checkout-page.html", allLogin = allLogin, allCheckout = allCheckout)
app.add_url_rule("/checkout-page", "checkout", checkout)
@app.route("/tp1", methods=["GET","POST"])
def tp1():
if request.method == "POST":
fname = request.form["fname"]
lname = request.form["lname"]
emailID = request.form["emailID"]
phone = request.form["phone"]
message = request.form["message"]
feedback = Feedback(fname = fname, lname = lname, emailID = emailID, phone = phone, message = message)
db.session.add(feedback)
db.session.commit()
allFeedback = Feedback.query.all()
return render_template("/tp1.html", allFeedback = allFeedback)
app.add_url_rule("/tp1", "tp1", tp1)
@app.route("/tp2", methods=["GET","POST"])
def tp2():
if request.method == "POST":
name = request.form.get("name")
# name = request.form["name"]
phone = request.form["phone"]
address = request.form["address"]
product = 'Oneplus 10r Skin'
checkout = Checkout(name = name, phone = phone, address = address, product = product)
db.session.add(checkout)
db.session.commit()
allCheckout = Checkout.query.all()
return render_template("/tp2.html", allCheckout = allCheckout)
app.add_url_rule("/tp2", "tp2", tp2)
@app.route("/delete")
def delete():
db.session.query(Login).delete()
db.session.commit()
return redirect("/")
# Deployment
if __name__ == "__main__":
if not path.exists("./instace/dote.db"):
app.app_context().push()
db.create_all()
# Creating database if it doesn't exist
else:
pass
# Ignoring the query as database already exists
# app.run(debug = False, host = '0.0.0.0')
app.run(debug = False, host = '0.0.0.0', port = 6969)