forked from CMS/memberPlumbing
Remove membershipViewer
This commit is contained in:
parent
b509495c5f
commit
743fe3b9fb
@ -1,85 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import http
|
||||
import re
|
||||
|
||||
from flask import Flask, render_template, request
|
||||
|
||||
from common import doors, membershipworks
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
def parse_list(member, regex):
|
||||
data_list = []
|
||||
for key, value in member.items():
|
||||
match = re.match(regex, key)
|
||||
if match is not None and value != "":
|
||||
data_list.append(match.group(1))
|
||||
|
||||
return ", ".join(data_list)
|
||||
|
||||
|
||||
def parse_members(members):
|
||||
data = []
|
||||
for member in members:
|
||||
props = {
|
||||
"Name": member["Account Name"],
|
||||
"Renewal Date": member["Renewal Date"],
|
||||
"Card Number": member["Access Card Facility Code"]
|
||||
+ "-"
|
||||
+ member["Access Card Number"],
|
||||
"Account on Hold": "Yes" if member["Account on Hold"] != "" else "No",
|
||||
}
|
||||
|
||||
props["Certifications"] = parse_list(member, "Certified: (.*)")
|
||||
props["Door Access"] = parse_list(member, "Access (.*)\?")
|
||||
props["Memebership Level"] = parse_list(member, "CMS (.*)")
|
||||
|
||||
data.append(props)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def main():
|
||||
# maybe not now: membership agreement signed
|
||||
# TODO: renewal date check
|
||||
term = request.args.get("term", "")
|
||||
|
||||
if len(term) < 3:
|
||||
return render_template(
|
||||
"members.html", error="Enter at least 3 characters to search"
|
||||
)
|
||||
|
||||
data = membershipworks.get_members(
|
||||
["members", "staff"], "lvl,xws,xms,xsc,xas,xfd,xac,phn,eml,lbl,xcf,nam,end"
|
||||
)
|
||||
|
||||
members = parse_members(data)
|
||||
members = [member for member in members if term.lower() in member["Name"].lower()]
|
||||
headers = [
|
||||
"Name",
|
||||
"Certifications",
|
||||
"Door Access",
|
||||
"Memebership Level",
|
||||
"Card Number",
|
||||
"Renewal Date",
|
||||
"Account on Hold",
|
||||
]
|
||||
|
||||
if len(members) > 4:
|
||||
return render_template(
|
||||
"members.html", error="Too many results, please be more specific."
|
||||
)
|
||||
|
||||
return render_template("members.html", headers=headers, members=members)
|
||||
|
||||
|
||||
@app.route("/frontDoor/<lock>", methods=["POST"])
|
||||
def unlockLockDoor(lock):
|
||||
doors["Front Door"].lockOrUnlockDoor(lock != "unlock")
|
||||
return ("", http.HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, host="0.0.0.0")
|
@ -1,54 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title> CMS Members </title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
td, th{
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
tr[onHold=Yes] {
|
||||
background-color: #f66;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form action="./frontDoor/lock" method="post">
|
||||
<button>Lock Front Door</button>
|
||||
<button formaction="./frontDoor/unlock">Unlock Front Door</button>
|
||||
</form>
|
||||
<form>
|
||||
<input type="text" name="term" />
|
||||
<button>Search</button>
|
||||
</form>
|
||||
{% if headers is not none %}
|
||||
<table>
|
||||
<tr>
|
||||
{% for header in headers %}
|
||||
<th> {{ header }} </th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% for member in members %}
|
||||
<tr onHold ="{{ member['Account on Hold'] }}">
|
||||
{% for header in headers %}
|
||||
<td> {{ member[header] }} </td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</table>
|
||||
{% endif %}
|
||||
<span class="error">{{ error }}</span>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user