mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
PyLint wasnt done with me
This commit is contained in:
parent
b426a6f6c4
commit
733a443835
7 changed files with 99 additions and 73 deletions
|
@ -40,7 +40,7 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
# Get config file
|
# Get config file
|
||||||
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8') as file:
|
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8') as file:
|
||||||
conf = safe_load(file, loader=FullLoader)
|
conf = safe_load(file)
|
||||||
print("Loaded gallery config")
|
print("Loaded gallery config")
|
||||||
|
|
||||||
# App configuration
|
# App configuration
|
||||||
|
|
|
@ -38,18 +38,9 @@ def get_file(file_name):
|
||||||
"""
|
"""
|
||||||
# Get args
|
# Get args
|
||||||
res = request.args.get('r', default=None, type=str) # Type of file (thumb, etc)
|
res = request.args.get('r', default=None, type=str) # Type of file (thumb, etc)
|
||||||
filtered = request.args.get('f', default=False, type=bool) # Whether to apply filters
|
filtered = request.args.get('f', default=False, type=bool) # Whether to apply filters # pylint: disable=W0612
|
||||||
blur = request.args.get('b', default=False, type=bool) # Whether to force blur
|
blur = request.args.get('b', default=False, type=bool) # Whether to force blur
|
||||||
|
|
||||||
# Idea: instead if specifying the height and width, pass in a string like "200x200" or "200x" or "x200"
|
|
||||||
# This would remove the need for the if statements below and would be possible to pass in a string
|
|
||||||
# like 'thumb' to get the thumbnail size instead of having to specify the width and height
|
|
||||||
# This would also allow for more flexibility in the future if I wanted to add more sizes
|
|
||||||
# Another idea is to pass in a list of filters to apply to the image
|
|
||||||
# such as "blur,grayscale" or "blur,grayscale,sepia". But this would require a lot more work to implement
|
|
||||||
# and would be a lot more complicated to use, would also implement the risk of the server being overloaded
|
|
||||||
# with requests to apply a lot of filters to a lot of images at once
|
|
||||||
|
|
||||||
file_name = secure_filename(file_name) # Sanitize file name
|
file_name = secure_filename(file_name) # Sanitize file name
|
||||||
|
|
||||||
# if no args are passed, return the raw file
|
# if no args are passed, return the raw file
|
||||||
|
@ -77,12 +68,12 @@ def get_file(file_name):
|
||||||
|
|
||||||
img = ImageOps.exif_transpose(img) # Rotate image based on EXIF data
|
img = ImageOps.exif_transpose(img) # Rotate image based on EXIF data
|
||||||
|
|
||||||
# Todo: If type is thumb(nail), return from database instead of file system
|
# Todo: If type is thumb(nail), return from database instead of file system pylint: disable=W0511
|
||||||
# as it's faster than generating a new thumbnail on every request
|
# as it's faster than generating a new thumbnail on every request
|
||||||
if res:
|
if res:
|
||||||
if res == 'thumb' or res == 'thumbnail':
|
if res in ['thumb', 'thumbnail']:
|
||||||
width, height = 400, 400
|
width, height = 400, 400
|
||||||
elif res == 'prev' or res == 'preview':
|
elif res in ['prev', 'preview']:
|
||||||
width, height = 1920, 1080
|
width, height = 1920, 1080
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -94,7 +85,7 @@ def get_file(file_name):
|
||||||
|
|
||||||
img.thumbnail((width, height), Image.LANCZOS)
|
img.thumbnail((width, height), Image.LANCZOS)
|
||||||
|
|
||||||
# Todo: If the image has a NSFW tag, blur image for example
|
# Todo: If the image has a NSFW tag, blur image for example pylint: disable=W0511
|
||||||
# if filtered:
|
# if filtered:
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
@ -245,10 +236,16 @@ def modify_group():
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
if request.form['action'] == 'add':
|
if request.form['action'] == 'add':
|
||||||
if db_session.query(db.GroupJunction).filter_by(group_id=group_id, post_id=image_id).first() is None:
|
if not db_session.query(db.GroupJunction)\
|
||||||
db_session.add(db.GroupJunction(group_id=group_id, post_id=image_id, date_added=dt.utcnow()))
|
.filter_by(group_id=group_id, post_id=image_id)\
|
||||||
|
.first():
|
||||||
|
db_session.add(db.GroupJunction(group_id=group_id,
|
||||||
|
post_id=image_id,
|
||||||
|
date_added=dt.utcnow()))
|
||||||
elif request.form['action'] == 'remove':
|
elif request.form['action'] == 'remove':
|
||||||
db_session.query(db.GroupJunction).filter_by(group_id=group_id, post_id=image_id).delete()
|
db_session.query(db.GroupJunction)\
|
||||||
|
.filter_by(group_id=group_id, post_id=image_id)\
|
||||||
|
.delete()
|
||||||
|
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
|
@ -262,7 +259,7 @@ def metadata(img_id):
|
||||||
"""
|
"""
|
||||||
img = db_session.query(db.Posts).filter_by(id=img_id).first()
|
img = db_session.query(db.Posts).filter_by(id=img_id).first()
|
||||||
|
|
||||||
if img is None:
|
if not img:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
img_path = os.path.join(current_app.config['UPLOAD_FOLDER'], img.file_name)
|
img_path = os.path.join(current_app.config['UPLOAD_FOLDER'], img.file_name)
|
||||||
|
@ -279,7 +276,7 @@ def logfile():
|
||||||
"""
|
"""
|
||||||
log_dict = {}
|
log_dict = {}
|
||||||
|
|
||||||
with open('only.log', encoding='utf-8') as file:
|
with open('only.log', encoding='utf-8', mode='r') as file:
|
||||||
for i, line in enumerate(file):
|
for i, line in enumerate(file):
|
||||||
line = line.split(' : ')
|
line = line.split(' : ')
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
"""
|
"""
|
||||||
Onlylegs - Image Groups
|
Onlylegs - Image Groups
|
||||||
Why groups? Because I don't like calling these albums, sounds more limiting that it actually is
|
Why groups? Because I don't like calling these albums
|
||||||
|
sounds more limiting that it actually is in this gallery
|
||||||
"""
|
"""
|
||||||
import logging
|
from flask import Blueprint, abort, render_template, url_for
|
||||||
import json
|
|
||||||
from datetime import datetime as dt
|
|
||||||
|
|
||||||
from flask import Blueprint, abort, jsonify, render_template, url_for, request, g
|
|
||||||
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from gallery import db
|
from gallery import db
|
||||||
|
@ -22,15 +19,21 @@ def groups():
|
||||||
"""
|
"""
|
||||||
Group overview, shows all image groups
|
Group overview, shows all image groups
|
||||||
"""
|
"""
|
||||||
groups = db_session.query(db.Groups).all()
|
group_list = db_session.query(db.Groups).all()
|
||||||
|
|
||||||
for group in groups:
|
for group_item in group_list:
|
||||||
thumbnail = db_session.query(db.GroupJunction.post_id).filter(db.GroupJunction.group_id == group.id).order_by(db.GroupJunction.date_added.desc()).first()
|
thumbnail = db_session.query(db.GroupJunction.post_id)\
|
||||||
|
.filter(db.GroupJunction.group_id == group_item.id)\
|
||||||
|
.order_by(db.GroupJunction.date_added.desc())\
|
||||||
|
.first()
|
||||||
|
|
||||||
if thumbnail is not None:
|
if thumbnail:
|
||||||
group.thumbnail = db_session.query(db.Posts.file_name, db.Posts.post_alt, db.Posts.image_colours, db.Posts.id).filter(db.Posts.id == thumbnail[0]).first()
|
group_item.thumbnail = db_session.query(db.Posts.file_name, db.Posts.post_alt,
|
||||||
|
db.Posts.image_colours, db.Posts.id)\
|
||||||
|
.filter(db.Posts.id == thumbnail[0])\
|
||||||
|
.first()
|
||||||
|
|
||||||
return render_template('groups/list.html', groups=groups)
|
return render_template('groups/list.html', groups=group_list)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<int:group_id>')
|
@blueprint.route('/<int:group_id>')
|
||||||
|
@ -38,21 +41,26 @@ def group(group_id):
|
||||||
"""
|
"""
|
||||||
Group view, shows all images in a group
|
Group view, shows all images in a group
|
||||||
"""
|
"""
|
||||||
group = db_session.query(db.Groups).filter(db.Groups.id == group_id).first()
|
group_item = db_session.query(db.Groups).filter(db.Groups.id == group_id).first()
|
||||||
|
|
||||||
if group is None:
|
if group_item is None:
|
||||||
abort(404, 'Group not found! D:')
|
abort(404, 'Group not found! D:')
|
||||||
|
|
||||||
group.author_username = db_session.query(db.Users.username).filter(db.Users.id == group.author_id).first()[0]
|
group_item.author_username = db_session.query(db.Users.username)\
|
||||||
|
.filter(db.Users.id == group_item.author_id)\
|
||||||
|
.first()[0]
|
||||||
|
|
||||||
group_images = db_session.query(db.GroupJunction.post_id).filter(db.GroupJunction.group_id == group_id).order_by(db.GroupJunction.date_added.desc()).all()
|
group_images = db_session.query(db.GroupJunction.post_id)\
|
||||||
|
.filter(db.GroupJunction.group_id == group_id)\
|
||||||
|
.order_by(db.GroupJunction.date_added.desc())\
|
||||||
|
.all()
|
||||||
|
|
||||||
images = []
|
images = []
|
||||||
for image in group_images:
|
for image in group_images:
|
||||||
image = db_session.query(db.Posts).filter(db.Posts.id == image[0]).first()
|
image = db_session.query(db.Posts).filter(db.Posts.id == image[0]).first()
|
||||||
images.append(image)
|
images.append(image)
|
||||||
|
|
||||||
return render_template('groups/group.html', group=group, images=images)
|
return render_template('groups/group.html', group=group_item, images=images)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<int:group_id>/<int:image_id>')
|
@blueprint.route('/<int:group_id>/<int:image_id>')
|
||||||
|
@ -65,16 +73,30 @@ def group_post(group_id, image_id):
|
||||||
if img is None:
|
if img is None:
|
||||||
abort(404, 'Image not found')
|
abort(404, 'Image not found')
|
||||||
|
|
||||||
img.author_username = db_session.query(db.Users.username).filter(db.Users.id == img.author_id).first()[0]
|
img.author_username = db_session.query(db.Users.username)\
|
||||||
|
.filter(db.Users.id == img.author_id)\
|
||||||
|
.first()[0]
|
||||||
|
|
||||||
groups = db_session.query(db.GroupJunction.group_id).filter(db.GroupJunction.post_id == image_id).all()
|
group_list = db_session.query(db.GroupJunction.group_id)\
|
||||||
img.groups = []
|
.filter(db.GroupJunction.post_id == image_id)\
|
||||||
for group in groups:
|
.all()
|
||||||
group = db_session.query(db.Groups).filter(db.Groups.id == group[0]).first()
|
|
||||||
img.groups.append(group)
|
|
||||||
|
|
||||||
next_url = db_session.query(db.GroupJunction.post_id).filter(db.GroupJunction.group_id == group_id).filter(db.GroupJunction.post_id > image_id).order_by(db.GroupJunction.date_added.asc()).first()
|
img.group_list = []
|
||||||
prev_url = db_session.query(db.GroupJunction.post_id).filter(db.GroupJunction.group_id == group_id).filter(db.GroupJunction.post_id < image_id).order_by(db.GroupJunction.date_added.desc()).first()
|
for group_item in group_list:
|
||||||
|
group_item = db_session.query(db.Groups).filter(db.Groups.id == group_item[0]).first()
|
||||||
|
img.group_list.append(group_item)
|
||||||
|
|
||||||
|
next_url = db_session.query(db.GroupJunction.post_id)\
|
||||||
|
.filter(db.GroupJunction.group_id == group_id)\
|
||||||
|
.filter(db.GroupJunction.post_id > image_id)\
|
||||||
|
.order_by(db.GroupJunction.date_added.asc())\
|
||||||
|
.first()
|
||||||
|
|
||||||
|
prev_url = db_session.query(db.GroupJunction.post_id)\
|
||||||
|
.filter(db.GroupJunction.group_id == group_id)\
|
||||||
|
.filter(db.GroupJunction.post_id < image_id)\
|
||||||
|
.order_by(db.GroupJunction.date_added.desc())\
|
||||||
|
.first()
|
||||||
|
|
||||||
if next_url is not None:
|
if next_url is not None:
|
||||||
next_url = url_for('group.group_post', group_id=group_id, image_id=next_url[0])
|
next_url = url_for('group.group_post', group_id=group_id, image_id=next_url[0])
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Onlylegs Gallery - Routing
|
Onlylegs Gallery - Routing
|
||||||
"""
|
"""
|
||||||
from datetime import datetime as dt
|
|
||||||
|
|
||||||
from flask import Blueprint, render_template, url_for
|
from flask import Blueprint, render_template, url_for
|
||||||
from werkzeug.exceptions import abort
|
from werkzeug.exceptions import abort
|
||||||
|
|
||||||
|
@ -36,23 +34,32 @@ def image(image_id):
|
||||||
"""
|
"""
|
||||||
img = db_session.query(db.Posts).filter(db.Posts.id == image_id).first()
|
img = db_session.query(db.Posts).filter(db.Posts.id == image_id).first()
|
||||||
|
|
||||||
if img is None:
|
if not img:
|
||||||
abort(404, 'Image not found :<')
|
abort(404, 'Image not found :<')
|
||||||
|
|
||||||
img.author_username = db_session.query(db.Users.username).filter(db.Users.id == img.author_id).first()[0]
|
img.author_username = db_session.query(db.Users.username)\
|
||||||
|
.filter(db.Users.id == img.author_id).first()[0]
|
||||||
|
|
||||||
|
groups = db_session.query(db.GroupJunction.group_id)\
|
||||||
|
.filter(db.GroupJunction.post_id == image_id).all()
|
||||||
|
|
||||||
groups = db_session.query(db.GroupJunction.group_id).filter(db.GroupJunction.post_id == image_id).all()
|
|
||||||
img.groups = []
|
img.groups = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
group = db_session.query(db.Groups).filter(db.Groups.id == group[0]).first()
|
group = db_session.query(db.Groups).filter(db.Groups.id == group[0]).first()
|
||||||
img.groups.append(group)
|
img.groups.append(group)
|
||||||
|
|
||||||
next_url = db_session.query(db.Posts.id).filter(db.Posts.id > image_id).order_by(db.Posts.id.asc()).first()
|
next_url = db_session.query(db.Posts.id)\
|
||||||
prev_url = db_session.query(db.Posts.id).filter(db.Posts.id < image_id).order_by(db.Posts.id.desc()).first()
|
.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()
|
||||||
|
|
||||||
if next_url is not None:
|
if next_url:
|
||||||
next_url = url_for('gallery.image', image_id=next_url[0])
|
next_url = url_for('gallery.image', image_id=next_url[0])
|
||||||
if prev_url is not None:
|
if prev_url:
|
||||||
prev_url = url_for('gallery.image', image_id=prev_url[0])
|
prev_url = url_for('gallery.image', image_id=prev_url[0])
|
||||||
|
|
||||||
return render_template('image.html', image=img, next_url=next_url, prev_url=prev_url)
|
return render_template('image.html', image=img, next_url=next_url, prev_url=prev_url)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Metadata:
|
||||||
if len(mapping_val[key]) == 2:
|
if len(mapping_val[key]) == 2:
|
||||||
exif[mapping_name][mapping_val[key][0]] = {
|
exif[mapping_name][mapping_val[key][0]] = {
|
||||||
'raw': value,
|
'raw': value,
|
||||||
'formatted': getattr(helpers, mapping_val[key][1])(value),
|
'formatted': getattr(helpers, mapping_val[key][1])(value), # pylint: disable=E0602
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
exif[mapping_name][mapping_val[key][0]] = {
|
exif[mapping_name][mapping_val[key][0]] = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue