-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_app.py
122 lines (108 loc) · 3.83 KB
/
flask_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
import mysql.connector
from flask import Flask, render_template,request,session
import os
from decouple import config
import json
import requests
from order_manager import order
from user_validator import user
db =mysql.connector.connect(
host = config('HOST'),
user = config('USER'),
passwd = config('PASSWORD'),
database = config('DATABASE')
)
app = Flask(__name__)
class School:
def __init__(self, key, name, lat, lng):
self.key = key
self.name = name
self.lat = lat
self.lng = lng
app.config['SECRET_KEY'] = 'abc'
@app.route("/")
def index():
return render_template("login.html")
@app.route("/signup-link")
def signup():
return render_template("sign_up.html")
@app.route("/login-link")
def login():
return render_template("login.html")
@app.route("/user-validate", methods = ["POST","GET"])
def validate_user():
username = request.form['emailer']
password = request.form['pswrd']
decision = user.check_user(username,password)
if decision ==True:
data1 = order.get_order()
api_key= config('API_KEY')
session['Username'] = username
return render_template("map.html",data1=data1,api_key=api_key)
else:
return "invalid password or you need to sign up"
@app.route("/newuser-add", methods = ["POST","GET"])
def create_user():
username = request.form['emailer']
print(username)
password = request.form['pswrd']
does_user_exist = user.check_if_user_exists(username)
#print(does_user_exist)
if does_user_exist == False:
user.add_user(username,password)
data1 = order.get_order()
api_key= config('API_KEY')
session['Username'] = username
return render_template("map.html",data1=data1,api_key=api_key)
else:
return "Unfortunately a user with this name already exists please pick a new one....."
@app.route("/map")
def map_view():
data1 = order.get_order()
print(data1)
api_key= config('API_KEY')
return render_template("map.html", data1=data1,api_key=api_key)
@app.route("/view_orders")
def order_view():
name = session['Username']
user_order_info = order.get_order_specific_person(name)
return render_template("orders.html", data = user_order_info)
@app.route("/delete_order", methods=["POST"])
def delete_order():
final_data = []
delete_data = request.form['edit']
delete_data = delete_data.replace("(","")
delete_data = delete_data.replace(")","")
delete_data = delete_data.replace("'","")
print(delete_data)
delete_data = delete_data.split(',')
delete_data = list(delete_data)
first_half = delete_data[0:2]
secound_half = delete_data[4:7]
for things in first_half:
final_data.append(str(things))
for j in secound_half:
final_data.append(str(j))
#final_data.append(delete_data[4:7])
print(final_data)
a = order.delete_order(final_data[0].strip(),final_data[1].strip(),final_data[2].strip(),final_data[3].strip(),final_data[4].strip())
print(final_data[0],final_data[2],int(final_data[3]))
name = session['Username']
user_order_info = order.get_order_specific_person(name)
return render_template("orders.html", data = user_order_info)
@app.route("/deliveryform")
def deliveryform():
name = session['Username']
return render_template("deliveryform.html" , name = name)
@app.route("/deliverydata", methods = ['POST'])
def deliverydata():
name = session['Username']
address = request.form['Address']
Item = request.form['Item']
Price = request.form['price']
info = request.form['info']
order.add_order(name,address,Item,Price,info)
user_order_info = order.get_order_specific_person(name)
return render_template("orders.html", data = user_order_info)
if __name__ == '__main__':
app.run(host= '10.0.0.36',port=800, debug=True)