2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
Onlylegs Gallery - Routing
|
|
|
|
"""
|
2023-03-23 12:54:00 +00:00
|
|
|
from flask import Blueprint, render_template, url_for, request
|
2023-01-10 14:40:43 +00:00
|
|
|
from werkzeug.exceptions import abort
|
2023-03-03 00:26:46 +00:00
|
|
|
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
2023-03-12 15:52:23 +00:00
|
|
|
from gallery import db
|
2023-01-26 14:43:08 +00:00
|
|
|
|
2023-01-31 23:44:44 +00:00
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
blueprint = Blueprint('gallery', __name__)
|
2023-03-04 13:45:26 +00:00
|
|
|
db_session = sessionmaker(bind=db.engine)
|
|
|
|
db_session = db_session()
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
2023-03-04 13:45:26 +00:00
|
|
|
"""
|
2023-03-11 22:14:03 +00:00
|
|
|
Home page of the website, shows the feed of the latest images
|
2023-03-04 13:45:26 +00:00
|
|
|
"""
|
2023-03-05 18:16:28 +00:00
|
|
|
images = db_session.query(db.Posts.file_name,
|
2023-03-11 22:14:03 +00:00
|
|
|
db.Posts.post_alt,
|
2023-03-08 09:01:20 +00:00
|
|
|
db.Posts.image_colours,
|
|
|
|
db.Posts.created_at,
|
|
|
|
db.Posts.id).order_by(db.Posts.id.desc()).all()
|
2023-04-01 17:40:42 +00:00
|
|
|
|
2023-03-23 12:54:00 +00:00
|
|
|
if request.args.get('coffee') == 'please':
|
|
|
|
abort(418)
|
2023-03-20 17:57:47 +00:00
|
|
|
|
2023-03-09 23:31:58 +00:00
|
|
|
return render_template('index.html', images=images)
|
2023-01-10 14:40:43 +00:00
|
|
|
|
2023-03-11 22:14:03 +00:00
|
|
|
|
2023-03-04 13:45:26 +00:00
|
|
|
@blueprint.route('/image/<int:image_id>')
|
|
|
|
def image(image_id):
|
|
|
|
"""
|
|
|
|
Image view, shows the image and its metadata
|
|
|
|
"""
|
2023-04-01 17:40:42 +00:00
|
|
|
# Get the image, if it doesn't exist, 404
|
|
|
|
image = db_session.query(db.Posts).filter(db.Posts.id == image_id).first()
|
|
|
|
if not image:
|
2023-03-09 23:31:58 +00:00
|
|
|
abort(404, 'Image not found :<')
|
2023-01-25 15:13:56 +00:00
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
# Get the image's author username
|
|
|
|
image.author_username = db_session.query(db.Users.username)\
|
|
|
|
.filter(db.Users.id == image.author_id).first()[0]
|
2023-03-20 17:57:47 +00:00
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
# Get the image's groups
|
2023-03-20 17:57:47 +00:00
|
|
|
groups = db_session.query(db.GroupJunction.group_id)\
|
|
|
|
.filter(db.GroupJunction.post_id == image_id).all()
|
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
# For each group, get the group data and add it to the image item
|
|
|
|
image.groups = []
|
2023-03-09 23:31:58 +00:00
|
|
|
for group in groups:
|
2023-04-01 17:40:42 +00:00
|
|
|
group = db_session.query(db.Groups.id, db.Groups.name)\
|
|
|
|
.filter(db.Groups.id == group[0])\
|
|
|
|
.first()
|
|
|
|
image.groups.append(group)
|
2023-03-20 17:57:47 +00:00
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
# Get the next and previous images
|
2023-03-20 17:57:47 +00:00
|
|
|
next_url = db_session.query(db.Posts.id)\
|
|
|
|
.filter(db.Posts.id > image_id)\
|
|
|
|
.order_by(db.Posts.id.asc())\
|
|
|
|
.first()
|
|
|
|
prev_url = db_session.query(db.Posts.id)\
|
|
|
|
.filter(db.Posts.id < image_id)\
|
|
|
|
.order_by(db.Posts.id.desc())\
|
|
|
|
.first()
|
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
# If there is a next or previous image, get the url
|
2023-03-20 17:57:47 +00:00
|
|
|
if next_url:
|
2023-03-11 22:14:03 +00:00
|
|
|
next_url = url_for('gallery.image', image_id=next_url[0])
|
2023-03-20 17:57:47 +00:00
|
|
|
if prev_url:
|
2023-03-11 22:14:03 +00:00
|
|
|
prev_url = url_for('gallery.image', image_id=prev_url[0])
|
|
|
|
|
2023-04-01 17:40:42 +00:00
|
|
|
return render_template('image.html', image=image, next_url=next_url, prev_url=prev_url)
|
2023-01-25 15:13:56 +00:00
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
@blueprint.route('/profile')
|
|
|
|
def profile():
|
2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
Profile overview, shows all profiles on the onlylegs gallery
|
|
|
|
"""
|
2023-01-10 14:40:43 +00:00
|
|
|
return render_template('profile.html', user_id='gwa gwa')
|
|
|
|
|
2023-03-11 22:14:03 +00:00
|
|
|
|
2023-03-04 13:45:26 +00:00
|
|
|
@blueprint.route('/profile/<int:user_id>')
|
|
|
|
def profile_id(user_id):
|
|
|
|
"""
|
|
|
|
Shows user ofa given id, displays their uploads and other info
|
|
|
|
"""
|
2023-03-11 22:14:03 +00:00
|
|
|
return render_template('profile.html', user_id=user_id)
|