From deddf1605a1cdb7ecfc3db1272997b844c2a6609 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 13 Aug 2018 16:27:15 -0400 Subject: [PATCH] membershipViewer: Add search, try not to expose too much information --- membershipViewer.py | 25 ++++++++++++++++--------- templates/members.html | 8 +++++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/membershipViewer.py b/membershipViewer.py index b5e4e9a..7685bd0 100644 --- a/membershipViewer.py +++ b/membershipViewer.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import re -from flask import Flask, render_template +from flask import Flask, render_template, request app = Flask(__name__) @@ -26,10 +26,6 @@ def parse_members(members): + member['Access Card Number'], 'Account on Hold': "Yes" if member['Account on Hold'] != '' else "No" } - certifications = [] - access = [] - levels = [] - props['Certifications'] = parse_list(member, 'Certified: (.*)') props['Door Access'] = parse_list(member, 'Access (.*)\?') props['Memebership Level'] = parse_list(member, 'CMS (.*)') @@ -41,17 +37,28 @@ def parse_members(members): @app.route("/") def main(): # maybe not now: membership agreement signed - # TODO: renewal date + # TODO: renewal date check + term = request.args.get('term', '') - members = getMembershipworksData( + if len(term) < 3: + return render_template("members.html", + error="Enter at least 3 characters to search") + + data = getMembershipworksData( ['members', 'staff'], "lvl,xws,xms,xsc,xas,xfd,xac,phn,eml,lbl,xcf,nam,end") - data = parse_members(members) + 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'] - return render_template("members.html", headers=headers, members=data) + 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) if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') diff --git a/templates/members.html b/templates/members.html index a3e6bf7..0fa6813 100644 --- a/templates/members.html +++ b/templates/members.html @@ -24,7 +24,11 @@ -

Members

+
+ + +
+ {% if headers is not none %} {% for header in headers %} @@ -40,5 +44,7 @@ {% endfor %}
+ {% endif %} + {{ error }}