mirror of
https://github.com/TrentSPalmer/flask_photo_scaling_app.git
synced 2025-07-05 11:43:16 -07:00
refactor with blueprints
This commit is contained in:
68
app/photo_routes/delete_download.py
Normal file
68
app/photo_routes/delete_download.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
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
|
||||
import psycopg2
|
||||
import os
|
||||
|
||||
d_d = Blueprint(
|
||||
"d_d", __name__, template_folder="templates"
|
||||
)
|
||||
|
||||
|
||||
@d_d.route('/download')
|
||||
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)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
|
||||
@d_d.route('/delete', methods=['GET', 'POST'])
|
||||
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:
|
||||
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(render_template(
|
||||
'delete_photo.html',
|
||||
title="Delete Photo?",
|
||||
photo=photo,
|
||||
photo_url=current_app.config['PHOTO_URL'],
|
||||
form=form
|
||||
))
|
||||
|
||||
|
||||
def delete_photo(photo):
|
||||
conn = psycopg2.connect(
|
||||
dbname=current_app.config['DATABASE_NAME'],
|
||||
user=current_app.config['DATABASE_USER'],
|
||||
host=current_app.config['DATABASE_HOST'],
|
||||
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))
|
||||
if cur.fetchone()[0] == 0:
|
||||
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))
|
||||
next_photo_id = cur.fetchone()[0]
|
||||
os.chdir(current_app.config['PHOTO_SAVE_PATH'])
|
||||
if os.path.exists('raw_' + photo.photo_name):
|
||||
os.remove('raw_' + photo.photo_name)
|
||||
if os.path.exists('1280_' + photo.photo_name):
|
||||
os.remove('1280_' + photo.photo_name)
|
||||
if os.path.exists('480_' + photo.photo_name):
|
||||
os.remove('480_' + photo.photo_name)
|
||||
cur.execute("DELETE FROM photo WHERE id=%s", (photo.id, ))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return next_photo_id
|
44
app/photo_routes/photo_upload.py
Normal file
44
app/photo_routes/photo_upload.py
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, abort
|
||||
from app.forms import UploadPhotoForm
|
||||
from .scripts.process_uploaded_photo import process_uploaded_photo
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
pupload = Blueprint(
|
||||
"pupload", __name__, template_folder="templates"
|
||||
)
|
||||
|
||||
|
||||
@pupload.route('/photo-upload', methods=['GET', 'POST'])
|
||||
def photo_upload():
|
||||
if not current_user.is_authenticated:
|
||||
return(redirect(url_for('proute.index')))
|
||||
form = UploadPhotoForm()
|
||||
if request.method == 'POST' and form.validate_on_submit():
|
||||
f = request.files['image']
|
||||
filename = secure_filename(f.filename)
|
||||
if filename != '':
|
||||
import os
|
||||
file_ext = os.path.splitext(filename)[1]
|
||||
if file_ext not in ['.jpg', '.png'] or file_ext != validate_image(f.stream):
|
||||
abort(400)
|
||||
f.save(os.path.join(current_app.config['PHOTO_SAVE_PATH'], 'raw_' + filename))
|
||||
photo_id = process_uploaded_photo(filename, current_user, current_app.config)
|
||||
print(photo_id)
|
||||
flash("Thanks for the new photo!")
|
||||
return(redirect(url_for('p_route.photo', photo_id=photo_id)))
|
||||
return(redirect(url_for('proute.index')))
|
||||
return render_template('upload.html', title="Photo Upload", form=form)
|
||||
|
||||
|
||||
def validate_image(stream):
|
||||
import imghdr
|
||||
header = stream.read(512)
|
||||
stream.seek(0)
|
||||
format = imghdr.what(None, header)
|
||||
if not format:
|
||||
return None
|
||||
return '.' + (format if format != 'jpeg' else 'jpg')
|
76
app/photo_routes/photox.py
Normal file
76
app/photo_routes/photox.py
Normal file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flask import Blueprint, redirect, url_for, current_app, render_template
|
||||
from flask_login import current_user
|
||||
from app.models import Photo
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
|
||||
p_route = Blueprint(
|
||||
"p_route", __name__, template_folder="templates"
|
||||
)
|
||||
|
||||
|
||||
@p_route.route('/photo/<int:photo_id>')
|
||||
def photo(photo_id):
|
||||
photo = Photo.query.get(photo_id)
|
||||
if not current_user.is_authenticated or photo is None:
|
||||
return(redirect(url_for('proute.index')))
|
||||
find_next_previous(photo)
|
||||
calc_additional_data(photo)
|
||||
return render_template(
|
||||
'photo.html',
|
||||
title="Photo",
|
||||
photo=photo,
|
||||
photo_url=current_app.config['PHOTO_URL']
|
||||
)
|
||||
|
||||
|
||||
def find_next_previous(photo):
|
||||
conn = psycopg2.connect(
|
||||
dbname=current_app.config['DATABASE_NAME'],
|
||||
user=current_app.config['DATABASE_USER'],
|
||||
host=current_app.config['DATABASE_HOST'],
|
||||
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))
|
||||
count = cur.fetchone()[0]
|
||||
if count == 0:
|
||||
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))
|
||||
photo.next_photo_id = cur.fetchone()[0]
|
||||
cur.execute("SELECT count(id) FROM photo WHERE contributor_id=%s AND id < %s", (photo.contributor_id, photo.id))
|
||||
count = cur.fetchone()[0]
|
||||
if count == 0:
|
||||
cur.execute("SELECT id FROM photo WHERE contributor_id=%s ORDER BY id DESC", (photo.contributor_id, ))
|
||||
else:
|
||||
cur.execute("SELECT id FROM photo WHERE contributor_id=%s AND id < %s ORDER BY id DESC", (photo.contributor_id, photo.id))
|
||||
photo.previous_photo_id = cur.fetchone()[0]
|
||||
conn.close()
|
||||
|
||||
|
||||
def calc_additional_data(photo):
|
||||
photo.UploadDate = photo.timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if photo.photo_raw_size >= 1048576:
|
||||
photo.SizeOnDisc = str(round(photo.photo_raw_size / 1048576, 1)) + 'M'
|
||||
else:
|
||||
photo.SizeOnDisc = str(round(photo.photo_raw_size / 1024, 1)) + 'K'
|
||||
if photo.photo_1280_size >= 1048576:
|
||||
photo.SizeOnDisc1280 = str(round(photo.photo_1280_size / 1048576, 1)) + 'M'
|
||||
else:
|
||||
photo.SizeOnDisc1280 = str(round(photo.photo_1280_size / 1024, 1)) + 'K'
|
||||
if photo.photo_480_size >= 1048576:
|
||||
photo.SizeOnDisc480 = str(round(photo.photo_480_size / 1048576, 1)) + 'M'
|
||||
else:
|
||||
photo.SizeOnDisc480 = str(round(photo.photo_480_size / 1024, 1)) + 'K'
|
||||
if photo.GPSAltitude is not None:
|
||||
photo.GPSAltitudeFeet = round(photo.GPSAltitude * 3.28084, 1)
|
||||
else:
|
||||
photo.GPSAltitudeFeet = None
|
||||
if photo.GPSLatitude is not None and photo.GPSLongitude is not None:
|
||||
photo.LatLong = "{},{}".format(photo.GPSLatitude, photo.GPSLongitude)
|
||||
photo.MapUrl = "https://www.google.com/maps/search/?api=1&query={}".format(photo.LatLong)
|
||||
else:
|
||||
photo.LatLong, photo.MapUrl = None, None
|
48
app/photo_routes/proutes.py
Normal file
48
app/photo_routes/proutes.py
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flask import Blueprint, flash, render_template, current_app
|
||||
from flask_login import current_user
|
||||
from shutil import disk_usage
|
||||
import psycopg2
|
||||
|
||||
proute = Blueprint(
|
||||
"proute", __name__, template_folder="templates"
|
||||
)
|
||||
|
||||
|
||||
@proute.route("/")
|
||||
@proute.route("/index")
|
||||
def index():
|
||||
if current_user.is_authenticated:
|
||||
photos = get_photo_list(current_user.id)
|
||||
flash(get_disk_stats())
|
||||
return(render_template(
|
||||
'index.html',
|
||||
title="Photos",
|
||||
photos=photos,
|
||||
photo_url=current_app.config['PHOTO_URL']
|
||||
))
|
||||
return render_template('index.html', title="Photos")
|
||||
|
||||
|
||||
def get_photo_list(contributor_id):
|
||||
conn = psycopg2.connect(
|
||||
dbname=current_app.config['DATABASE_NAME'],
|
||||
user=current_app.config['DATABASE_USER'],
|
||||
host=current_app.config['DATABASE_HOST'],
|
||||
password=current_app.config['DATABASE_PASSWORD']
|
||||
)
|
||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
cur.execute("SELECT photo_name,id FROM photo WHERE contributor_id=%s ORDER BY timestamp,\"DateTimeOriginal\" DESC", (contributor_id, ))
|
||||
photos = cur.fetchall()
|
||||
conn.close()
|
||||
return photos
|
||||
|
||||
|
||||
def get_disk_stats():
|
||||
disk_stats = disk_usage('/')
|
||||
return("Used {}GB of {}GB, {}GB free".format(
|
||||
round(disk_stats.used / 1073741824, 1),
|
||||
round(disk_stats.total / 1073741824, 1),
|
||||
round(disk_stats.free / 1073741824, 1)
|
||||
))
|
26
app/photo_routes/scripts/crop_photo.py
Normal file
26
app/photo_routes/scripts/crop_photo.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
|
||||
def crop_photo(photo, photo_save_path):
|
||||
photo_1280 = '1280_' + photo
|
||||
photo_480 = '480_' + photo
|
||||
processing_tuple = ((1280, photo_1280), (480, photo_480))
|
||||
os.chdir(photo_save_path)
|
||||
img = Image.open('raw_' + photo)
|
||||
if img.size[0] > img.size[1]:
|
||||
for x in processing_tuple:
|
||||
basewidth = x[0]
|
||||
wpercent = (basewidth / float(img.size[0]))
|
||||
hsize = int(float(img.size[1] * float(wpercent)))
|
||||
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
||||
img.save(x[1])
|
||||
else:
|
||||
for x in processing_tuple:
|
||||
baseheight = x[0]
|
||||
hpercent = (baseheight / float(img.size[1]))
|
||||
wsize = int(float(img.size[0] * float(hpercent)))
|
||||
img = img.resize((wsize, baseheight), Image.ANTIALIAS)
|
||||
img.save(x[1])
|
95
app/photo_routes/scripts/get_exif_data.py
Normal file
95
app/photo_routes/scripts/get_exif_data.py
Normal file
@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from PIL import Image
|
||||
from PIL.ExifTags import TAGS, GPSTAGS
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_exif_data(photo):
|
||||
exif_data = {}
|
||||
get_file_sizes(photo, exif_data)
|
||||
return(exif_data)
|
||||
|
||||
|
||||
def get_exif(img_raw, exif_data):
|
||||
if hasattr(img_raw, '_getexif'):
|
||||
exifdata = img_raw._getexif()
|
||||
if exifdata is not None:
|
||||
date_format = "%Y:%m:%d %H:%M:%S"
|
||||
for k, v in TAGS.items():
|
||||
if k in exifdata:
|
||||
if v == "Make":
|
||||
exif_data['Make'] = exifdata[k]
|
||||
if v == "Model":
|
||||
exif_data['Model'] = exifdata[k]
|
||||
if v == "Software":
|
||||
exif_data['Software'] = exifdata[k]
|
||||
if v == "DateTime":
|
||||
exif_data['DateTime'] = datetime.strptime(exifdata[k], date_format)
|
||||
if v == "DateTimeOriginal":
|
||||
exif_data['DateTimeOriginal'] = datetime.strptime(exifdata[k], date_format)
|
||||
if v == "DateTimeDigitized":
|
||||
exif_data['DateTimeDigitized'] = datetime.strptime(exifdata[k], date_format)
|
||||
if v == "FNumber":
|
||||
exif_data['fnumber'] = round(exifdata[k][0] / exifdata[k][1], 1)
|
||||
if v == "DigitalZoomRatio":
|
||||
exif_data['DigitalZoomRatio'] = round(exifdata[k][0] / exifdata[k][1], 2)
|
||||
if v == "TimeZoneOffset":
|
||||
exif_data['TimeZoneOffset'] = exifdata[k]
|
||||
if v == "GPSInfo":
|
||||
gpsinfo = {}
|
||||
for h, i in GPSTAGS.items():
|
||||
if h in exifdata[k]:
|
||||
if i == 'GPSAltitudeRef':
|
||||
gpsinfo['GPSAltitudeRef'] = int.from_bytes(exifdata[k][h], "big")
|
||||
if i == 'GPSAltitude':
|
||||
gpsinfo['GPSAltitude'] = round(exifdata[k][h][0] / exifdata[k][h][1], 3)
|
||||
if i == 'GPSLatitudeRef':
|
||||
gpsinfo['GPSLatitudeRef'] = exifdata[k][h]
|
||||
if i == 'GPSLatitude':
|
||||
gpsinfo['GPSLatitude'] = calc_coordinate(exifdata[k][h])
|
||||
if i == 'GPSLongitudeRef':
|
||||
gpsinfo['GPSLongitudeRef'] = exifdata[k][h]
|
||||
if i == 'GPSLongitude':
|
||||
gpsinfo['GPSLongitude'] = calc_coordinate(exifdata[k][h])
|
||||
update_gpsinfo(gpsinfo, exif_data)
|
||||
|
||||
|
||||
def update_gpsinfo(gpsinfo, exif_data):
|
||||
if 'GPSAltitudeRef' in gpsinfo and 'GPSLatitude' in gpsinfo:
|
||||
exif_data['GPSAltitude'] = gpsinfo['GPSAltitude']
|
||||
exif_data['GPSAboveSeaLevel'] = False if gpsinfo['GPSAltitudeRef'] != 0 else True
|
||||
if 'GPSLatitudeRef' in gpsinfo and 'GPSLatitude' in gpsinfo:
|
||||
exif_data['GPSLatitude'] = gpsinfo['GPSLatitude'] if gpsinfo['GPSLatitudeRef'] != 'S' else 0 - gpsinfo['GPSLatitude']
|
||||
if 'GPSLongitudeRef' in gpsinfo and 'GPSLongitude' in gpsinfo:
|
||||
exif_data['GPSLongitude'] = gpsinfo['GPSLongitude'] if gpsinfo['GPSLongitudeRef'] != 'W' else 0 - gpsinfo['GPSLongitude']
|
||||
|
||||
|
||||
def calc_coordinate(x):
|
||||
degrees = x[0][0] / x[0][1]
|
||||
minutes = x[1][0] / x[1][1]
|
||||
seconds = x[2][0] / x[2][1]
|
||||
return round(degrees + minutes / 60 + seconds / 3600, 5)
|
||||
|
||||
|
||||
def get_dimensions_and_format(photo, exif_data):
|
||||
img_raw = Image.open('raw_' + photo)
|
||||
img_1280 = Image.open('1280_' + photo)
|
||||
img_480 = Image.open('480_' + photo)
|
||||
exif_data['AspectRatio'] = round(img_raw.width / img_raw.height, 5)
|
||||
exif_data['photo_format'] = img_raw.format
|
||||
exif_data['photo_width'] = img_raw.width
|
||||
exif_data['photo_height'] = img_raw.height
|
||||
exif_data['photo_1280_width'] = img_1280.width
|
||||
exif_data['photo_1280_height'] = img_1280.height
|
||||
exif_data['photo_480_width'] = img_480.width
|
||||
exif_data['photo_480_height'] = img_480.height
|
||||
get_exif(img_raw, exif_data)
|
||||
|
||||
|
||||
def get_file_sizes(photo, exif_data):
|
||||
exif_data['photo_raw_size'] = os.path.getsize('raw_' + photo)
|
||||
exif_data['photo_1280_size'] = os.path.getsize('1280_' + photo)
|
||||
exif_data['photo_480_size'] = os.path.getsize('480_' + photo)
|
||||
get_dimensions_and_format(photo, exif_data)
|
163
app/photo_routes/scripts/process_uploaded_photo.py
Normal file
163
app/photo_routes/scripts/process_uploaded_photo.py
Normal file
@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import psycopg2
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
from .crop_photo import crop_photo
|
||||
from .get_exif_data import get_exif_data
|
||||
|
||||
|
||||
def process_uploaded_photo(filename, current_user, app_config):
|
||||
crop_photo(filename, app_config['PHOTO_SAVE_PATH'])
|
||||
exif_data = get_exif_data(filename)
|
||||
conn = psycopg2.connect(
|
||||
dbname=app_config['DATABASE_NAME'],
|
||||
user=app_config['DATABASE_USER'],
|
||||
host=app_config['DATABASE_HOST'],
|
||||
password=app_config['DATABASE_PASSWORD']
|
||||
)
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT setval('photo_id_seq', (SELECT MAX(id) FROM photo))")
|
||||
conn.commit()
|
||||
cur.execute("SELECT count(id) FROM photo WHERE photo_name=%s", (filename, ))
|
||||
if cur.fetchone()[0] == 0:
|
||||
sql_statement = "INSERT INTO photo("
|
||||
|
||||
sql_statement += "photo_name,"
|
||||
sql_statement += "contributor_id,"
|
||||
sql_statement += "timestamp,"
|
||||
|
||||
sql_statement += "photo_raw_size,"
|
||||
sql_statement += "photo_1280_size,"
|
||||
sql_statement += "photo_480_size,"
|
||||
|
||||
sql_statement += "photo_format,"
|
||||
sql_statement += "photo_width,"
|
||||
sql_statement += "photo_height,"
|
||||
|
||||
sql_statement += "photo_1280_width,"
|
||||
sql_statement += "photo_1280_height,"
|
||||
sql_statement += "photo_480_width,"
|
||||
|
||||
sql_statement += "photo_480_height,"
|
||||
sql_statement += "\"Make\","
|
||||
sql_statement += "\"Model\","
|
||||
|
||||
sql_statement += "\"Software\","
|
||||
sql_statement += "\"DateTime\","
|
||||
sql_statement += "\"DateTimeOriginal\","
|
||||
|
||||
sql_statement += "\"DateTimeDigitized\","
|
||||
sql_statement += "fnumber,"
|
||||
sql_statement += "\"DigitalZoomRatio\","
|
||||
|
||||
sql_statement += "\"AspectRatio\","
|
||||
sql_statement += "\"TimeZoneOffset\","
|
||||
sql_statement += "\"GPSAltitude\","
|
||||
|
||||
sql_statement += "\"GPSAboveSeaLevel\","
|
||||
sql_statement += "\"GPSLatitude\","
|
||||
sql_statement += "\"GPSLongitude\","
|
||||
|
||||
sql_statement += "timestamp_int) "
|
||||
|
||||
sql_statement += "VALUES(%s,%s,%s,%s,%s,%s,"
|
||||
sql_statement += "%s,%s,%s,%s,%s,%s,"
|
||||
sql_statement += "%s,%s,%s,%s,%s,%s,"
|
||||
sql_statement += "%s,%s,%s,%s,%s,%s,"
|
||||
sql_statement += "%s,%s,%s,%s) RETURNING id"
|
||||
cur.execute(sql_statement, (
|
||||
filename,
|
||||
current_user.id,
|
||||
str(datetime.utcnow()),
|
||||
exif_data['photo_raw_size'],
|
||||
exif_data['photo_1280_size'],
|
||||
exif_data['photo_480_size'],
|
||||
exif_data['photo_format'],
|
||||
exif_data['photo_width'],
|
||||
exif_data['photo_height'],
|
||||
exif_data['photo_1280_width'],
|
||||
exif_data['photo_1280_height'],
|
||||
exif_data['photo_480_width'],
|
||||
exif_data['photo_480_height'],
|
||||
exif_data['Make'] if 'Make' in exif_data else None,
|
||||
exif_data['Model'] if 'Model' in exif_data else None,
|
||||
exif_data['Software'] if 'Software' in exif_data else None,
|
||||
exif_data['DateTime'] if 'DateTime' in exif_data else None,
|
||||
exif_data['DateTimeOriginal'] if 'DateTimeOriginal' in exif_data else None,
|
||||
exif_data['DateTimeDigitized'] if 'DateTimeDigitized' in exif_data else None,
|
||||
exif_data['fnumber'] if 'fnumber' in exif_data else None,
|
||||
exif_data['DigitalZoomRatio'] if 'DigitalZoomRatio' in exif_data else None,
|
||||
exif_data['AspectRatio'],
|
||||
exif_data['TimeZoneOffset'] if 'TimeZoneOffset' in exif_data else None,
|
||||
exif_data['GPSAltitude'] if 'GPSAltitude' in exif_data else None,
|
||||
exif_data['GPSAboveSeaLevel'] if 'GPSAboveSeaLevel' in exif_data else None,
|
||||
exif_data['GPSLatitude'] if 'GPSLatitude' in exif_data else None,
|
||||
exif_data['GPSLongitude'] if 'GPSLongitude' in exif_data else None,
|
||||
int(time() * 1000)
|
||||
))
|
||||
photo_id = cur.fetchone()[0]
|
||||
else:
|
||||
cur.execute("SELECT id FROM photo WHERE photo_name=%s", (filename, ))
|
||||
photo_id = cur.fetchone()[0]
|
||||
sql_statement = "UPDATE photo SET "
|
||||
sql_statement += "contributor_id=%s, "
|
||||
sql_statement += "timestamp=%s, "
|
||||
sql_statement += "photo_raw_size=%s, "
|
||||
sql_statement += "photo_1280_size=%s, "
|
||||
sql_statement += "photo_480_size=%s, "
|
||||
sql_statement += "photo_format=%s, "
|
||||
sql_statement += "photo_width=%s, "
|
||||
sql_statement += "photo_height=%s, "
|
||||
sql_statement += "photo_1280_width=%s, "
|
||||
sql_statement += "photo_1280_height=%s, "
|
||||
sql_statement += "photo_480_width=%s, "
|
||||
sql_statement += "photo_480_height=%s, "
|
||||
sql_statement += "\"Make\"=%s, "
|
||||
sql_statement += "\"Model\"=%s, "
|
||||
sql_statement += "\"Software\"=%s, "
|
||||
sql_statement += "\"DateTime\"=%s, "
|
||||
sql_statement += "\"DateTimeOriginal\"=%s, "
|
||||
sql_statement += "\"DateTimeDigitized\"=%s, "
|
||||
sql_statement += "fnumber=%s, "
|
||||
sql_statement += "\"DigitalZoomRatio\"=%s, "
|
||||
sql_statement += "\"AspectRatio\"=%s, "
|
||||
sql_statement += "\"TimeZoneOffset\"=%s, "
|
||||
sql_statement += "\"GPSAltitude\"=%s, "
|
||||
sql_statement += "\"GPSAboveSeaLevel\"=%s, "
|
||||
sql_statement += "\"GPSLatitude\"=%s, "
|
||||
sql_statement += "\"GPSLongitude\"=%s, "
|
||||
sql_statement += "timestamp_int=%s WHERE photo_name=%s"
|
||||
cur.execute(sql_statement, (
|
||||
current_user.id,
|
||||
str(datetime.utcnow()),
|
||||
exif_data['photo_raw_size'],
|
||||
exif_data['photo_1280_size'],
|
||||
exif_data['photo_480_size'],
|
||||
exif_data['photo_format'],
|
||||
exif_data['photo_width'],
|
||||
exif_data['photo_height'],
|
||||
exif_data['photo_1280_width'],
|
||||
exif_data['photo_1280_height'],
|
||||
exif_data['photo_480_width'],
|
||||
exif_data['photo_480_height'],
|
||||
exif_data['Make'] if 'Make' in exif_data else None,
|
||||
exif_data['Model'] if 'Model' in exif_data else None,
|
||||
exif_data['Software'] if 'Software' in exif_data else None,
|
||||
exif_data['DateTime'] if 'DateTime' in exif_data else None,
|
||||
exif_data['DateTimeOriginal'] if 'DateTimeOriginal' in exif_data else None,
|
||||
exif_data['DateTimeDigitized'] if 'DateTimeDigitized' in exif_data else None,
|
||||
exif_data['fnumber'] if 'fnumber' in exif_data else None,
|
||||
exif_data['DigitalZoomRatio'] if 'DigitalZoomRatio' in exif_data else None,
|
||||
exif_data['AspectRatio'],
|
||||
exif_data['TimeZoneOffset'] if 'TimeZoneOffset' in exif_data else None,
|
||||
exif_data['GPSAltitude'] if 'GPSAltitude' in exif_data else None,
|
||||
exif_data['GPSAboveSeaLevel'] if 'GPSAboveSeaLevel' in exif_data else None,
|
||||
exif_data['GPSLatitude'] if 'GPSLatitude' in exif_data else None,
|
||||
exif_data['GPSLongitude'] if 'GPSLongitude' in exif_data else None,
|
||||
int(time() * 1000),
|
||||
filename
|
||||
))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return(photo_id)
|
24
app/photo_routes/templates/delete_photo.html
Normal file
24
app/photo_routes/templates/delete_photo.html
Normal file
@ -0,0 +1,24 @@
|
||||
<style>
|
||||
.formContainer {
|
||||
align-items: center;
|
||||
margin-top: 100px;
|
||||
}
|
||||
|
||||
#submitContainer {
|
||||
margin-top: 100px;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class='formContainer'>
|
||||
|
||||
<form action={{ url_for('d_d.delete', photo_id=photo.id) }} method="post" novalidate>
|
||||
<h2>Delete Photo?</h2>
|
||||
<img style="width: 100%;" src={{ photo_url + '480_' + photo['photo_name'] }} alt={{ '480_' + photo['photo_name'] }}>
|
||||
{{ form.hidden_tag() }}
|
||||
<p id="submitContainer">{{ form.submit() }}</p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
233
app/photo_routes/templates/photo.html
Normal file
233
app/photo_routes/templates/photo.html
Normal file
@ -0,0 +1,233 @@
|
||||
<style>
|
||||
img {
|
||||
width: 400px;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% extends "base.html" %}
|
||||
|
||||
|
||||
{% block morenavs %}
|
||||
<button id="previousPhoto" class="navBracket" onclick="location.href='{{ url_for('p_route.photo', photo_id=photo.previous_photo_id) }}';">‹</button>
|
||||
<button class="navBracket delButton" onclick="location.href='{{ url_for('d_d.delete', photo_id=photo.id) }}';">DEL</button>
|
||||
<button id="nextPhoto" class="navBracket" onclick="location.href='{{ url_for('p_route.photo', photo_id=photo.next_photo_id) }}';">›</button>
|
||||
<style>
|
||||
#main {
|
||||
max-width: unset;
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.delButton {
|
||||
padding-top: 3px;
|
||||
padding-bottom: 0px;
|
||||
font-size: 2rem;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="photoContainer" id="gestureZone">
|
||||
<img style="width: 600;" src={{ photo_url + 'raw_' + photo['photo_name'] }} alt={{ 'raw_' + photo['photo_name'] }}>
|
||||
<div class="photoRow">
|
||||
<div class="dataContainer">
|
||||
<div class="headingRow">
|
||||
<h2 class="photoPageH2">Original as Uploaded</h2>
|
||||
<a href="{{ url_for('d_d.download', file='raw_' + photo.photo_name)}}" download="{{ 'raw_' + photo.photo_name }}" target="_blank">
|
||||
<button class="downloadButton">Download</button>
|
||||
</a>
|
||||
</div>
|
||||
<p>
|
||||
<a class="blue" href={{ photo_url + 'raw_' + photo['photo_name'] }}>{{ photo_url + 'raw_' + photo.photo_name }}</a>
|
||||
</p>
|
||||
{% if photo.Make != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Make:</div>
|
||||
<div class="dataRowRight">{{ photo.Make }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.Model != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Model:</div>
|
||||
<div class="dataRowRight">{{ photo.Model }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.Software != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Software:</div>
|
||||
<div class="dataRowRight">{{ photo.Software }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Upload Date:</div>
|
||||
<div class="dataRowRight">{{ photo.UploadDate }}</div>
|
||||
</div>
|
||||
{% if photo.DateTime != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">DateTime:</div>
|
||||
<div class="dataRowRight">{{ photo.DateTime }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.DateTimeOriginal != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">DateTimeOriginal:</div>
|
||||
<div class="dataRowRight">{{ photo.DateTimeOriginal }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.DateTimeDigitized != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">DateTimeDigitized:</div>
|
||||
<div class="dataRowRight">{{ photo.DateTimeDigitized }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.TimeZoneOffset != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">TimeZoneOffset:</div>
|
||||
<div class="dataRowRight">{{ photo.TimeZoneOffset }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">SizeOnDisc:</div>
|
||||
<div class="dataRowRight">{{ photo.SizeOnDisc }}</div>
|
||||
</div>
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Width / Height:</div>
|
||||
<div class="dataRowRight">{{ photo.photo_width }} / {{ photo.photo_height }}</div>
|
||||
</div>
|
||||
{% if photo.AspectRatio != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">AspectRatio:</div>
|
||||
<div class="dataRowRight">{{ photo.AspectRatio }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.DigitalZoomRatio != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">DigitalZoomRatio:</div>
|
||||
<div class="dataRowRight">{{ photo.DigitalZoomRatio }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.fnumber != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">fnumber:</div>
|
||||
<div class="dataRowRight">{{ photo.fnumber }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.GPSAltitude != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Altitude Meters:</div>
|
||||
<div class="dataRowRight">{{ photo.GPSAltitude }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.GPSAltitudeFeet != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Altitude Feet:</div>
|
||||
<div class="dataRowRight">{{ photo.GPSAltitudeFeet }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.GPSAboveSeaLevel != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Above Sea Level:</div>
|
||||
<div class="dataRowRight">{{ photo.GPSAboveSeaLevel }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if photo.LatLong != None %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">GPS Coordinates:</div>
|
||||
<div class="dataRowRight">
|
||||
<a class="blue" href={{ photo.MapUrl }} rel="noopener noreferrer" target="_blank">
|
||||
{{ photo.LatLong }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">PhotoFormat:</div>
|
||||
<div class="dataRowRight">{{ photo.photo_format }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="photo">
|
||||
<img src={{ photo_url + 'raw_' + photo['photo_name'] }} alt={{ 'raw_' + photo['photo_name'] }}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="photoRow">
|
||||
<div class="dataContainer">
|
||||
<div class="headingRow">
|
||||
<h2 class="photoPageH2">1280 Max-Conversion</h2>
|
||||
<a href="{{ url_for('d_d.download', file='1280_' + photo.photo_name)}}" download="{{ '1280_' + photo.photo_name }}" target="_blank">
|
||||
<button class="downloadButton">Download</button>
|
||||
</a>
|
||||
</div>
|
||||
<p>
|
||||
<a class="blue" href={{ photo_url + '1280_' + photo['photo_name'] }}>{{ photo_url + '1280_' + photo.photo_name }}</a>
|
||||
</p>
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">SizeOnDisc:</div>
|
||||
<div class="dataRowRight">{{ photo.SizeOnDisc1280 }}</div>
|
||||
</div>
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Width / Height:</div>
|
||||
<div class="dataRowRight">{{ photo.photo_1280_width }} / {{ photo.photo_1280_height }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="photo">
|
||||
<img src={{ photo_url + '1280_' + photo['photo_name'] }} alt={{ '1280_' + photo['photo_name'] }}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="photoRow">
|
||||
<div class="dataContainer">
|
||||
<div class="headingRow">
|
||||
<h2 class="photoPageH2">480 Max-Conversion</h2>
|
||||
<a href="{{ url_for('d_d.download', file='480_' + photo.photo_name)}}" download="{{ '480_' + photo.photo_name }}" target="_blank">
|
||||
<button class="downloadButton">Download</button>
|
||||
</a>
|
||||
</div>
|
||||
<p>
|
||||
<a class="blue" href={{ photo_url + '480_' + photo['photo_name'] }}>{{ photo_url + '480_' + photo.photo_name }}</a>
|
||||
</p>
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">SizeOnDisc:</div>
|
||||
<div class="dataRowRight">{{ photo.SizeOnDisc480 }}</div>
|
||||
</div>
|
||||
<div class="dataRow">
|
||||
<div class="dataRowLeft">Width / Height:</div>
|
||||
<div class="dataRowRight">{{ photo.photo_480_width }} / {{ photo.photo_480_height }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="photo">
|
||||
<img src={{ photo_url + '480_' + photo['photo_name'] }} alt={{ '480_' + photo['photo_name'] }}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let touchstartX = 0;
|
||||
let touchendX = 0;
|
||||
|
||||
const gestureZone = document.getElementById('gestureZone');
|
||||
|
||||
gestureZone.addEventListener('touchstart', function(event) {
|
||||
touchstartX = event.changedTouches[0].screenX;
|
||||
}, false);
|
||||
|
||||
gestureZone.addEventListener('touchend', function(event) {
|
||||
touchendX = event.changedTouches[0].screenX;
|
||||
handleGesture();
|
||||
}, false);
|
||||
|
||||
function handleGesture() {
|
||||
if (touchendX <= touchstartX - 100) {
|
||||
console.log('Swiped left');
|
||||
location.href='{{ url_for('p_route.photo', photo_id=photo.next_photo_id) }}';
|
||||
}
|
||||
|
||||
if (touchendX >= touchstartX + 100) {
|
||||
console.log('Swiped right');
|
||||
location.href='{{ url_for('p_route.photo', photo_id=photo.previous_photo_id) }}';
|
||||
}
|
||||
}
|
||||
activateHotKeys();
|
||||
</script>
|
||||
{% endblock %}
|
19
app/photo_routes/templates/upload.html
Normal file
19
app/photo_routes/templates/upload.html
Normal file
@ -0,0 +1,19 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="formContainer">
|
||||
<h1>{{ title }}</h1>
|
||||
<form action="" method="post" enctype="multipart/form-data" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<p>
|
||||
{{ form.image.label }}<br>
|
||||
<span class="inputInfo imageInputInfo">
|
||||
suggest max 3MB
|
||||
</span><br>
|
||||
{{ form.image(style="width: 100%; margin-top: 40px;") }}
|
||||
</p>
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user