python-gallery/gallery/views/profile.py

37 lines
1 KiB
Python
Raw Normal View History

2023-04-06 16:22:56 +00:00
"""
Onlylegs Gallery - Profile view
"""
from flask import Blueprint, render_template, request
from werkzeug.exceptions import abort
from flask_login import current_user
from gallery.models import Posts, Users
2023-04-06 16:22:56 +00:00
2023-04-07 12:35:30 +00:00
blueprint = Blueprint("profile", __name__, url_prefix="/profile")
2023-04-06 16:22:56 +00:00
2023-04-07 12:35:30 +00:00
@blueprint.route("/profile")
2023-04-06 16:22:56 +00:00
def profile():
"""
Profile overview, shows all profiles on the onlylegs gallery
"""
2023-04-07 12:35:30 +00:00
user_id = request.args.get("id", default=None, type=int)
2023-04-06 16:22:56 +00:00
# If there is no userID set, check if the user is logged in and display their profile
if not user_id:
if current_user.is_authenticated:
user_id = current_user.id
else:
2023-04-07 12:35:30 +00:00
abort(404, "You must be logged in to view your own profile!")
2023-04-06 16:22:56 +00:00
# Get the user's data
user = Users.query.filter(Users.id == user_id).first()
2023-04-06 16:22:56 +00:00
if not user:
2023-04-07 12:35:30 +00:00
abort(404, "User not found :c")
2023-04-06 16:22:56 +00:00
images = Posts.query.filter(Posts.author_id == user_id).all()
2023-04-06 16:22:56 +00:00
2023-04-07 12:35:30 +00:00
return render_template("profile.html", user=user, images=images)