From 89a46ed5aad9cbfc159cec5687e30e21261c0a57 Mon Sep 17 00:00:00 2001 From: Guamss Date: Mon, 23 Feb 2026 17:40:44 +0100 Subject: [PATCH] pagination fonctionnelle --- src/myalbum/__pycache__/app.cpython-314.pyc | Bin 1393 -> 2170 bytes src/myalbum/app.py | 45 ++++++++++--- src/myalbum/static/styles/style.css | 61 ++++++++++++++++++ src/myalbum/templates/index.html | 66 ++++++++++++++++---- 4 files changed, 149 insertions(+), 23 deletions(-) mode change 100755 => 100644 src/myalbum/app.py create mode 100644 src/myalbum/static/styles/style.css diff --git a/src/myalbum/__pycache__/app.cpython-314.pyc b/src/myalbum/__pycache__/app.cpython-314.pyc index 8b3bcac913e577005635e5b437b6cd378053234d..97e8225d546ca38ba0290ca350c405d42c2d50ab 100644 GIT binary patch literal 2170 zcmZ`)%Wo4$7@zfecfIkGB#v<~aZ-{Z7qCf)NT?9BYC`R%gp~yjREsSWZ=4N&EVC05 ztR7r(sMA)Wp;QSHDv`<|RWJMjJylh2l@e^4bQ+{oRH}M|hCiUQYfnrOox^^=`JOZ1 zWA>2C*#gMA{o^-k2M54YV?!6)06Sk0PzFg5XJP;u)DmN&7G#OCh>cp2HE8hI7#HOc zZ(?fA`*ij&ZCy3i0qdwJ>arqkg0n|&dW||KMmQWae->YZ9XvA5FmG) zIRHZ9-^PAC#A5DDF0Eh1Zm1M83QQp-ujSH6!2(pS%_=$yF_??x(^-W8A*bpnqe6ox zO&3wI?803jk^H^7;v{E-4P6Z+ zfF!)C0e0_pup!Dg0SExuh;6O}pqbFXSxb`9Kp1F@Y^QRW=+~F*qKI0=Epc{;#<$3O zs65FKuawUw*d%k2vr8qDRgV00~PHH2H?-1n&W7egZ%f5`yHTQJR!?h~#hbD2lhxSTx63QqKSw zdkX-$lWIu;ikh?s$mHDhC3REOq|$*Vrl?tkgg|pl<7>8rP3ohXO-fI%iA4TplTXnc zsTKS_A-=Z9tZ|OU(H#Gy!@s2COfXW2dTvtr5XBQE2Z##^y8{fc6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ask import Flask, render_template +from flask import Flask, render_template, request from PIL import Image from os import listdir from myalbum.models import Photo -PHOTO_DIR = "./static" +PHOTO_DIR = "./static/photos" +NUM_PHOTO_PER_PAGE = 9 app = Flask(__name__) + @app.route("/") -def hello_world(): +def index(): + requested_page = request.args.get('page', '1') + + if requested_page.isnumeric(): + requested_page = int(requested_page) + else: + requested_page = 1 + photos = [] - paths = listdir(PHOTO_DIR) - for path in paths: + paths = sorted(listdir(PHOTO_DIR), reverse=True) + page = max(1, requested_page) + + first_index = (page - 1) * NUM_PHOTO_PER_PAGE + last_photo_index = page * NUM_PHOTO_PER_PAGE + + photos_to_show = paths[first_index:last_photo_index] + if len(photos_to_show) == 0 and len(paths) >= NUM_PHOTO_PER_PAGE: + photos_to_show = paths[0:NUM_PHOTO_PER_PAGE] + + for path in photos_to_show: + if not path.lower().endswith(('.png', '.jpg', '.jpeg')): + continue + + img = Image.open(os.path.join(PHOTO_DIR, path)) - print(img.filename) exif_data = img.getexif() wid, hgt = img.size - brand = exif_data[271] - model = exif_data[272] - photos.append(Photo(path, str(wid) + "x" + str(hgt),brand, model)) - return render_template("index.html", photos=photos, str=str) \ No newline at end of file + brand = exif_data.get(271, "Inconnu") + model = exif_data.get(272, "Inconnu") + + + photos.append(Photo(path, f"{wid}x{hgt}", brand, model)) + + + return render_template("index.html", photos=photos, num_page=requested_page, str=str) \ No newline at end of file diff --git a/src/myalbum/static/styles/style.css b/src/myalbum/static/styles/style.css new file mode 100644 index 0000000..1731284 --- /dev/null +++ b/src/myalbum/static/styles/style.css @@ -0,0 +1,61 @@ +:root { + /* color-scheme: light dark; */ +} + +* { + font-family: "Roboto", sans-serif; +} + +main { + display: flex; + flex-direction: column; + align-items: center; + border: 1px solid black; + padding: 2rem; +} + +.pictures { + display: flex; + flex-wrap: wrap; + gap: 2rem; + justify-content: center; + width: 100%; +} + +.img-link { + display: flex; + flex-direction: column; + align-items: center; + text-decoration: none; + color: black; + width: calc((100% / 3) - 2rem); + transition: transform .2s; +} + +.img-link:hover { + transform: scale(1.05); +} + +.picture { + width: 100%; + height: auto; + object-fit: cover; +} + +.pagination { + display: flex; + justify-content: center; + gap: 1rem; +} + +@media screen and (max-width: 80rem) { + .img-link { + width: calc(50% - 2rem); + } +} + +@media screen and (max-width: 40rem) { + .img-link { + width: 100%; + } +} \ No newline at end of file diff --git a/src/myalbum/templates/index.html b/src/myalbum/templates/index.html index 1a45bea..fab977f 100644 --- a/src/myalbum/templates/index.html +++ b/src/myalbum/templates/index.html @@ -1,14 +1,54 @@ - + - - - - Document - - - {% for photo in photos %} - -

{{ str(photo) }}

- {% endfor %} - - \ No newline at end of file + + + + + Guams's album + + + +
+

Note : Toutes les personnes présentes sur les photos consentent à apparaître sur cette page

+
+ {% for photo in photos %} + + {{ photo.name }} +

{{ photo | string }}

+
+ {% endfor %} +
+ +
+ +