2023-01-10 18:12:55 +00:00
|
|
|
from flask import Blueprint, flash, g, redirect, render_template, request, url_for, jsonify, current_app
|
2023-01-10 14:40:43 +00:00
|
|
|
from werkzeug.exceptions import abort
|
|
|
|
from werkzeug.utils import secure_filename
|
2023-01-26 14:43:08 +00:00
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
from gallery.auth import login_required
|
|
|
|
from gallery.db import get_db
|
2023-01-26 14:43:08 +00:00
|
|
|
|
2023-01-31 17:32:22 +00:00
|
|
|
from . import metadata as mt
|
2023-01-11 19:46:31 +00:00
|
|
|
from PIL import Image
|
2023-01-26 14:43:08 +00:00
|
|
|
|
2023-01-10 15:41:39 +00:00
|
|
|
import os
|
2023-01-31 17:32:22 +00:00
|
|
|
from datetime import datetime
|
2023-01-31 23:44:44 +00:00
|
|
|
|
2023-01-31 17:32:22 +00:00
|
|
|
dt = datetime.now()
|
2023-01-10 18:12:55 +00:00
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
blueprint = Blueprint('gallery', __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
2023-01-10 18:12:55 +00:00
|
|
|
db = get_db()
|
2023-01-25 15:13:56 +00:00
|
|
|
images = db.execute('SELECT * FROM posts'
|
|
|
|
' ORDER BY created_at DESC').fetchall()
|
|
|
|
|
2023-01-10 18:12:55 +00:00
|
|
|
return render_template('index.html', images=images)
|
2023-01-10 14:40:43 +00:00
|
|
|
|
2023-01-25 15:13:56 +00:00
|
|
|
|
|
|
|
@blueprint.route('/image/<int:id>')
|
|
|
|
def image(id):
|
|
|
|
# Get image from database
|
|
|
|
db = get_db()
|
2023-01-26 14:43:08 +00:00
|
|
|
image = db.execute('SELECT * FROM posts WHERE id = ?', (id, )).fetchone()
|
2023-01-25 15:13:56 +00:00
|
|
|
|
|
|
|
if image is None:
|
|
|
|
abort(404)
|
|
|
|
|
2023-01-31 23:44:44 +00:00
|
|
|
exif = mt.metadata.yoink(
|
|
|
|
os.path.join(current_app.config['UPLOAD_FOLDER'], image['file_name']))
|
2023-01-31 22:08:37 +00:00
|
|
|
|
|
|
|
return render_template('image.html', image=image, exif=exif)
|
2023-01-25 15:13:56 +00:00
|
|
|
|
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
@blueprint.route('/group')
|
|
|
|
def groups():
|
2023-01-11 10:53:01 +00:00
|
|
|
return render_template('group.html', group_id='gwa gwa')
|
2023-01-10 14:40:43 +00:00
|
|
|
|
2023-01-25 15:13:56 +00:00
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
@blueprint.route('/group/<int:id>')
|
2023-01-25 15:13:56 +00:00
|
|
|
def group(id):
|
2023-01-11 10:53:01 +00:00
|
|
|
return render_template('group.html', group_id=id)
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
|
2023-01-11 19:46:31 +00:00
|
|
|
@blueprint.route('/upload')
|
2023-01-10 14:40:43 +00:00
|
|
|
@login_required
|
|
|
|
def upload():
|
|
|
|
return render_template('upload.html')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/profile')
|
|
|
|
def profile():
|
|
|
|
return render_template('profile.html', user_id='gwa gwa')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/profile/<int:id>')
|
|
|
|
def profile_id(id):
|
|
|
|
return render_template('profile.html', user_id=id)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/settings')
|
|
|
|
@login_required
|
|
|
|
def settings():
|
|
|
|
return render_template('settings.html')
|