mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26: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
|
||||
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")
|
||||
|
||||
# App configuration
|
||||
|
|
|
@ -38,18 +38,9 @@ def get_file(file_name):
|
|||
"""
|
||||
# Get args
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
if res:
|
||||
if res == 'thumb' or res == 'thumbnail':
|
||||
if res in ['thumb', 'thumbnail']:
|
||||
width, height = 400, 400
|
||||
elif res == 'prev' or res == 'preview':
|
||||
elif res in ['prev', 'preview']:
|
||||
width, height = 1920, 1080
|
||||
else:
|
||||
try:
|
||||
|
@ -94,7 +85,7 @@ def get_file(file_name):
|
|||
|
||||
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:
|
||||
# pass
|
||||
|
||||
|
@ -245,10 +236,16 @@ def modify_group():
|
|||
abort(403)
|
||||
|
||||
if request.form['action'] == 'add':
|
||||
if db_session.query(db.GroupJunction).filter_by(group_id=group_id, post_id=image_id).first() is None:
|
||||
db_session.add(db.GroupJunction(group_id=group_id, post_id=image_id, date_added=dt.utcnow()))
|
||||
if not db_session.query(db.GroupJunction)\
|
||||
.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':
|
||||
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()
|
||||
|
||||
|
@ -262,7 +259,7 @@ def metadata(img_id):
|
|||
"""
|
||||
img = db_session.query(db.Posts).filter_by(id=img_id).first()
|
||||
|
||||
if img is None:
|
||||
if not img:
|
||||
abort(404)
|
||||
|
||||
img_path = os.path.join(current_app.config['UPLOAD_FOLDER'], img.file_name)
|
||||
|
@ -279,7 +276,7 @@ def logfile():
|
|||
"""
|
||||
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):
|
||||
line = line.split(' : ')
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
"""
|
||||
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
|
||||
import json
|
||||
from datetime import datetime as dt
|
||||
|
||||
from flask import Blueprint, abort, jsonify, render_template, url_for, request, g
|
||||
from flask import Blueprint, abort, render_template, url_for
|
||||
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from gallery import db
|
||||
|
@ -22,15 +19,21 @@ def 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:
|
||||
thumbnail = db_session.query(db.GroupJunction.post_id).filter(db.GroupJunction.group_id == group.id).order_by(db.GroupJunction.date_added.desc()).first()
|
||||
for group_item in group_list:
|
||||
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:
|
||||
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()
|
||||
if thumbnail:
|
||||
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>')
|
||||
|
@ -38,21 +41,26 @@ def group(group_id):
|
|||
"""
|
||||
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:')
|
||||
|
||||
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 = []
|
||||
for image in group_images:
|
||||
image = db_session.query(db.Posts).filter(db.Posts.id == image[0]).first()
|
||||
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>')
|
||||
|
@ -65,16 +73,30 @@ def group_post(group_id, image_id):
|
|||
if img is None:
|
||||
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()
|
||||
img.groups = []
|
||||
for group in groups:
|
||||
group = db_session.query(db.Groups).filter(db.Groups.id == group[0]).first()
|
||||
img.groups.append(group)
|
||||
group_list = db_session.query(db.GroupJunction.group_id)\
|
||||
.filter(db.GroupJunction.post_id == image_id)\
|
||||
.all()
|
||||
|
||||
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()
|
||||
img.group_list = []
|
||||
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:
|
||||
next_url = url_for('group.group_post', group_id=group_id, image_id=next_url[0])
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""
|
||||
Onlylegs Gallery - Routing
|
||||
"""
|
||||
from datetime import datetime as dt
|
||||
|
||||
from flask import Blueprint, render_template, url_for
|
||||
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()
|
||||
|
||||
if img is None:
|
||||
if not img:
|
||||
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 = []
|
||||
for group in groups:
|
||||
group = db_session.query(db.Groups).filter(db.Groups.id == group[0]).first()
|
||||
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()
|
||||
prev_url = db_session.query(db.Posts.id).filter(db.Posts.id < image_id).order_by(db.Posts.id.desc()).first()
|
||||
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()
|
||||
|
||||
if next_url is not None:
|
||||
if next_url:
|
||||
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])
|
||||
|
||||
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:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
'raw': value,
|
||||
'formatted': getattr(helpers, mapping_val[key][1])(value),
|
||||
'formatted': getattr(helpers, mapping_val[key][1])(value), # pylint: disable=E0602
|
||||
}
|
||||
else:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue