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:
Norm Rasmussen
2023-04-06 16:46:49 -04:00
parent d55694fab0
commit eade9a5f27
7 changed files with 140 additions and 41 deletions

View File

@ -7,6 +7,7 @@ import csv
import glob
import time
import pandas as pd
from urllib.parse import urlparse
from datetime import datetime, timezone, timedelta
from pathlib import Path
from functools import wraps
@ -86,9 +87,18 @@ def key_required(check):
if session.get("key") is None:
return redirect("/", code=302)
return check(*args, **kwargs)
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"])
def ask_key():
@ -108,7 +118,9 @@ def ask_key():
endpoint = "/v2/properties/school"
headers = {"accept": "application/json", "X-Api-Key": session["key"]}
response = requests.get(url + endpoint, headers=headers)
grab_subdomain()
return key_response(response)
error = "Hm. That doesn't seem right"
session.clear()
return render_template("index.html", title="Home", error=error)
@ -336,7 +348,7 @@ def load_templates():
while True:
count += 1
endpoint = "v2/custom_templates"
endpoint = f"v2/custom_templates?page={count}"
headers = {
"accept": "application/json",
"content-type": "application/json",
@ -344,7 +356,6 @@ def load_templates():
}
response = requests.get(url + endpoint, headers=headers)
data = response.json()
nextlink = data["links"]
for response in data["data"]:
last_updated = response["attributes"]["updated_at"].split("T")
full_updated = response["attributes"]["updated_at"]
@ -357,17 +368,15 @@ def load_templates():
)
templates.append((name, body, last_updated))
if "next" not in nextlink:
if data["data"] == []:
break
save_templates_backup(templates)
return render_template(
"templates.html",
title="Templates",
templates=templates,
)
return render_template("options.html")
save_templates_backup(templates)
return render_template(
"templates.html",
title="Templates",
templates=templates,
)
@app.route("/templates", methods=["GET", "POST"])
@ -475,9 +484,10 @@ def get_info():
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
def get_courses(variable):
def get_courses():
print("course function running")
count = 0
courses = []
cats = []
@ -537,9 +547,9 @@ def get_courses(variable):
finally:
pd.set_option("display.max_colwidth", 30)
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)
table = df.to_html()
courses_table = df.to_html()
session["dfcsv"] = df.to_csv()
if data["data"] == []:
@ -547,12 +557,75 @@ def get_courses(variable):
return render_template("get_info.html",
title="Course Information",
table=table)
table=courses_table)
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"])
@key_required
def undo_template():

View File

@ -192,6 +192,9 @@ justify-content: space-evenly;
justify-content: space-evenly;
}
.subdom-link { color: #089FB7; }
.subdom-link:hover { color: #F05323; }
#templates {
width: 75%;
}
@ -279,11 +282,6 @@ ul {
padding: 0;
}
html, body {
background: #eaedf2;
font-family: 'Roboto', sans-serif;
}
.floating-container {
position: fixed;
width: 100px;
@ -293,7 +291,7 @@ html, body {
margin: 35px 25px;
}
.floating-container:hover {
height: 200px;
height: 280px;
}
.floating-container:hover .floating-button {
box-shadow: 0 10px 25px rgba(44, 179, 240, 0.6);
@ -352,17 +350,18 @@ html, body {
}
.floating-container .float-element .material-icons {
vertical-align: middle;
color: white;
font-size: 16px;
}
.floating-container .float-element:nth-child(1) {
background: #42A5F5;
box-shadow: 0 20px 20px -10px rgba(66, 165, 245, 0.5);
background: #F05323;
box-shadow: 0 20px 20px -10px rgba(240, 84, 36, 0.5);
}
.floating-container .float-element:nth-child(2) {
background: #4CAF50;
box-shadow: 0 20px 20px -10px rgba(76, 175, 80, 0.5);
background: #FED109;
box-shadow: 0 20px 20px -10px rgba(255, 209, 10, 0.5);
}
.floating-container .float-element:nth-child(3) {
background: #FF9800;
box-shadow: 0 20px 20px -10px rgba(255, 152, 0, 0.5);
background: #089FB7;
box-shadow: 0 20px 20px -10px rgba(08, 159, 183, 0.5);
}

View File

@ -1,17 +1,23 @@
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="floating-container">
<div class="floating-button">+</div>
<div class="element-container">
<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">
<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></a>
</span>
</i> </a> </span>
{% endif %}
</div>
</div>

View File

@ -3,6 +3,18 @@
{% include 'header.html' %}
{% include 'logo.html' %}
{% block content %}
<h2>Academy: {{ session.raw_school }}.</h2>
</br>
</br>
<h2>Academy: {{ session.raw_school }}</h2>
<p>&nbsp</p>
<h3>Subdomain:
<a class="subdom-link" href={{ session.subdomain }}>{{ session.subdomain }}
</a>
</h3>
{% endblock %}
<style>
.subdom-link { color: #089FB7; }
.subdom-link:hover { color: #F05323; }
</style>

View File

@ -3,7 +3,7 @@
<form class="navbutton"
id="get_courses"
action="{{ url_for('get_courses', variable='courses')}}"
action="{{ url_for('get_courses')}}"
method="post">
<a class="navoption"
onclick="document.forms['get_courses'].submit()"
@ -12,4 +12,14 @@
</a>
</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>

View File

@ -90,7 +90,6 @@
</form>
</div>
{% endif %}
<script>
codeInput.registerTemplate("code-input", codeInput.templates.hljs(hljs,
[
@ -99,4 +98,4 @@
<script>
codeInput.registerTemplate("code-input", codeInput.templates.prism(Prism, []));
</script>
{% include 'footer_button.html'%}
{% include 'footer_button.html'%}