mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
🦞
This commit is contained in:
parent
4c7bf9706f
commit
d19a33501a
36 changed files with 808 additions and 1052 deletions
|
@ -5,9 +5,9 @@ sounds more limiting that it actually is in this gallery
|
|||
"""
|
||||
from flask import Blueprint, render_template, url_for, request
|
||||
|
||||
from onlylegs.models import Post, User, GroupJunction, Group
|
||||
from onlylegs.models import Pictures, Users, AlbumJunction, Albums
|
||||
from onlylegs.extensions import db
|
||||
from onlylegs.utils.colour import contrast
|
||||
from onlylegs.utils import colour
|
||||
|
||||
|
||||
blueprint = Blueprint("group", __name__, url_prefix="/group")
|
||||
|
@ -18,21 +18,21 @@ def groups():
|
|||
"""
|
||||
Group overview, shows all image groups
|
||||
"""
|
||||
groups = Group.query.all()
|
||||
groups = Albums.query.all()
|
||||
|
||||
# For each group, get the 3 most recent images
|
||||
for group in groups:
|
||||
group.author_username = (
|
||||
User.query.with_entities(User.username)
|
||||
.filter(User.id == group.author_id)
|
||||
Users.query.with_entities(Users.username)
|
||||
.filter(Users.id == group.author_id)
|
||||
.first()[0]
|
||||
)
|
||||
|
||||
# Get the 3 most recent images
|
||||
images = (
|
||||
GroupJunction.query.with_entities(GroupJunction.post_id)
|
||||
.filter(GroupJunction.group_id == group.id)
|
||||
.order_by(GroupJunction.date_added.desc())
|
||||
AlbumJunction.query.with_entities(AlbumJunction.picture_id)
|
||||
.filter(AlbumJunction.album_id == group.id)
|
||||
.order_by(AlbumJunction.date_added.desc())
|
||||
.limit(3)
|
||||
)
|
||||
|
||||
|
@ -40,8 +40,10 @@ def groups():
|
|||
group.images = []
|
||||
for image in images:
|
||||
group.images.append(
|
||||
Post.query.with_entities(Post.filename, Post.alt, Post.colours, Post.id)
|
||||
.filter(Post.id == image[0])
|
||||
Pictures.query.with_entities(
|
||||
Pictures.filename, Pictures.alt, Pictures.colours, Pictures.id
|
||||
)
|
||||
.filter(Pictures.id == image[0])
|
||||
.first()
|
||||
)
|
||||
|
||||
|
@ -54,26 +56,29 @@ def group(group_id):
|
|||
Group view, shows all images in a group
|
||||
"""
|
||||
# Get the group, if it doesn't exist, 404
|
||||
group = db.get_or_404(Group, group_id, description="Group not found! D:")
|
||||
group = db.get_or_404(Albums, group_id, description="Group not found! D:")
|
||||
|
||||
# Get all images in the group from the junction table
|
||||
junction = (
|
||||
GroupJunction.query.with_entities(GroupJunction.post_id)
|
||||
.filter(GroupJunction.group_id == group_id)
|
||||
.order_by(GroupJunction.date_added.desc())
|
||||
AlbumJunction.query.with_entities(AlbumJunction.picture_id)
|
||||
.filter(AlbumJunction.album_id == group_id)
|
||||
.order_by(AlbumJunction.date_added.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
# Get the image data for each image in the group
|
||||
images = []
|
||||
for image in junction:
|
||||
images.append(Post.query.filter(Post.id == image[0]).first())
|
||||
images.append(Pictures.query.filter(Pictures.id == image[0]).first())
|
||||
|
||||
# Check contrast for the first image in the group for the banner
|
||||
text_colour = "rgb(var(--fg-black))"
|
||||
if images:
|
||||
text_colour = contrast(
|
||||
images[0].colours[0], "rgb(var(--fg-black))", "rgb(var(--fg-white))"
|
||||
colour_obj = colour.Colour(images[0].colours[0])
|
||||
text_colour = (
|
||||
"rgb(var(--fg-black));"
|
||||
if colour_obj.is_light()
|
||||
else "rgb(var(--fg-white));"
|
||||
)
|
||||
|
||||
return render_template(
|
||||
|
@ -87,12 +92,12 @@ def group_post(group_id, image_id):
|
|||
Image view, shows the image and its metadata from a specific group
|
||||
"""
|
||||
# Get the image, if it doesn't exist, 404
|
||||
image = db.get_or_404(Post, image_id, description="Image not found :<")
|
||||
image = db.get_or_404(Pictures, image_id, description="Image not found :<")
|
||||
|
||||
# Get all groups the image is in
|
||||
groups = (
|
||||
GroupJunction.query.with_entities(GroupJunction.group_id)
|
||||
.filter(GroupJunction.post_id == image_id)
|
||||
AlbumJunction.query.with_entities(AlbumJunction.album_id)
|
||||
.filter(AlbumJunction.picture_id == image_id)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
@ -100,24 +105,24 @@ def group_post(group_id, image_id):
|
|||
image.groups = []
|
||||
for group in groups:
|
||||
image.groups.append(
|
||||
Group.query.with_entities(Group.id, Group.name)
|
||||
.filter(Group.id == group[0])
|
||||
Albums.query.with_entities(Albums.id, Albums.name)
|
||||
.filter(Albums.id == group[0])
|
||||
.first()
|
||||
)
|
||||
|
||||
# Get the next and previous images in the group
|
||||
next_url = (
|
||||
GroupJunction.query.with_entities(GroupJunction.post_id)
|
||||
.filter(GroupJunction.group_id == group_id)
|
||||
.filter(GroupJunction.post_id > image_id)
|
||||
.order_by(GroupJunction.date_added.asc())
|
||||
AlbumJunction.query.with_entities(AlbumJunction.picture_id)
|
||||
.filter(AlbumJunction.album_id == group_id)
|
||||
.filter(AlbumJunction.picture_id > image_id)
|
||||
.order_by(AlbumJunction.date_added.asc())
|
||||
.first()
|
||||
)
|
||||
prev_url = (
|
||||
GroupJunction.query.with_entities(GroupJunction.post_id)
|
||||
.filter(GroupJunction.group_id == group_id)
|
||||
.filter(GroupJunction.post_id < image_id)
|
||||
.order_by(GroupJunction.date_added.desc())
|
||||
AlbumJunction.query.with_entities(AlbumJunction.picture_id)
|
||||
.filter(AlbumJunction.album_id == group_id)
|
||||
.filter(AlbumJunction.picture_id < image_id)
|
||||
.order_by(AlbumJunction.date_added.desc())
|
||||
.first()
|
||||
)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ Onlylegs - Image View
|
|||
"""
|
||||
from math import ceil
|
||||
from flask import Blueprint, render_template, url_for, current_app, request
|
||||
from onlylegs.models import Post, GroupJunction, Group
|
||||
from onlylegs.models import Pictures, AlbumJunction, Albums
|
||||
from onlylegs.extensions import db
|
||||
|
||||
|
||||
|
@ -16,12 +16,12 @@ def image(image_id):
|
|||
Image view, shows the image and its metadata
|
||||
"""
|
||||
# Get the image, if it doesn't exist, 404
|
||||
image = db.get_or_404(Post, image_id, description="Image not found :<")
|
||||
image = db.get_or_404(Pictures, image_id, description="Image not found :<")
|
||||
|
||||
# Get all groups the image is in
|
||||
groups = (
|
||||
GroupJunction.query.with_entities(GroupJunction.group_id)
|
||||
.filter(GroupJunction.post_id == image_id)
|
||||
AlbumJunction.query.with_entities(AlbumJunction.album_id)
|
||||
.filter(AlbumJunction.picture_id == image_id)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
@ -29,23 +29,23 @@ def image(image_id):
|
|||
image.groups = []
|
||||
for group in groups:
|
||||
image.groups.append(
|
||||
Group.query.with_entities(Group.id, Group.name)
|
||||
.filter(Group.id == group[0])
|
||||
Albums.query.with_entities(Albums.id, Albums.name)
|
||||
.filter(Albums.id == group[0])
|
||||
.first()
|
||||
)
|
||||
|
||||
# Get the next and previous images
|
||||
# Check if there is a group ID set
|
||||
next_url = (
|
||||
Post.query.with_entities(Post.id)
|
||||
.filter(Post.id > image_id)
|
||||
.order_by(Post.id.asc())
|
||||
Pictures.query.with_entities(Pictures.id)
|
||||
.filter(Pictures.id > image_id)
|
||||
.order_by(Pictures.id.asc())
|
||||
.first()
|
||||
)
|
||||
prev_url = (
|
||||
Post.query.with_entities(Post.id)
|
||||
.filter(Post.id < image_id)
|
||||
.order_by(Post.id.desc())
|
||||
Pictures.query.with_entities(Pictures.id)
|
||||
.filter(Pictures.id < image_id)
|
||||
.order_by(Pictures.id.desc())
|
||||
.first()
|
||||
)
|
||||
|
||||
|
@ -56,7 +56,9 @@ def image(image_id):
|
|||
prev_url = url_for("image.image", image_id=prev_url[0])
|
||||
|
||||
# Yoink all the images in the database
|
||||
total_images = Post.query.with_entities(Post.id).order_by(Post.id.desc()).all()
|
||||
total_images = (
|
||||
Pictures.query.with_entities(Pictures.id).order_by(Pictures.id.desc()).all()
|
||||
)
|
||||
limit = current_app.config["UPLOAD_CONF"]["max-load"]
|
||||
|
||||
# If the number of items is less than the limit, no point of calculating the page
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
Onlylegs Gallery - Index view
|
||||
"""
|
||||
from math import ceil
|
||||
|
||||
from flask import Blueprint, render_template, request, current_app
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
from onlylegs.models import Post
|
||||
from onlylegs.models import Pictures, Users
|
||||
|
||||
|
||||
blueprint = Blueprint("gallery", __name__)
|
||||
|
@ -17,31 +15,32 @@ def index():
|
|||
"""
|
||||
Home page of the website, shows the feed of the latest images
|
||||
"""
|
||||
# meme
|
||||
if request.args.get("coffee") == "please":
|
||||
abort(418)
|
||||
|
||||
# pagination, defaults to page 1 if no page is specified
|
||||
page = request.args.get("page", default=1, type=int)
|
||||
limit = current_app.config["UPLOAD_CONF"]["max-load"]
|
||||
|
||||
# get the total number of images in the database
|
||||
# calculate the total number of pages, and make sure the page number is valid
|
||||
total_images = Post.query.with_entities(Post.id).count()
|
||||
total_images = Pictures.query.with_entities(Pictures.id).count()
|
||||
pages = ceil(max(total_images, limit) / limit)
|
||||
if page > pages:
|
||||
abort(
|
||||
return abort(
|
||||
404,
|
||||
"You have reached the far and beyond, "
|
||||
+ "but you will not find your answers here.",
|
||||
"You have reached the far and beyond, but you will not find your answers here.",
|
||||
)
|
||||
|
||||
# get the images for the current page
|
||||
images = (
|
||||
Post.query.with_entities(
|
||||
Post.filename, Post.alt, Post.colours, Post.created_at, Post.id
|
||||
Pictures.query.with_entities(
|
||||
Pictures.filename,
|
||||
Pictures.alt,
|
||||
Pictures.colours,
|
||||
Pictures.created_at,
|
||||
Pictures.id,
|
||||
Users.username,
|
||||
)
|
||||
.order_by(Post.id.desc())
|
||||
.join(Users)
|
||||
.order_by(Pictures.id.desc())
|
||||
.offset((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.all()
|
||||
|
|
|
@ -5,7 +5,7 @@ from flask import Blueprint, render_template, request
|
|||
from werkzeug.exceptions import abort
|
||||
from flask_login import current_user
|
||||
|
||||
from onlylegs.models import Post, User, Group
|
||||
from onlylegs.models import Pictures, Users, Albums
|
||||
from onlylegs.extensions import db
|
||||
|
||||
|
||||
|
@ -27,9 +27,9 @@ def profile():
|
|||
abort(404, "You must be logged in to view your own profile!")
|
||||
|
||||
# Get the user's data
|
||||
user = db.get_or_404(User, user_id, description="User not found :<")
|
||||
user = db.get_or_404(Users, user_id, description="User not found :<")
|
||||
|
||||
images = Post.query.filter(Post.author_id == user_id).all()
|
||||
groups = Group.query.filter(Group.author_id == user_id).all()
|
||||
images = Pictures.query.filter(Pictures.author_id == user_id).all()
|
||||
groups = Albums.query.filter(Albums.author_id == user_id).all()
|
||||
|
||||
return render_template("profile.html", user=user, images=images, groups=groups)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue