mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Change database structure
Update naming to something more useful Date filled in automatically
This commit is contained in:
parent
bf083a85ad
commit
4627498b8d
11 changed files with 83 additions and 89 deletions
|
@ -5,10 +5,9 @@ from uuid import uuid4
|
|||
import os
|
||||
import pathlib
|
||||
import logging
|
||||
from datetime import datetime as dt
|
||||
import platformdirs
|
||||
|
||||
from flask import Blueprint, send_from_directory, abort, flash, jsonify, request, current_app
|
||||
from flask import Blueprint, send_from_directory, abort, flash, request, current_app
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from flask_login import login_required, current_user
|
||||
|
@ -65,7 +64,7 @@ def upload():
|
|||
|
||||
# Get file extension, generate random name and set file path
|
||||
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)
|
||||
|
||||
# Check if file extension is allowed
|
||||
|
@ -85,13 +84,12 @@ def upload():
|
|||
|
||||
# Save to database
|
||||
query = db.Posts(author_id=current_user.id,
|
||||
created_at=dt.utcnow(),
|
||||
file_name=img_name+'.'+img_ext,
|
||||
file_type=img_ext,
|
||||
image_exif=img_exif,
|
||||
image_colours=img_colors,
|
||||
post_description=form['description'],
|
||||
post_alt=form['alt'])
|
||||
filename=img_name + '.' + img_ext,
|
||||
mimetype=img_ext,
|
||||
exif=img_exif,
|
||||
colours=img_colors,
|
||||
description=form['description'],
|
||||
alt=form['alt'])
|
||||
|
||||
db_session.add(query)
|
||||
db_session.commit()
|
||||
|
@ -115,13 +113,13 @@ def delete_image(image_id):
|
|||
|
||||
# Delete file
|
||||
try:
|
||||
os.remove(os.path.join(current_app.config['UPLOAD_FOLDER'], img.file_name))
|
||||
os.remove(os.path.join(current_app.config['UPLOAD_FOLDER'], img.filename))
|
||||
except FileNotFoundError:
|
||||
logging.warning('File not found: %s, already deleted or never existed', img.file_name)
|
||||
logging.warning('File not found: %s, already deleted or never existed', img.filename)
|
||||
|
||||
# Delete cached files
|
||||
cache_path = os.path.join(platformdirs.user_config_dir('onlylegs'), 'cache')
|
||||
cache_name = img.file_name.rsplit('.')[0]
|
||||
cache_name = img.filename.rsplit('.')[0]
|
||||
for cache_file in pathlib.Path(cache_path).glob(cache_name + '*'):
|
||||
os.remove(cache_file)
|
||||
|
||||
|
@ -136,7 +134,7 @@ def delete_image(image_id):
|
|||
# Commit all changes
|
||||
db_session.commit()
|
||||
|
||||
logging.info('Removed image (%s) %s', image_id, img.file_name)
|
||||
logging.info('Removed image (%s) %s', image_id, img.filename)
|
||||
flash(['Image was all in Le Head!', '1'])
|
||||
return 'Gwa Gwa'
|
||||
|
||||
|
@ -149,8 +147,7 @@ def create_group():
|
|||
"""
|
||||
new_group = db.Groups(name=request.form['name'],
|
||||
description=request.form['description'],
|
||||
author_id=current_user.id,
|
||||
created_at=dt.utcnow())
|
||||
author_id=current_user.id)
|
||||
|
||||
db_session.add(new_group)
|
||||
db_session.commit()
|
||||
|
@ -180,8 +177,7 @@ def modify_group():
|
|||
.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()))
|
||||
post_id=image_id))
|
||||
elif request.form['action'] == 'remove':
|
||||
(db_session.query(db.GroupJunction)
|
||||
.filter_by(group_id=group_id, post_id=image_id)
|
||||
|
|
|
@ -37,8 +37,8 @@ def groups():
|
|||
# For each image, get the image data and add it to the group item
|
||||
group.images = []
|
||||
for image in images:
|
||||
group.images.append(db_session.query(db.Posts.file_name, db.Posts.post_alt,
|
||||
db.Posts.image_colours, db.Posts.id)
|
||||
group.images.append(db_session.query(db.Posts.filename, db.Posts.alt,
|
||||
db.Posts.colours, db.Posts.id)
|
||||
.filter(db.Posts.id == image[0])
|
||||
.first())
|
||||
|
||||
|
@ -79,7 +79,7 @@ def group(group_id):
|
|||
# Check contrast for the first image in the group for the banner
|
||||
text_colour = 'rgb(var(--fg-black))'
|
||||
if images:
|
||||
text_colour = contrast.contrast(images[0].image_colours[0],
|
||||
text_colour = contrast.contrast(images[0].colours[0],
|
||||
'rgb(var(--fg-black))',
|
||||
'rgb(var(--fg-white))')
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ def index():
|
|||
"""
|
||||
Home page of the website, shows the feed of the latest images
|
||||
"""
|
||||
images = db_session.query(db.Posts.file_name,
|
||||
db.Posts.post_alt,
|
||||
db.Posts.image_colours,
|
||||
images = db_session.query(db.Posts.filename,
|
||||
db.Posts.alt,
|
||||
db.Posts.colours,
|
||||
db.Posts.created_at,
|
||||
db.Posts.id).order_by(db.Posts.id.desc()).all()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue