j'ai perdu mon projet
This commit is contained in:
parent
0d008656e7
commit
cb849afd4f
Binary file not shown.
33
src/myalbum/app.py
Executable file → Normal file
33
src/myalbum/app.py
Executable file → Normal file
@ -1,24 +1,41 @@
|
||||
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__)
|
||||
|
||||
def create_pagination(images: list[Photo]) -> list[list[Photo]]:
|
||||
return [images[i : i + NUM_PHOTO_PER_PAGE] for i in range(0, len(images), NUM_PHOTO_PER_PAGE)]
|
||||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
photos = []
|
||||
paths = listdir(PHOTO_DIR)
|
||||
for path in paths:
|
||||
|
||||
for path in sorted(paths, reverse=True):
|
||||
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)
|
||||
brand = exif_data.get(271, "Inconnu")
|
||||
model = exif_data.get(272, "Inconnu")
|
||||
|
||||
photos.append(Photo(path, f"{wid}x{hgt}", brand, model))
|
||||
|
||||
pages = create_pagination(photos)
|
||||
requested_page = request.args.get('page', '0')
|
||||
|
||||
if requested_page.isnumeric():
|
||||
idx = int(requested_page)
|
||||
if 0 <= idx < len(pages):
|
||||
return render_template("index.html", pages=pages, num_page=idx, str=str)
|
||||
|
||||
return render_template("index.html", pages=pages, num_page=1, str=str)
|
||||
61
src/myalbum/static/styles/style.css
Normal file
61
src/myalbum/static/styles/style.css
Normal file
@ -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%;
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{% for photo in photos %}
|
||||
<img src="{{ url_for('static', filename=photo.name) }}">
|
||||
<p>{{ str(photo) }}</p>
|
||||
{% endfor %}
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ url_for('static', filename='styles/style.css') }}"
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Guams's album</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="banner">
|
||||
<div class="banner-header">
|
||||
|
||||
</div>
|
||||
<div class="banner-body">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<main>
|
||||
<p>Note : Toutes les personnes présentes sur les photos consentent à apparaître sur cette page</p>
|
||||
<div class="pictures">
|
||||
{% for photo in pages[num_page - 1] %}
|
||||
<a class="img-link" href="{{ url_for('static', filename='photos/' + photo.name) }}" target="_blank">
|
||||
<img
|
||||
src="{{ url_for('static', filename='photos/' + photo.name) }}"
|
||||
alt="{{ photo.name }}"
|
||||
title="{{ photo.name }}"
|
||||
class="picture"
|
||||
/>
|
||||
<p>{{ photo | string }}</p>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="main-footer">
|
||||
<div class="pagination">
|
||||
{% if num_page > 0 %}
|
||||
<a href="/?page={{ num_page - 1 }}"><</a>
|
||||
{% endif %} {% for i in range(pages|length) %}
|
||||
<a
|
||||
href="/?page={{ i }}"
|
||||
class="{{ 'active' if i == num_page else '' }}"
|
||||
>
|
||||
{{ i + 1 }}
|
||||
</a>
|
||||
{% endfor %} {% if num_page < (pages|length - 1) %}
|
||||
<a href="/?page={{ num_page + 1 }}">></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user