diff --git a/acmsite/__init__.py b/acmsite/__init__.py index d7a7a3c..506050c 100644 --- a/acmsite/__init__.py +++ b/acmsite/__init__.py @@ -62,5 +62,8 @@ def create_app(): from .admin import bp as admin_bp app.register_blueprint(admin_bp) + from .api import bp as api_bp + app.register_blueprint(api_bp) + return app diff --git a/acmsite/admin/__init__.py b/acmsite/admin/__init__.py index 3963c0c..0b07f24 100644 --- a/acmsite/admin/__init__.py +++ b/acmsite/admin/__init__.py @@ -288,7 +288,7 @@ def upload_photo_post(): if not current_user.is_admin: return error_json("Unauthorized") - img_path = os.path.join(current_app.config["UPLOAD_FOLDER"], f"{current_user.username()}.png") + img_path = os.path.join("acmsite/" + current_app.config["UPLOAD_FOLDER"], f"{current_user.username()}.png") b64_string = request.data.decode() b64_string += '=' * (len(b64_string) % 4) diff --git a/acmsite/api/__init__.py b/acmsite/api/__init__.py new file mode 100644 index 0000000..de57176 --- /dev/null +++ b/acmsite/api/__init__.py @@ -0,0 +1,48 @@ +from os.path import exists +from flask import Blueprint, jsonify, url_for, current_app +import os +import datetime + +from acmsite.models import Event, Officer, User + +bp = Blueprint("api", __name__, url_prefix="/api") + + +def json(obj): + """ + Calls a "create_json" method on the passed in object. Write it yourself! + """ + return obj.create_json() + +@bp.route("/events/upcoming") +def upcoming_events(): + event_list = Event.query.filter(Event.start_time > + datetime.datetime.now()).all() + + return jsonify(list(map(json, event_list))) + +@bp.route("/officers/current") +def current_officers(): + now = datetime.datetime.now() + officers = Officer.query.filter(Officer.term_start < now, Officer.term_end > + now).all() + + officers_complete = [] + for o in officers: + u = User.query.filter_by(id = o.user_id).first() + if u is None: + continue # Broken reference, continue + img = url_for('static', filename="img/officers/placeholder.png") + if exists(f"acmsite/{current_app.config['UPLOAD_FOLDER']}/{u.username()}.png"): + img = url_for("main.officer_images", username="f{u.username()}.png") + officers_complete.append({ + "id": o.id, + "position": o.position, + "term_end": o.term_end, + "term_start": o.term_start, + "name": u.first_name + " " + u.last_name, + "img": img + }) + + + return jsonify(list(officers_complete)) diff --git a/acmsite/main/__init__.py b/acmsite/main/__init__.py index 768b928..f514f56 100644 --- a/acmsite/main/__init__.py +++ b/acmsite/main/__init__.py @@ -1,5 +1,5 @@ import datetime -from flask import Blueprint, render_template, abort, redirect +from flask import Blueprint, current_app, render_template, abort, redirect, send_from_directory, send_file from acmsite.models import Event, Link bp = Blueprint('main', __name__) @@ -21,6 +21,12 @@ def events(): def join(): return render_template("join.html") +@bp.route("/officers/") +def officer_images(username): + print(current_app.config["UPLOAD_FOLDER"]) + print(username) + return send_from_directory(current_app.config["UPLOAD_FOLDER"], username) + @bp.route("/") def shortlink(slug): diff --git a/acmsite/templates/about.html b/acmsite/templates/about.html index 6f3acc7..c13eda2 100644 --- a/acmsite/templates/about.html +++ b/acmsite/templates/about.html @@ -13,67 +13,72 @@ very friendly. You can find a list of our events and meetings here.

Exec Board

-
-
- + President
President
+

Unavailable

-
- + Vice President
Vice President
+

Unavailable

-
- + Treasurer
Treasurer
+

Unavailable

-
- + Secretary
Secretary
+

Unavailable

-
- + PR Chair
PR Chair
+

Unavailable

-
- + Events Coordinator
Events Coordinator
+

Unavailable

@@ -81,32 +86,35 @@ very friendly. You can find a list of our events and meetings
-
- + Hackathon Manager
Hackathon Manager
+

Unavailable

-
- + Hackathon Manager
Hackathon Manager
+

Unavailable

-
- + System Administrator
System Administrator
+

Unavailable

@@ -162,4 +170,27 @@ officers in the chapter system.

Epsilon
-- The CS honor society + {% endblock %}