binaychandra commited on
Commit
72ae777
·
1 Parent(s): 56441cb

changed session things

Browse files
Files changed (1) hide show
  1. app.py +14 -34
app.py CHANGED
@@ -26,6 +26,7 @@ import time
26
  import json
27
 
28
  app = Flask(__name__, static_url_path='/static')
 
29
  # Set secret key
30
  app.config['SECRET_KEY'] = 'faith'
31
  app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=60)
@@ -145,7 +146,7 @@ def load_badges():
145
  def load_workforce():
146
  # con = sqlite3.connect("database.db")
147
  # df = pd.read_sql_query(f"SELECT * from workforce", con)
148
- df = pd.read_csv(r"referencefiles\workforce.csv")
149
  no_rows, no_cols = df.shape
150
  n_gui = df.GUI.nunique() if 'GUI' in df.columns else 'GUI not Found'
151
 
@@ -155,7 +156,7 @@ def load_workforce():
155
  json_empdist = get_wfrankwise_countmom()
156
  lst_topfive_dept = get_lst_topdepartment()
157
  json_rankwise_empdist = get_wfrankwise_count()
158
- tbl_selected = session.get('tbl_selected', []) #['Badges', 'learning']
159
  gpt_response = summary_extractor_from_df("""{"male": 56, "female": 44 }""")
160
 
161
  return render_template("validate_workforce.html",
@@ -212,18 +213,14 @@ def get_bot_valresponse():
212
  @app.route("/data", methods=['POST'])
213
  def data():
214
  tbl_htmls = {}
215
- firsttable = ""
216
- slsslinfo = session.get("sl_subsl")
217
- tbl_selected = session.get('tbl_selected', [])
218
  print("-------------------------Hello world------------------------")
219
  print(tbl_selected)
220
- for i, tblname in enumerate(tbl_selected):
221
- if i == 1:
222
- firsttable == tblname
223
  # Read sqlite query results into a pandas DataFrame
224
  # con = sqlite3.connect("database.db")
225
  # df = pd.read_sql_query(f"SELECT * from {tblname}", con)
226
- filepath = f".referencefiles/{tblname}.csv"
227
  df = pd.read_csv(filepath)
228
  top_records = df.copy()
229
  # con.close()
@@ -231,7 +228,7 @@ def data():
231
  html_top_records = html_top_records.replace('<thead>', '<thead class="thead-light" style="top: 0;position: sticky;">')
232
  tbl_htmls[tblname] = html_top_records
233
 
234
- return render_template('data.html', table_htmls = tbl_htmls, tempdisplay = slsslinfo, req_tables = json.dumps(firsttable))
235
 
236
  @app.route("/", methods=['GET', 'POST'])
237
  @app.route("/home", methods=['GET', 'POST'])
@@ -239,30 +236,13 @@ def hometest():
239
  if request.method == 'GET':
240
  return render_template('home.html')
241
  elif request.method == 'POST':
242
- session['start_date'] = request.form.get('calendar_value').split(":")[0]
243
- session['end_date'] = request.form.get('calendar_value').split(":")[1]
244
- session['sl_subsl'] = request.form.get('sl_subsl')
245
- session['tbl_selected'] = request.form.getlist('tbl_selected')
246
- # return redirect(url_for('data'))
247
- tbl_htmls = {}
248
- slsslinfo = request.form.get('sl_subsl')
249
- tbl_selected = request.form.getlist('tbl_selected')
250
- print("-------------------------Hello world------------------------")
251
- print(tbl_selected)
252
- for tblname in tbl_selected:
253
- # Read sqlite query results into a pandas DataFrame
254
- # con = sqlite3.connect("database.db")
255
- # df = pd.read_sql_query(f"SELECT * from {tblname}", con)
256
- filepath = f"referencefiles/{tblname}.csv"
257
- df = pd.read_csv(filepath)
258
- top_records = df.copy()
259
- # con.close()
260
- html_top_records = top_records.to_html(index=False, table_id= f'dtable_{tblname}', classes='display nowrap table table-bordered table-striped table-condensed small p-1', justify='left')
261
- html_top_records = html_top_records.replace('<thead>', '<thead class="thead-light" style="top: 0;position: sticky;">')
262
- tbl_htmls[tblname] = html_top_records
263
-
264
- return render_template('data.html', table_htmls = tbl_htmls, tempdisplay = slsslinfo, req_tables = json.dumps(tbl_selected[0]))
265
-
266
 
267
  # if __name__ == '__main__':
268
  # app.run(debug=True)
 
26
  import json
27
 
28
  app = Flask(__name__, static_url_path='/static')
29
+ request_info = {}
30
  # Set secret key
31
  app.config['SECRET_KEY'] = 'faith'
32
  app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=60)
 
146
  def load_workforce():
147
  # con = sqlite3.connect("database.db")
148
  # df = pd.read_sql_query(f"SELECT * from workforce", con)
149
+ df = pd.read_csv(r"referencefiles/workforce.csv")
150
  no_rows, no_cols = df.shape
151
  n_gui = df.GUI.nunique() if 'GUI' in df.columns else 'GUI not Found'
152
 
 
156
  json_empdist = get_wfrankwise_countmom()
157
  lst_topfive_dept = get_lst_topdepartment()
158
  json_rankwise_empdist = get_wfrankwise_count()
159
+ tbl_selected = request_info.get('tbl_selected', []) #['Badges', 'learning']
160
  gpt_response = summary_extractor_from_df("""{"male": 56, "female": 44 }""")
161
 
162
  return render_template("validate_workforce.html",
 
213
  @app.route("/data", methods=['POST'])
214
  def data():
215
  tbl_htmls = {}
216
+ tbl_selected = request_info.get('tbl_selected', [])
 
 
217
  print("-------------------------Hello world------------------------")
218
  print(tbl_selected)
219
+ for tblname in tbl_selected:
 
 
220
  # Read sqlite query results into a pandas DataFrame
221
  # con = sqlite3.connect("database.db")
222
  # df = pd.read_sql_query(f"SELECT * from {tblname}", con)
223
+ filepath = f"referencefiles/{tblname}.csv"
224
  df = pd.read_csv(filepath)
225
  top_records = df.copy()
226
  # con.close()
 
228
  html_top_records = html_top_records.replace('<thead>', '<thead class="thead-light" style="top: 0;position: sticky;">')
229
  tbl_htmls[tblname] = html_top_records
230
 
231
+ return render_template('data.html', table_htmls = tbl_htmls, req_tables = json.dumps(tbl_selected[0]))
232
 
233
  @app.route("/", methods=['GET', 'POST'])
234
  @app.route("/home", methods=['GET', 'POST'])
 
236
  if request.method == 'GET':
237
  return render_template('home.html')
238
  elif request.method == 'POST':
239
+ global request_info
240
+ request_info['start_date'] = request.form.get('calendar_value').split(":")[0]
241
+ request_info['end_date'] = request.form.get('calendar_value').split(":")[1]
242
+ request_info['sl_subsl'] = request.form.get('sl_subsl')
243
+ request_info['tbl_selected'] = request.form.getlist('tbl_selected')
244
+ return redirect(url_for('data'))
245
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  # if __name__ == '__main__':
248
  # app.run(debug=True)