From b65154b8653942fd96e26826a39373ddc9892685 Mon Sep 17 00:00:00 2001 From: ngolp Date: Thu, 17 Oct 2024 17:56:27 -0400 Subject: [PATCH 1/3] Basic implementation of searching by email. I'd like to expand this to searching by other column values as well if necessary, and I still need to add sorting. Also, "registered users" isn't perfectly centered (its pushed off just a bit by the search button). This commit is mainly so I can save my progress. --- goathacks/templates/admin.html | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/goathacks/templates/admin.html b/goathacks/templates/admin.html index 410c36a..07a0073 100644 --- a/goathacks/templates/admin.html +++ b/goathacks/templates/admin.html @@ -14,7 +14,21 @@ {% block app_content %}
-

Registered Users

+ +
+ + + +

Registered Users

+
+ @@ -90,5 +104,32 @@
+ + {% endblock %} -- 2.43.5 From 228244ad2dec4c302cb33f40a53a548eb459fa3c Mon Sep 17 00:00:00 2001 From: ngolp Date: Sun, 27 Oct 2024 12:28:10 -0400 Subject: [PATCH 2/3] Hacker table on admin dashboard can now be sorted by double clicking the headers. Spent a bit trying to implement this manually before learning about the sortable class. The more you know! --- goathacks/templates/admin.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/goathacks/templates/admin.html b/goathacks/templates/admin.html index 07a0073..ff5a99b 100644 --- a/goathacks/templates/admin.html +++ b/goathacks/templates/admin.html @@ -29,7 +29,7 @@

Registered Users

- +
@@ -107,6 +107,7 @@ {% endblock %} -- 2.43.5 From 4e2427491552c04d945549fb78a53e3211ecf28a Mon Sep 17 00:00:00 2001 From: ngolp Date: Thu, 31 Oct 2024 13:41:12 -0400 Subject: [PATCH 3/3] basic implementation of github issue #28 (modifying user details right from admin dashboard). Went with first name, last name, school, and phone number, since the user can change the shirt size and special accomodations on their own. --- goathacks/admin/__init__.py | 40 ++++++++++++++++++++++++++++++++++ goathacks/templates/admin.html | 36 ++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/goathacks/admin/__init__.py b/goathacks/admin/__init__.py index 08ddf33..ebecfc8 100644 --- a/goathacks/admin/__init__.py +++ b/goathacks/admin/__init__.py @@ -4,6 +4,8 @@ from flask_mail import Message from goathacks.models import User +from sqlalchemy.exc import IntegrityError + bp = Blueprint("admin", __name__, url_prefix="/admin") from goathacks import db, mail as app_mail @@ -221,6 +223,44 @@ def hackers(): users = User.query.all() return User.create_json_output(users) +@bp.route("/updateHacker", methods=["POST"]) +@login_required +def updateHacker(): + if not current_user.is_admin: + return redirect(url_for("dashboard.home")) + + # get params from json + hacker_id = request.json['hacker_id'] + change_field = request.json['change_field'] + new_val = request.json['new_val'] + + # find the user in db + user = User.query.filter_by(id=hacker_id).one() + if user is None: + return {"status": "error", "msg": "user not found"} + + + # update the hacker depending on change_field + match change_field: + case "first_name": + user.first_name = new_val + case "last_name": + user.last_name = new_val + case "school": + user.school = new_val + case "phone": + user.phone = new_val + + try: + db.session.commit() + except IntegrityError as err: + db.session.rollback() + flash("Could not update user information for user " + hacker_id) + return {"status": "error"} + + + return {"status": "success"} + import json import csv from io import StringIO diff --git a/goathacks/templates/admin.html b/goathacks/templates/admin.html index ff5a99b..a5ef1fd 100644 --- a/goathacks/templates/admin.html +++ b/goathacks/templates/admin.html @@ -21,7 +21,7 @@ data-bs-toggle="dropdown">Search @@ -93,11 +93,20 @@ - - + + - + {% endfor %} @@ -130,6 +139,25 @@ } } } + + function updateHacker(id, change_field, new_val) { + //tell backend to update a specific field for a hacker + const headers = [ + ["Content-Type", "application/json"], + ]; + + let body = { + "hacker_id": id.substr(0, id.indexOf('-')), + "change_field": change_field, + "new_val": new_val, + } + + //send the post request, and report the error if there is one + fetch('/admin/updateHacker', {method: 'POST', body: JSON.stringify(body), headers: headers}).catch((err) => { + window.alert("Error updating user - see console for details"); + console.log(err); + }) + } {% endblock %} -- 2.43.5
Options{{ hacker.id }} {{ hacker.last_login }} {{ hacker.email }}{{ hacker.first_name + ' ' + hacker.last_name }}{{ hacker.phone }} +
+ + +
+
+ + {{ hacker.shirt_size }} {{ hacker.accomodations }}{{ hacker.school }} + +