Opted for timeout/inactivity to clear the session rather than closing the tab/window. That should do for the time being. Need to add the client path sessions to when the ession is created. Currently, it will only delete the old files if the user clicks templates first. If they don't and files exist... they may not get deleted.

This commit is contained in:
Norm Rasmussen
2023-03-17 17:22:18 -04:00
parent b0addb6475
commit 7630cb80aa
15 changed files with 62 additions and 755 deletions

View File

@ -5,9 +5,9 @@ app = Flask(__name__)
app.config.from_object(Config)
# Upload folder
UPLOAD_FOLDER = "/Users/normrasmussen/Documents/Projects/CSM_webapp/app/static/files"
#UPLOAD_FOLDER = "/Users/normrasmussen/Documents/Projects/CSM_webapp/app/static/files"
# UPLOAD_FOLDER = 'static/files'
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
ALLOWED_EXTENSIONS = {"csv"}
#app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
#ALLOWED_EXTENSIONS = {"csv"}
from app import routes, forms
from app import routes

View File

@ -1,76 +0,0 @@
@app.route("/get_courses", methods=["GET", "POST"])
def get_courses():
array = []
course_dict = {}
pd.set_option("display.max_colwidth", 100)
count = 0
dataframe = pd.DataFrame()
if request.method == "POST":
while True:
count += 1
endpoint = f"v2/courses?page={count}"
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
response = requests.get(url + endpoint, headers=headers)
data = response.json()
nextlink = data["links"]
for response in data["data"]:
uuid = response["id"]
course_dict = {"id": uuid}
for keys, values in response["attributes"].items():
course_dict[keys] = values
array.append(course_dict)
dataframe = pd.DataFrame(array).drop(
["list_image_url", "permalink"], axis=1
)
dataframe["full_description"] = dataframe[
"full_description"
].str.replace(r"<[^<>]*>", "", regex=True)
print(dataframe)
if "next" not in nextlink:
break
dfcourse = dataframe.to_html()
session["dfcsv"] = dataframe.to_csv()
return render_template("get.html", table=dfcourse, title="List of Courses")
else:
return "This isn't working. Let's go our own way."
@app.route("/get_people", methods=["GET", "POST"])
def get_people():
array = []
ppl_dict = {}
count = 0
dataframe = pd.DataFrame()
if request.method == "POST":
print("get People POST")
while True:
count += 1
endpoint = f"v2/people?page={count}"
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
response = requests.get(url + endpoint, headers=headers)
data = response.json()
nextlink = data["links"]
for response in data["data"]:
uuid = response["id"]
ppl_dict = {"id": uuid}
for keys, values in response["attributes"].items():
ppl_dict[keys] = values
array.append(ppl_dict)
dataframe = pd.DataFrame(array).drop("custom_avatar_url", axis=1)
print(dataframe)
if "next" not in nextlink:
break
dfppl = dataframe.to_html()
session["dfcsv"] = dataframe.to_csv()
return render_template("get.html", table=dfppl, title="List of People")
else:
return render_template("get.html", error="Something went wrong")

View File

@ -5,11 +5,12 @@ import re
import os
import csv
import glob
import pathlib
from flask_socketio import SocketIO
from datetime import datetime, timezone
from .forms import TemplateForm
# import eventlet
from datetime import datetime, timezone, timedelta
# from flask_socketio import SocketIO
# from flask_session import Session
from functools import wraps
import flask
from flask import (
redirect,
flash,
@ -21,18 +22,25 @@ from flask import (
g,
)
from werkzeug.utils import secure_filename
from app import app, forms
from app import app
# Upload folder
UPLOAD_FOLDER = "/Users/normrasmussen/Documents/Projects/CSM_webapp/app/static/files/csv"
TEMPLATES_FOLDER = "/Users/normrasmussen/Documents/Projects/CSM_webapp/app/static/files/templates/"
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["TEMPLATES_FOLDER"] = TEMPLATES_FOLDER
ALLOWED_EXTENSIONS = {"csv"}
#SESSION_PERMANENT = False
#PERMANENT_SESSION_LIFETIME = 1800
app.config.update(SECRET_KEY=os.urandom(24))
app.permanent_session_lifetime = timedelta(minutes=5)
# flask.session.modified = True
# Global Variables
socketio = SocketIO(app)
specials = "'!@#$%^&*()\[\]-+?_=,<>/'"
#eventlet.monkey_patch()
#socketio = SocketIO(app)
specials = '"!@#$%^&*()-+?_=,<>/"'
url = "https://api.northpass.com/"
@ -422,7 +430,6 @@ def save_templates_backup(templates):
temp.write(file_body)
temp.close
@app.route("/undo_template", methods=["POST"])
@key_required
def undo_template():
@ -430,26 +437,39 @@ def undo_template():
if request.form["undo_templates"]:
pass
@socketio.on("disconnect")
def test_disconnect():
print("Client disconnected")
@app.route("/stop", methods=["POST"])
def stop():
print("stopping")
'''
@socketio.on("connect")
@socketio.on('disconnect')
def client_disconnect():
clear_session()
print("Disconnected!")
@socketio.on('message')
def handle_message(data):
print('received message: ' + data)
@socketio.on('connect')
def test_connect():
print("connection established")
@app.before_request
def before_request_func():
print("before_request executing!")
@app.route("/cmtest", methods=["GET", "POST"])
def cmtest():
form = TemplateForm()
if form.validate_on_submit():
text = form.template_code.data
return render_template("templates.html", form=form)
app.secret_key = "@&I\x1a?\xce\x94\xbb0w\x17\xbf&Y\xa2\xc2(A\xf5\xf2\x97\xba\xeb\xfa"
@app.after_request
def after_request_func(response):
print("after_request executing!")
return response
'''
# flask.session.permanent = False
# app.permanent_session_lifetime = datetime.timedelta(minutes=20)
# flask.session.modified = True
# flask.secret_key = "@&I\x1a?\xce\x94\xbb0w\x17\xbf&Y\xa2\xc2(A\xf5\xf2\x97\xba\xeb\xfa"
# if __name__ == "__main__":
# socketio.run(app, debug=True)
# ask_key()

View File

@ -3,7 +3,7 @@
{% include 'header.html' %}
{% include 'logo.html' %}
{% block content %}
<h2>You're currently accessing {{ session.school }}.</h2>
<h2>You're currently accessing {{ session.raw_school }}.</h2>
<h2>&nbsp;</h2>
<div class="instructions-list">
<div class="instructions-left">

View File

@ -21,8 +21,10 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/WebCoder49/code-input@1.2.2/code-input.min.css">
<link href="{{ url_for('static', filename='css/prism.css')}}" rel="stylesheet" />
</head>
<body>
{% block content %} {% endblock %}
<script src="{{ url_for('static', filename='css/prism.js' )}}"></script>
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js"></script>
<script>
@ -30,5 +32,6 @@
window.history.replaceState( null, null, window.location.href );
}
</script>
</body>
</html>

View File

@ -3,6 +3,6 @@
{% include 'header.html' %}
{% include 'logo.html' %}
{% block content %}
<h2>Academy: {{ session.school }}.</h2>
<h2>Academy: {{ session.raw_school }}.</h2>
{% endblock %}

View File

@ -11,10 +11,9 @@
<p>
</p>
<form action="{{ url_for("ask_key")}}" method="post">
<input id="fields" type="password" name="apikey">
<input id="fields" type="submit" value="Submit">
<input id="pw" type="password" name="apikey">
<input id="sbm" type="submit" value="Submit">
</form>
</div>
</div>
</body>
{% endblock %}

View File

@ -4,6 +4,6 @@
{% include 'header.html' %}
{% block content %}
<h2>Hello! You're currently accessing {{ session.school }}.</h2>
<h2>Hello! You're currently accessing {{ session.raw_school }}.</h2>
{% endblock %}

View File

@ -19,7 +19,7 @@
{% if templates %}
<h2> Here are the liquid templates for </h2>
<h2 style="color:#F05323"><strong> {{ session.school }} </strong></h2>
<h2 style="color:#F05323"><strong> {{ session.raw_school }} </strong></h2>
{% endif %}
<div class="templates_display" >
{% for templates in templates %}

6
app/wsgi.py Normal file
View File

@ -0,0 +1,6 @@
import eventlet
from eventlet import wsgi
from app import apicalls
app = apicalls()
wsgi.server(eventlet.list(("127.0.0.1", 5000), app))