mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-01-15 11:05:23 +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
|
||||||
|
@ -114,7 +120,7 @@ def create_app(): # pylint: disable=R0914
|
||||||
app.register_blueprint(view_group.blueprint)
|
app.register_blueprint(view_group.blueprint)
|
||||||
app.register_blueprint(view_profile.blueprint)
|
app.register_blueprint(view_profile.blueprint)
|
||||||
app.register_blueprint(view_settings.blueprint)
|
app.register_blueprint(view_settings.blueprint)
|
||||||
|
|
||||||
# APIS
|
# APIS
|
||||||
app.register_blueprint(api_media.blueprint)
|
app.register_blueprint(api_media.blueprint)
|
||||||
app.register_blueprint(api_group.blueprint)
|
app.register_blueprint(api_group.blueprint)
|
||||||
|
|
|
@ -43,12 +43,14 @@ def account_picture(user_id):
|
||||||
if img_ext not in current_app.config["ALLOWED_EXTENSIONS"].keys():
|
if img_ext not in current_app.config["ALLOWED_EXTENSIONS"].keys():
|
||||||
logging.info("File extension not allowed: %s", img_ext)
|
logging.info("File extension not allowed: %s", img_ext)
|
||||||
return jsonify({"error": "File extension not allowed"}), 403
|
return jsonify({"error": "File extension not allowed"}), 403
|
||||||
|
|
||||||
if user.picture:
|
if user.picture:
|
||||||
# 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
|
||||||
|
@ -76,7 +78,7 @@ def account_username(user_id):
|
||||||
"""
|
"""
|
||||||
user = db.get_or_404(User, user_id)
|
user = db.get_or_404(User, user_id)
|
||||||
new_name = request.form["name"]
|
new_name = request.form["name"]
|
||||||
|
|
||||||
username_regex = re.compile(r"\b[A-Za-z0-9._-]+\b")
|
username_regex = re.compile(r"\b[A-Za-z0-9._-]+\b")
|
||||||
|
|
||||||
# Validate the form
|
# Validate the form
|
||||||
|
@ -84,7 +86,7 @@ def account_username(user_id):
|
||||||
return jsonify({"error": "Username is invalid"}), 400
|
return jsonify({"error": "Username is invalid"}), 400
|
||||||
elif user.id != current_user.id:
|
elif user.id != current_user.id:
|
||||||
return jsonify({"error": "You are not allowed to do this, go away"}), 403
|
return jsonify({"error": "You are not allowed to do this, go away"}), 403
|
||||||
|
|
||||||
# Save to database
|
# Save to database
|
||||||
user.username = new_name
|
user.username = new_name
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""
|
"""
|
||||||
Gwa Gwa!
|
Gwa Gwa!
|
||||||
"""
|
"""
|
||||||
print("Gwa Gwa!")
|
print("Gwa Gwa!")
|
||||||
|
|
Loading…
Reference in a new issue