mirror of
https://github.com/TrentSPalmer/flask_photo_scaling_app.git
synced 2025-02-18 13:40:55 -08:00
fix style app/photo_routes/delete_download.py
This commit is contained in:
parent
bab12d33e9
commit
b3f0de046b
@ -1,6 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flask import Blueprint, request, redirect, url_for, render_template, current_app, send_file
|
||||
from flask import (
|
||||
Blueprint, request, redirect, url_for,
|
||||
render_template, current_app, send_file,
|
||||
)
|
||||
from flask_login import current_user
|
||||
from app.models import Photo
|
||||
from app.forms import ConfirmPhotoDelete
|
||||
@ -17,7 +20,10 @@ def download():
|
||||
if current_user.is_authenticated:
|
||||
f = request.args['file']
|
||||
try:
|
||||
return send_file('/var/lib/photo_app/photos/{}'.format(f), attachment_filename=f)
|
||||
return send_file(
|
||||
'/var/lib/photo_app/photos/{}'.format(f),
|
||||
attachment_filename=f,
|
||||
)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
@ -27,11 +33,14 @@ def delete():
|
||||
photo = Photo.query.get(request.args['photo_id'])
|
||||
if photo is None:
|
||||
return(redirect(url_for('proute.index')))
|
||||
if not current_user.is_authenticated or photo.contributor_id != current_user.id:
|
||||
cu = current_user
|
||||
if not cu.is_authenticated or photo.contributor_id != cu.id:
|
||||
return(redirect(url_for('proute.index')))
|
||||
form = ConfirmPhotoDelete()
|
||||
if request.method == 'POST' and form.validate_on_submit():
|
||||
return(redirect(url_for('p_route.photo', photo_id=delete_photo(photo))))
|
||||
return(
|
||||
redirect(url_for('p_route.photo', photo_id=delete_photo(photo))),
|
||||
)
|
||||
return(render_template(
|
||||
'delete_photo.html',
|
||||
title="Delete Photo?",
|
||||
@ -49,11 +58,19 @@ def delete_photo(photo):
|
||||
password=current_app.config['DATABASE_PASSWORD']
|
||||
)
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT count(id) FROM photo WHERE contributor_id=%s AND id>%s", (photo.contributor_id, photo.id))
|
||||
cur.execute(
|
||||
"SELECT count(id) FROM photo WHERE contributor_id=%s AND id>%s",
|
||||
(photo.contributor_id, photo.id),
|
||||
)
|
||||
if cur.fetchone()[0] == 0:
|
||||
cur.execute("SELECT id FROM photo WHERE contributor_id=%s ORDER BY id", (photo.contributor_id, ))
|
||||
cur.execute(
|
||||
"SELECT id FROM photo WHERE contributor_id=%s ORDER BY id",
|
||||
(photo.contributor_id, ),
|
||||
)
|
||||
else:
|
||||
cur.execute("SELECT id FROM photo WHERE contributor_id=%s AND id>%s ORDER BY id", (photo.contributor_id, photo.id))
|
||||
my_statement = "SELECT id FROM photo WHERE contributor_id=%s "
|
||||
my_statement += "AND id>%s ORDER BY id"
|
||||
cur.execute(my_statement, (photo.contributor_id, photo.id))
|
||||
next_photo_id = cur.fetchone()[0]
|
||||
os.chdir(current_app.config['PHOTO_SAVE_PATH'])
|
||||
if os.path.exists('raw_' + photo.photo_name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user