-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_atlas.py
119 lines (91 loc) · 3.43 KB
/
app_atlas.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
from flask import Flask, render_template, request
from pymongo import MongoClient
from pprint import pprint
app = Flask(__name__)
import os
# connString = os.environ["MONGODB_CONNSTRING"]
connString = "mongodb://localhost:27017"
client = MongoClient(connString)
db = client.test
storage = db.storage
# storage.drop()
# exit()
def database_new_entry(new_result):
global storage
if storage.find({"Name": new_result["Name"]}).count() > 0:
avaliability_flag = True
print("Trying to overwrite issue")
exit()
student_details = {"Name": new_result["Name"], "grds": new_result}
entry_status = storage.insert_one(student_details)
return entry_status
def database_update_entry(key_val, new_result):
global storage
entry_status = storage.update_one({"Name": key_val}, {"$set": {"grds": new_result}})
print("inside database_update_entry", key_val, new_result)
return entry_status
data = {}
# data['Headings']=
@app.route("/")
def student():
return render_template("student.html")
@app.route("/result", methods=["POST", "GET"])
def result():
if request.method == "POST":
result = request.form
print(result)
print(result["Name"])
global data
if storage.find({"Name": result["Name"]}).count() > 0:
avaliability_flag = True
Queryresult = storage.find_one({"Name": result["Name"]})
pass_dict = Queryresult["grds"]
else:
avaliability_flag = False
print("Check if key available: ", avaliability_flag)
print("checking db existance")
if avaliability_flag == False: # not (result['Name'] in data.keys()):
data[result["Name"]] = result
print("data", data)
print("result['Name']", data[result["Name"]])
entry_status = database_new_entry(result)
return render_template("result.html", result=result)
else:
return render_template("edit.html", result=result, old_result=pass_dict)
@app.route("/update", methods=["POST", "GET"])
def update():
result = request.form
print("result from updater", result)
global data
name_var = result["Name"]
print("name_var", type(name_var), name_var)
name_var_without_padding = name_var[1:-1]
data[name_var_without_padding] = result
update_status = database_update_entry(name_var_without_padding, result)
print("Final result:::::::", result)
return render_template("student.html")
@app.route("/fulllist", methods=["GET"])
def fulllist():
print("Into full list===========")
global data
tl = [" Student Name ", " Physics ", " Chemistry ", " Mathematics "]
global db
coll1 = db.storage # selecting the coll1 in myDatabase
mod_dict = {}
for document in coll1.find():
print("database", document)
print("split", document["Name"], document["grds"])
mod_dict[document["Name"]] = document["grds"]
return render_template("print.html", dict=mod_dict, headings=tl)
@app.route("/studenteditlink/<string:iname>", methods=["GET"])
def studenteditlink(iname):
# name_var=data[iname]
global storage
Queryresult = storage.find_one({"Name": iname})
print("Queryresult:::")
pprint(Queryresult)
pass_dict = Queryresult["grds"]
print("pass_dict", pass_dict)
return render_template("editstudent.html", sname=iname, obj=pass_dict)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)