2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
Onlylegs Gallery - Routing
|
|
|
|
"""
|
2023-03-08 09:01:20 +00:00
|
|
|
from datetime import datetime as dt
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-03-08 09:01:20 +00:00
|
|
|
from flask import Blueprint, render_template, current_app, request, g
|
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-01-26 14:43:08 +00:00
|
|
|
|
2023-03-04 13:45:26 +00:00
|
|
|
from . import db
|
2023-01-31 17:32:22 +00:00
|
|
|
from . import metadata as mt
|
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
|
|
|
"""
|
|
|
|
Home page of the website, shows the feed of latest images
|
|
|
|
"""
|
2023-03-05 18:16:28 +00:00
|
|
|
images = db_session.query(db.Posts.file_name,
|
2023-03-08 09:01:20 +00:00
|
|
|
db.Posts.image_colours,
|
|
|
|
db.Posts.author_id,
|
|
|
|
db.Posts.created_at,
|
|
|
|
db.Posts.id).order_by(db.Posts.id.desc()).all()
|
2023-03-05 16:22:11 +00:00
|
|
|
|
2023-03-01 23:29:34 +00:00
|
|
|
return render_template('index.html',
|
|
|
|
images=images,
|
|
|
|
image_count=len(images),
|
|
|
|
name=current_app.config['WEBSITE']['name'],
|
|
|
|
motto=current_app.config['WEBSITE']['motto'])
|
2023-01-10 14:40:43 +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-03-05 18:16:28 +00:00
|
|
|
img = db_session.query(db.Posts).filter(db.Posts.id == image_id).first()
|
2023-03-08 13:36:35 +00:00
|
|
|
|
2023-03-03 00:26:46 +00:00
|
|
|
if img is None:
|
2023-03-05 18:16:28 +00:00
|
|
|
abort(404, 'Image not found')
|
2023-01-25 15:13:56 +00:00
|
|
|
|
2023-03-08 13:36:35 +00:00
|
|
|
author = db_session.query(db.Users.username).filter(db.Users.id == img.author_id).first()[0]
|
|
|
|
img.author_username = author
|
2023-03-09 12:22:25 +00:00
|
|
|
|
|
|
|
next = db_session.query(db.Posts.id).filter(db.Posts.id > image_id).order_by(db.Posts.id.asc()).first()
|
|
|
|
prev = db_session.query(db.Posts.id).filter(db.Posts.id < image_id).order_by(db.Posts.id.desc()).first()
|
|
|
|
|
|
|
|
if next is not None:
|
|
|
|
next = next[0]
|
|
|
|
if prev is not None:
|
|
|
|
prev = prev[0]
|
2023-03-08 13:36:35 +00:00
|
|
|
|
2023-03-09 12:22:25 +00:00
|
|
|
return render_template('image.html',
|
|
|
|
image=img,
|
|
|
|
exif=img.image_exif,
|
|
|
|
next=next,
|
|
|
|
prev=prev,
|
|
|
|
next_id=next,
|
|
|
|
prev_id=prev)
|
2023-01-25 15:13:56 +00:00
|
|
|
|
2023-03-08 09:01:20 +00:00
|
|
|
@blueprint.route('/group', methods=['GET', 'POST'])
|
2023-01-10 14:40:43 +00:00
|
|
|
def groups():
|
2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
Group overview, shows all image groups
|
|
|
|
"""
|
2023-03-08 09:01:20 +00:00
|
|
|
if request.method == 'GET':
|
|
|
|
groups = db_session.query(db.Groups.name, db.Groups.author_id).all()
|
|
|
|
|
|
|
|
return render_template('group.html', groups=groups)
|
|
|
|
elif request.method == 'POST':
|
|
|
|
group_name = request.form['name']
|
|
|
|
group_description = request.form['description']
|
|
|
|
group_author = g.user.id
|
|
|
|
|
|
|
|
new_group = db.Groups(name=group_name, description=group_description, author_id=group_author, created_at=dt.now())
|
|
|
|
|
|
|
|
db_session.add(new_group)
|
|
|
|
|
|
|
|
return ':3'
|
2023-01-10 14:40:43 +00:00
|
|
|
|
2023-03-04 13:45:26 +00:00
|
|
|
@blueprint.route('/group/<int:group_id>')
|
|
|
|
def group(group_id):
|
|
|
|
"""
|
|
|
|
Group view, shows all images in a group
|
|
|
|
"""
|
|
|
|
return render_template('group.html', group_id=group_id)
|
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-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-08 09:01:20 +00:00
|
|
|
return render_template('profile.html', user_id=user_id)
|