Very temporary user profiles

This commit is contained in:
Michał Gdula 2023-04-04 14:55:32 +00:00
parent c417457d31
commit 271eb728dd
3 changed files with 41 additions and 19 deletions

View file

@ -202,7 +202,7 @@
<table>
<tr>
<td>Author</td>
<td><a href="{{ url_for('gallery.profile_id', user_id=image.author_id) }}" class="link">{{ image.author_username }}</a></td>
<td><a href="{{ url_for('gallery.profile', id=image.author_id) }}" class="link">{{ image.author_username }}</a></td>
</tr>
<tr>
<td>Upload date</td>

View file

@ -2,17 +2,29 @@
{% block nav_profile %}selected{% endblock %}
{% block content %}
<div class="banner">
<img src="{{ url_for('static', filename='') }}" onload="imgFade(this)" style="opacity:0;"/>
<span></span>
<div class="banner small">
<div class="banner-content">
<h1>Profile</h1>
<p>Hello {{ current_user.username }}</p>
<h1>{{ user.username }}</h1>
<p>Member since <span class="time">{{ user.created_at }}</span></p>
</div>
</div>
<h1>User</h1>
<p>{{user_id}}</p>
{% if images %}
<div class="gallery-grid">
{% for image in images %}
<a id="image-{{ image.id }}" class="gallery-item" href="{{ url_for('gallery.image', image_id=image.id) }}" style="background-color: rgb({{ image.image_colours.0.0 }}, {{ image.image_colours.0.1 }}, {{ image.image_colours.0.2 }})">
<div class="image-filter">
<p class="image-subtitle"></p>
<p class="image-title"><span class="time">{{ image.created_at }}</span></p>
</div>
<img fetchpriority="low" alt="{{ image.post_alt }}" data-src="{{ url_for('api.file', file_name=image.file_name) }}?r=thumb" onload="this.classList.add('loaded');" id="lazy-load"/>
</a>
{% endfor %}
</div>
{% else %}
<div class="big-text">
<h1>*crickets chirping*</h1>
<p>There are no images here yet, upload some!</p>
</div>
{% endif %}
{% endblock %}

View file

@ -3,6 +3,7 @@ Onlylegs Gallery - Routing
"""
from flask import Blueprint, render_template, url_for, request
from werkzeug.exceptions import abort
from flask_login import current_user
from sqlalchemy.orm import sessionmaker
from gallery import db
@ -81,12 +82,21 @@ def profile():
"""
Profile overview, shows all profiles on the onlylegs gallery
"""
return render_template('profile.html', user_id='gwa gwa')
@blueprint.route('/profile/<int:user_id>')
def profile_id(user_id):
"""
Shows user ofa given id, displays their uploads and other info
"""
return render_template('profile.html', user_id=user_id)
user_id = request.args.get('id', default=None, type=int)
# 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:
abort(404)
# Get the user's data
user = db_session.query(db.Users).filter(db.Users.id == user_id).first()
if not user:
abort(404, 'User not found :c')
images = db_session.query(db.Posts).filter(db.Posts.author_id == user_id).all()
return render_template('profile.html', user=user, images=images)