-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
92 lines (70 loc) · 2.64 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
import os
from flask import Flask, render_template, redirect, request, url_for
from flask_pymongo import PyMongo
from bson.objectid import ObjectId
from os import path
if path.exists("env.py"):
import env
app = Flask(__name__)
app.config["MONGO_DBNAME"] = 'working_it_out'
app.config["MONGO_URI"] = os.environ.get('MONGO_URI')
mongo = PyMongo(app)
@app.route('/')
@app.route('/get_gyms')
def get_gyms():
return render_template("home.html", gyms=mongo.db.gyms.find())
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/add_new_gym")
def add_new_gym():
return render_template("add_gym.html")
# Sends the data that the user inserts to the database
@app.route("/insert_gym", methods=['POST'])
def insert_gym():
gym = mongo.db.gyms
gym.insert_one({
'gym_name': request.form.get('gym_name'),
'gym_type': request.form.get('gym_type'),
'gym_address':request.form.get('gym_address'),
'cost':request.form.get('cost'),
'gym_url':request.form.get('gym_url'),
})
return redirect(url_for('get_gyms'))
# Allows user to update information about a gym
@app.route("/edit_gym/<gym_id>")
def edit_gym(gym_id):
the_gym = mongo.db.gyms.find_one({"_id": ObjectId(gym_id)})
return render_template("update_gym.html", gym=the_gym)
@app.route("/update_gym/<gym_id>", methods=["POST"])
def update_gym(gym_id):
gym = mongo.db.gyms
gym.update({'_id': ObjectId(gym_id)}, {
'gym_name' : request.form.get('gym_name'),
'status' : request.form.get('gym_type'),
'address' : request.form.get('gym_address'),
'cost' : request.form.get('cost'),
'gym_url' : request.form.get('gym_url')
})
return redirect(url_for('get_gyms'))
# Delete option for a user if they wish to delete a review they wrote or delete a review written by someone else that may be incorrect
@app.route("/delete_gym/<gym_id>")
def delete_gym(gym_id):
mongo.db.gyms.remove({'_id': ObjectId(gym_id)})
return redirect(url_for('get_gyms'))
@app.route("/leave_review")
def gym_review():
return render_template("gym_review.html", gyms=mongo.db.gyms.find())
# Sends the data that the user inserts to the database
@app.route("/gym_review", methods=['POST'])
def insert_review():
review = mongo.db.reviews
review.insert_one(request.form.to_dict())
return redirect(url_for('gym_review'))
@app.route("/read_review")
def read_review():
return render_template("read_reviews.html", reviews=mongo.db.reviews.find())
if __name__ == '__main__':
app.run(host=os.environ.get('IP'),
port=int(os.environ.get('PORT')),
debug=True)