mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-01-28 17:18:24 +00:00
Run files through Black
This commit is contained in:
parent
60e7078e13
commit
dd0e009200
|
@ -15,7 +15,13 @@ from werkzeug.security import generate_password_hash
|
||||||
from onlylegs.extensions import db, migrate, login_manager, assets, compress, cache
|
from onlylegs.extensions import db, migrate, login_manager, assets, compress, cache
|
||||||
from onlylegs.config import INSTANCE_DIR, MIGRATIONS_DIR
|
from onlylegs.config import INSTANCE_DIR, MIGRATIONS_DIR
|
||||||
from onlylegs.models import User
|
from onlylegs.models import User
|
||||||
from onlylegs.views import index as view_index, image as view_image, group as view_group, settings as view_settings, profile as view_profile
|
from onlylegs.views import (
|
||||||
|
index as view_index,
|
||||||
|
image as view_image,
|
||||||
|
group as view_group,
|
||||||
|
settings as view_settings,
|
||||||
|
profile as view_profile,
|
||||||
|
)
|
||||||
from onlylegs.api import media as api_media, group as api_group, account as api_account
|
from onlylegs.api import media as api_media, group as api_group, account as api_account
|
||||||
from onlylegs import auth as view_auth
|
from onlylegs import auth as view_auth
|
||||||
from onlylegs import gwagwa
|
from onlylegs import gwagwa
|
||||||
|
|
|
@ -48,7 +48,9 @@ def account_picture(user_id):
|
||||||
# Delete cached files and old image
|
# Delete cached files and old image
|
||||||
os.remove(os.path.join(current_app.config["PFP_FOLDER"], user.picture))
|
os.remove(os.path.join(current_app.config["PFP_FOLDER"], user.picture))
|
||||||
cache_name = user.picture.rsplit(".")[0]
|
cache_name = user.picture.rsplit(".")[0]
|
||||||
for cache_file in pathlib.Path(current_app.config["CACHE_FOLDER"]).glob(cache_name + "*"):
|
for cache_file in pathlib.Path(current_app.config["CACHE_FOLDER"]).glob(
|
||||||
|
cache_name + "*"
|
||||||
|
):
|
||||||
os.remove(cache_file)
|
os.remove(cache_file)
|
||||||
|
|
||||||
# Save file
|
# Save file
|
||||||
|
|
|
@ -45,7 +45,12 @@ def modify_group():
|
||||||
if group.author_id != current_user.id:
|
if group.author_id != current_user.id:
|
||||||
return jsonify({"message": "You are not the owner of this group"}), 403
|
return jsonify({"message": "You are not the owner of this group"}), 403
|
||||||
|
|
||||||
if (action == "add" and not GroupJunction.query.filter_by(group_id=group_id, post_id=image_id).first()):
|
if (
|
||||||
|
action == "add"
|
||||||
|
and not GroupJunction.query.filter_by(
|
||||||
|
group_id=group_id, post_id=image_id
|
||||||
|
).first()
|
||||||
|
):
|
||||||
db.session.add(GroupJunction(group_id=group_id, post_id=image_id))
|
db.session.add(GroupJunction(group_id=group_id, post_id=image_id))
|
||||||
elif request.form["action"] == "remove":
|
elif request.form["action"] == "remove":
|
||||||
GroupJunction.query.filter_by(group_id=group_id, post_id=image_id).delete()
|
GroupJunction.query.filter_by(group_id=group_id, post_id=image_id).delete()
|
||||||
|
|
|
@ -8,7 +8,15 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import Blueprint, flash, abort, send_from_directory, jsonify, request, current_app
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
flash,
|
||||||
|
abort,
|
||||||
|
send_from_directory,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
current_app,
|
||||||
|
)
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from colorthief import ColorThief
|
from colorthief import ColorThief
|
||||||
|
@ -61,7 +69,9 @@ def upload():
|
||||||
# Get file extension, generate random name and set file path
|
# Get file extension, generate random name and set file path
|
||||||
img_ext = pathlib.Path(form_file.filename).suffix.replace(".", "").lower()
|
img_ext = pathlib.Path(form_file.filename).suffix.replace(".", "").lower()
|
||||||
img_name = "GWAGWA_" + str(uuid4())
|
img_name = "GWAGWA_" + str(uuid4())
|
||||||
img_path = os.path.join(current_app.config["UPLOAD_FOLDER"], img_name + "." + img_ext)
|
img_path = os.path.join(
|
||||||
|
current_app.config["UPLOAD_FOLDER"], img_name + "." + img_ext
|
||||||
|
)
|
||||||
|
|
||||||
# Check if file extension is allowed
|
# Check if file extension is allowed
|
||||||
if img_ext not in current_app.config["ALLOWED_EXTENSIONS"].keys():
|
if img_ext not in current_app.config["ALLOWED_EXTENSIONS"].keys():
|
||||||
|
@ -106,17 +116,24 @@ def delete_image(image_id):
|
||||||
# Check if image exists and if user is allowed to delete it (author)
|
# Check if image exists and if user is allowed to delete it (author)
|
||||||
if post.author_id != current_user.id:
|
if post.author_id != current_user.id:
|
||||||
logging.info("User %s tried to delete image %s", current_user.id, image_id)
|
logging.info("User %s tried to delete image %s", current_user.id, image_id)
|
||||||
return jsonify({"message": "You are not allowed to delete this image, heck off"}), 403
|
return (
|
||||||
|
jsonify({"message": "You are not allowed to delete this image, heck off"}),
|
||||||
|
403,
|
||||||
|
)
|
||||||
|
|
||||||
# Delete file
|
# Delete file
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(current_app.config["UPLOAD_FOLDER"], post.filename))
|
os.remove(os.path.join(current_app.config["UPLOAD_FOLDER"], post.filename))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logging.warning("File not found: %s, already deleted or never existed", post.filename)
|
logging.warning(
|
||||||
|
"File not found: %s, already deleted or never existed", post.filename
|
||||||
|
)
|
||||||
|
|
||||||
# Delete cached files
|
# Delete cached files
|
||||||
cache_name = post.filename.rsplit(".")[0]
|
cache_name = post.filename.rsplit(".")[0]
|
||||||
for cache_file in pathlib.Path(current_app.config["CACHE_FOLDER"]).glob(cache_name + "*"):
|
for cache_file in pathlib.Path(current_app.config["CACHE_FOLDER"]).glob(
|
||||||
|
cache_name + "*"
|
||||||
|
):
|
||||||
os.remove(cache_file)
|
os.remove(cache_file)
|
||||||
|
|
||||||
GroupJunction.query.filter_by(post_id=image_id).delete()
|
GroupJunction.query.filter_by(post_id=image_id).delete()
|
||||||
|
|
Loading…
Reference in a new issue