major styling pass, artist list, and import processing improvements
This commit is contained in:
+41
-9
@@ -14,7 +14,18 @@ main = Blueprint('main', __name__)
|
||||
|
||||
@main.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
from random import choice
|
||||
from app.models import ImageRecord
|
||||
|
||||
image = ImageRecord.query.order_by(func.random()).first()
|
||||
background_url = None
|
||||
|
||||
if image:
|
||||
filename = image.filepath.replace('/images/', '')
|
||||
background_url = url_for('main.serve_image', filename=filename)
|
||||
|
||||
return render_template('index.html', background_url=background_url)
|
||||
|
||||
|
||||
@main.route('/gallery')
|
||||
@login_required
|
||||
@@ -25,11 +36,12 @@ def gallery():
|
||||
).limit(recent_images).all()
|
||||
return render_template('gallery.html', images=images)
|
||||
|
||||
@main.route('/static/images/<path:filename>')
|
||||
@main.route('/images/<path:filename>')
|
||||
def serve_image(filename):
|
||||
return send_from_directory('/images', filename)
|
||||
|
||||
@main.route('/artist/<artist_name>')
|
||||
@login_required
|
||||
def artist_gallery(artist_name):
|
||||
per_page=49
|
||||
page = request.args.get('page', 1, type=int)
|
||||
@@ -38,6 +50,30 @@ def artist_gallery(artist_name):
|
||||
).paginate(page=page, per_page=per_page)
|
||||
return render_template('artist_gallery.html', images=images, artist=artist_name)
|
||||
|
||||
@main.route('/artists')
|
||||
@login_required
|
||||
def artist_list():
|
||||
from app.models import ImageRecord
|
||||
from sqlalchemy import func
|
||||
|
||||
# Define how many images to show per artist card
|
||||
images_per_artist = 3 # Change this value to tweak
|
||||
|
||||
# Get all unique artist names
|
||||
artists = db.session.query(ImageRecord.artist).distinct().all()
|
||||
artist_data = []
|
||||
|
||||
for (artist,) in artists:
|
||||
images = (
|
||||
ImageRecord.query
|
||||
.filter_by(artist=artist)
|
||||
.order_by(ImageRecord.taken_at.desc().nullslast(), ImageRecord.imported_at.desc())
|
||||
.limit(images_per_artist)
|
||||
.all()
|
||||
)
|
||||
artist_data.append({'name': artist, 'images': images})
|
||||
|
||||
return render_template('artist_list.html', artist_data=artist_data, images_per_artist=images_per_artist)
|
||||
|
||||
@main.route('/settings')
|
||||
@login_required
|
||||
@@ -49,13 +85,9 @@ def settings():
|
||||
@main.route('/import-images')
|
||||
@login_required
|
||||
def trigger_image_import():
|
||||
if not current_user.is_admin:
|
||||
abort(403)
|
||||
source_dir = '/import'
|
||||
dest_dir = '/images'
|
||||
|
||||
result = import_images_task(source_dir, dest_dir)
|
||||
flash(f"Image import completed: {result}")
|
||||
with open('/import/trigger.flag', 'w') as f:
|
||||
f.write('start')
|
||||
flash("Image import triggered.")
|
||||
return redirect(url_for('main.settings'))
|
||||
|
||||
@main.route('/reset-db', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user