diff --git a/src/myalbum/__pycache__/app.cpython-314.pyc b/src/myalbum/__pycache__/app.cpython-314.pyc index 8b3bcac..97e8225 100644 Binary files a/src/myalbum/__pycache__/app.cpython-314.pyc and b/src/myalbum/__pycache__/app.cpython-314.pyc differ diff --git a/src/myalbum/app.py b/src/myalbum/app.py old mode 100755 new mode 100644 index f0061b3..1adece4 --- a/src/myalbum/app.py +++ b/src/myalbum/app.py @@ -1,24 +1,49 @@ import os -from flask 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 %} +
+ +
+ +