Added getting people functionality. Configured the action button to only show up if there's something to do (like a table) and also can scroll to the top.
This commit is contained in:
Binary file not shown.
107
app/routes.py
107
app/routes.py
@ -7,6 +7,7 @@ import csv
|
|||||||
import glob
|
import glob
|
||||||
import time
|
import time
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
from urllib.parse import urlparse
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
@ -86,9 +87,18 @@ def key_required(check):
|
|||||||
if session.get("key") is None:
|
if session.get("key") is None:
|
||||||
return redirect("/", code=302)
|
return redirect("/", code=302)
|
||||||
return check(*args, **kwargs)
|
return check(*args, **kwargs)
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
|
def grab_subdomain():
|
||||||
|
endpoint = "/v2/courses"
|
||||||
|
headers = {"accept":"application/json", "X-Api-Key":session["key"]}
|
||||||
|
response = requests.get(url+endpoint, headers=headers)
|
||||||
|
data2 = response.json()["data"][0]["links"]["enroll"]["href"]
|
||||||
|
data = urlparse(data2)
|
||||||
|
data = str("https://" + data.netloc)
|
||||||
|
print(data)
|
||||||
|
session["subdomain"] = data
|
||||||
|
|
||||||
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
def ask_key():
|
def ask_key():
|
||||||
@ -108,7 +118,9 @@ def ask_key():
|
|||||||
endpoint = "/v2/properties/school"
|
endpoint = "/v2/properties/school"
|
||||||
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
|
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
|
||||||
response = requests.get(url + endpoint, headers=headers)
|
response = requests.get(url + endpoint, headers=headers)
|
||||||
|
grab_subdomain()
|
||||||
return key_response(response)
|
return key_response(response)
|
||||||
|
|
||||||
error = "Hm. That doesn't seem right"
|
error = "Hm. That doesn't seem right"
|
||||||
session.clear()
|
session.clear()
|
||||||
return render_template("index.html", title="Home", error=error)
|
return render_template("index.html", title="Home", error=error)
|
||||||
@ -336,7 +348,7 @@ def load_templates():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
count += 1
|
count += 1
|
||||||
endpoint = "v2/custom_templates"
|
endpoint = f"v2/custom_templates?page={count}"
|
||||||
headers = {
|
headers = {
|
||||||
"accept": "application/json",
|
"accept": "application/json",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -344,7 +356,6 @@ def load_templates():
|
|||||||
}
|
}
|
||||||
response = requests.get(url + endpoint, headers=headers)
|
response = requests.get(url + endpoint, headers=headers)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
nextlink = data["links"]
|
|
||||||
for response in data["data"]:
|
for response in data["data"]:
|
||||||
last_updated = response["attributes"]["updated_at"].split("T")
|
last_updated = response["attributes"]["updated_at"].split("T")
|
||||||
full_updated = response["attributes"]["updated_at"]
|
full_updated = response["attributes"]["updated_at"]
|
||||||
@ -357,17 +368,15 @@ def load_templates():
|
|||||||
)
|
)
|
||||||
templates.append((name, body, last_updated))
|
templates.append((name, body, last_updated))
|
||||||
|
|
||||||
if "next" not in nextlink:
|
if data["data"] == []:
|
||||||
break
|
break
|
||||||
|
|
||||||
save_templates_backup(templates)
|
save_templates_backup(templates)
|
||||||
return render_template(
|
return render_template(
|
||||||
"templates.html",
|
"templates.html",
|
||||||
title="Templates",
|
title="Templates",
|
||||||
templates=templates,
|
templates=templates,
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template("options.html")
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/templates", methods=["GET", "POST"])
|
@app.route("/templates", methods=["GET", "POST"])
|
||||||
@ -475,9 +484,10 @@ def get_info():
|
|||||||
return render_template("get_info.html", title="Get Customer Information")
|
return render_template("get_info.html", title="Get Customer Information")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/get_info/<variable>", methods=["GET", "POST"])
|
@app.route("/get_courses", methods=["GET", "POST"])
|
||||||
@key_required
|
@key_required
|
||||||
def get_courses(variable):
|
def get_courses():
|
||||||
|
print("course function running")
|
||||||
count = 0
|
count = 0
|
||||||
courses = []
|
courses = []
|
||||||
cats = []
|
cats = []
|
||||||
@ -537,9 +547,9 @@ def get_courses(variable):
|
|||||||
finally:
|
finally:
|
||||||
pd.set_option("display.max_colwidth", 30)
|
pd.set_option("display.max_colwidth", 30)
|
||||||
df = pd.DataFrame.from_records(courses)
|
df = pd.DataFrame.from_records(courses)
|
||||||
df.iloc[-1] = df.iloc[-1].astype(str).str.replace("[\]\[]",'')
|
# df.iloc[-1] = df.iloc[-1].astype(str).str.replace("[\]\[]",'')
|
||||||
df.fillna('', inplace=True)
|
df.fillna('', inplace=True)
|
||||||
table = df.to_html()
|
courses_table = df.to_html()
|
||||||
session["dfcsv"] = df.to_csv()
|
session["dfcsv"] = df.to_csv()
|
||||||
|
|
||||||
if data["data"] == []:
|
if data["data"] == []:
|
||||||
@ -547,12 +557,75 @@ def get_courses(variable):
|
|||||||
|
|
||||||
return render_template("get_info.html",
|
return render_template("get_info.html",
|
||||||
title="Course Information",
|
title="Course Information",
|
||||||
table=table)
|
table=courses_table)
|
||||||
|
|
||||||
return "You didn't post up"
|
return "You didn't post up"
|
||||||
|
|
||||||
|
@app.route("/get_groups", methods=["GET", "POST"])
|
||||||
|
@key_required
|
||||||
|
def get_groups():
|
||||||
|
print("groups function running")
|
||||||
|
count = 0
|
||||||
|
groups = []
|
||||||
|
group_dict = {}
|
||||||
|
if request.method == "POST":
|
||||||
|
while True:
|
||||||
|
count += 1
|
||||||
|
url = f"https://api.northpass.com/v2/groups?page={count}"
|
||||||
|
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
data = response.json()
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
for response in data["data"]:
|
||||||
|
uuid = response["id"]
|
||||||
|
name = response["attributes"]["name"]
|
||||||
|
ecount = response["attributes"]["membership_count"]
|
||||||
|
created = response["attributes"]["created_at"]
|
||||||
|
update = response["attributes"]["updated_at"]
|
||||||
|
elink = response["attributes"]["group_enrollment_link"]
|
||||||
|
group_dict = {
|
||||||
|
"Id": uuid,
|
||||||
|
"Name": name,
|
||||||
|
"Members": ecount,
|
||||||
|
"Created At": created,
|
||||||
|
"Last Updated": update,
|
||||||
|
"Enrollment Link":elink,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
groups.append(group_dict)
|
||||||
|
except TypeError as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
finally:
|
||||||
|
pd.set_option("display.max_colwidth", 30)
|
||||||
|
df = pd.DataFrame.from_records(groups)
|
||||||
|
# df.iloc[-1] = df.iloc[-1].astype(str).str.replace("[\]\[]",'')
|
||||||
|
df.fillna('', inplace=True)
|
||||||
|
groups_table = df.to_html()
|
||||||
|
session["dfcsv"] = df.to_csv()
|
||||||
|
if data["data"] == []:
|
||||||
|
break
|
||||||
|
return render_template("get_info.html",
|
||||||
|
title="Course Information",
|
||||||
|
table=groups_table)
|
||||||
|
return "You didn't post up"
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/get_people", methods=["GET", "POST"])
|
||||||
|
@key_required
|
||||||
|
def get_people():
|
||||||
|
print("groups function running")
|
||||||
|
count = 0
|
||||||
|
groups = []
|
||||||
|
group_dict = {}
|
||||||
|
if request.method == "POST":
|
||||||
|
while True:
|
||||||
|
count += 1
|
||||||
|
url = f"https://api.northpass.com/v2/groups?page={count}"
|
||||||
|
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
data = response.json()
|
||||||
|
print(data)
|
||||||
@app.route("/undo_template", methods=["POST"])
|
@app.route("/undo_template", methods=["POST"])
|
||||||
@key_required
|
@key_required
|
||||||
def undo_template():
|
def undo_template():
|
||||||
|
|||||||
@ -192,6 +192,9 @@ justify-content: space-evenly;
|
|||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.subdom-link { color: #089FB7; }
|
||||||
|
.subdom-link:hover { color: #F05323; }
|
||||||
|
|
||||||
#templates {
|
#templates {
|
||||||
width: 75%;
|
width: 75%;
|
||||||
}
|
}
|
||||||
@ -279,11 +282,6 @@ ul {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
html, body {
|
|
||||||
background: #eaedf2;
|
|
||||||
font-family: 'Roboto', sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
.floating-container {
|
.floating-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
@ -293,7 +291,7 @@ html, body {
|
|||||||
margin: 35px 25px;
|
margin: 35px 25px;
|
||||||
}
|
}
|
||||||
.floating-container:hover {
|
.floating-container:hover {
|
||||||
height: 200px;
|
height: 280px;
|
||||||
}
|
}
|
||||||
.floating-container:hover .floating-button {
|
.floating-container:hover .floating-button {
|
||||||
box-shadow: 0 10px 25px rgba(44, 179, 240, 0.6);
|
box-shadow: 0 10px 25px rgba(44, 179, 240, 0.6);
|
||||||
@ -352,17 +350,18 @@ html, body {
|
|||||||
}
|
}
|
||||||
.floating-container .float-element .material-icons {
|
.floating-container .float-element .material-icons {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
color: white;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
.floating-container .float-element:nth-child(1) {
|
.floating-container .float-element:nth-child(1) {
|
||||||
background: #42A5F5;
|
background: #F05323;
|
||||||
box-shadow: 0 20px 20px -10px rgba(66, 165, 245, 0.5);
|
box-shadow: 0 20px 20px -10px rgba(240, 84, 36, 0.5);
|
||||||
}
|
}
|
||||||
.floating-container .float-element:nth-child(2) {
|
.floating-container .float-element:nth-child(2) {
|
||||||
background: #4CAF50;
|
background: #FED109;
|
||||||
box-shadow: 0 20px 20px -10px rgba(76, 175, 80, 0.5);
|
box-shadow: 0 20px 20px -10px rgba(255, 209, 10, 0.5);
|
||||||
}
|
}
|
||||||
.floating-container .float-element:nth-child(3) {
|
.floating-container .float-element:nth-child(3) {
|
||||||
background: #FF9800;
|
background: #089FB7;
|
||||||
box-shadow: 0 20px 20px -10px rgba(255, 152, 0, 0.5);
|
box-shadow: 0 20px 20px -10px rgba(08, 159, 183, 0.5);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
||||||
<div class="floating-container">
|
<div class="floating-container">
|
||||||
<div class="floating-button">+</div>
|
<div class="floating-button">+</div>
|
||||||
<div class="element-container">
|
<div class="element-container">
|
||||||
|
|
||||||
<a href="https://app.northpass.com/admin/schools/{{ session.admin_id }}">
|
<a href="https://app.northpass.com/admin/schools/{{ session.admin_id }}">
|
||||||
<span class="float-element">
|
|
||||||
<i class="material-icons">admin_panel_settings</i>
|
|
||||||
</span>
|
|
||||||
{% if table %}
|
|
||||||
<a id="download" href="/downloadcsv">
|
|
||||||
<span class="float-element tooltip-left">
|
<span class="float-element tooltip-left">
|
||||||
|
<i class="material-icons">admin_panel_settings
|
||||||
|
</i> </a> </span>
|
||||||
|
|
||||||
|
<span class="float-element">
|
||||||
|
<a href="#top">
|
||||||
|
<i class="material-icons">vertical_align_top
|
||||||
|
</i> </a> </span>
|
||||||
|
|
||||||
|
{% if table %}
|
||||||
|
<span class="float-element">
|
||||||
|
<a id="download" href="/downloadcsv">
|
||||||
<i class="material-icons">download_for_offline
|
<i class="material-icons">download_for_offline
|
||||||
</i></a>
|
</i> </a> </span>
|
||||||
</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,6 +3,18 @@
|
|||||||
{% include 'header.html' %}
|
{% include 'header.html' %}
|
||||||
{% include 'logo.html' %}
|
{% include 'logo.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Academy: {{ session.raw_school }}.</h2>
|
</br>
|
||||||
|
</br>
|
||||||
|
<h2>Academy: {{ session.raw_school }}</h2>
|
||||||
|
<p> </p>
|
||||||
|
<h3>Subdomain:
|
||||||
|
<a class="subdom-link" href={{ session.subdomain }}>{{ session.subdomain }}
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.subdom-link { color: #089FB7; }
|
||||||
|
.subdom-link:hover { color: #F05323; }
|
||||||
|
</style>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<form class="navbutton"
|
<form class="navbutton"
|
||||||
id="get_courses"
|
id="get_courses"
|
||||||
action="{{ url_for('get_courses', variable='courses')}}"
|
action="{{ url_for('get_courses')}}"
|
||||||
method="post">
|
method="post">
|
||||||
<a class="navoption"
|
<a class="navoption"
|
||||||
onclick="document.forms['get_courses'].submit()"
|
onclick="document.forms['get_courses'].submit()"
|
||||||
@ -12,4 +12,14 @@
|
|||||||
</a>
|
</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form class="navbutton"
|
||||||
|
id="get_groups"
|
||||||
|
action="{{ url_for('get_groups')}}"
|
||||||
|
method="post">
|
||||||
|
<a class="navoption"
|
||||||
|
onclick="document.forms['get_groups'].submit()"
|
||||||
|
style="cursor:pointer;">
|
||||||
|
<p class="navselection">Get Groups</p>
|
||||||
|
</a>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -90,7 +90,6 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
codeInput.registerTemplate("code-input", codeInput.templates.hljs(hljs,
|
codeInput.registerTemplate("code-input", codeInput.templates.hljs(hljs,
|
||||||
[
|
[
|
||||||
@ -99,4 +98,4 @@
|
|||||||
<script>
|
<script>
|
||||||
codeInput.registerTemplate("code-input", codeInput.templates.prism(Prism, []));
|
codeInput.registerTemplate("code-input", codeInput.templates.prism(Prism, []));
|
||||||
</script>
|
</script>
|
||||||
{% include 'footer_button.html'%}
|
{% include 'footer_button.html'%}
|
||||||
|
|||||||
Reference in New Issue
Block a user