pywallter/views/gallery.py

57 lines
2.0 KiB
Python
Raw Permalink Normal View History

2022-08-06 18:22:24 +02:00
# -*- coding: utf-8 -*-
2023-11-02 08:03:21 +01:00
from flask import Blueprint, Flask, request, flash, render_template, url_for, session, redirect, abort, make_response, send_file, flash, abort, send_file, send_from_directory
2022-08-06 18:22:24 +02:00
from werkzeug.utils import secure_filename
2023-11-02 08:03:21 +01:00
from markupsafe import escape
2022-08-06 18:22:24 +02:00
from PIL import Image
import time
import sqlite3
import os
mygallery = Blueprint('mygallery', __name__, template_folder='templates')
app = Flask( 'pywallter' )
app.config.from_pyfile('config.py')
#### Variables ####################################################################################
DOSSIER_PERSO= app.config['DOSSIER_APP']
extensionimg = app.config['EXT_IMG']
DATABASE = app.config['DATABASE']
##################################################################################################
@mygallery.route( '/gallery/')
def gallery():
if 'username' in session :
UTILISATEUR='%s' % escape(session['username'])
THUMBNAILS=DOSSIER_PERSO + UTILISATEUR + '/images/thumbnails/'
fichiers = [fich for fich in os.listdir(THUMBNAILS)]
return render_template('gallery.html',
section='Gallery',
THUMBNAILS=THUMBNAILS,
fichiers=fichiers)
else :
return redirect(url_for('loginlogout.login'), code=401)
@mygallery.route('/myfiles/images/<filename>')
def myimg(filename):
if 'username' in session :
UTILISATEUR='%s' % escape(session['username'])
return send_from_directory(
os.path.join(DOSSIER_PERSO, UTILISATEUR, 'images'), filename )
else :
2022-08-06 23:49:16 +02:00
return redirect(BASE_URL, code=401)
2022-08-06 18:22:24 +02:00
@mygallery.route('/myfiles/images/thumbnails/<filename>')
def mythumbnails(filename):
if 'username' in session :
UTILISATEUR='%s' % escape(session['username'])
return send_from_directory(
os.path.join(DOSSIER_PERSO, UTILISATEUR, 'images/thumbnails'), filename )
else :
2022-08-06 23:49:16 +02:00
return redirect(BASE_URL, code=401)