From 260cef29d41c14060f2ba56020c91af6ddcd55b7 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sun, 14 Aug 2022 21:16:21 +0200 Subject: [PATCH] Add thumbnails --- .gitignore | 1 + partitioncloud/__init__.py | 3 ++- partitioncloud/partition.py | 27 ++++++++++++++++++++++ partitioncloud/templates/albums/album.html | 24 ++++++++++--------- 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 partitioncloud/partition.py diff --git a/.gitignore b/.gitignore index 3b597ff..72e6b16 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ # data instance/partitioncloud.sqlite partitioncloud/partitions +partitioncloud/thumbnails diff --git a/partitioncloud/__init__.py b/partitioncloud/__init__.py index 0d9b0ec..736be2b 100644 --- a/partitioncloud/__init__.py +++ b/partitioncloud/__init__.py @@ -5,7 +5,7 @@ Main file import os from flask import Flask, render_template, request, send_file, g, redirect -from . import auth, albums +from . import auth, albums, partition app = Flask(__name__) @@ -18,6 +18,7 @@ app.config.from_mapping( app.register_blueprint(auth.bp) app.register_blueprint(albums.bp) +app.register_blueprint(partition.bp) @app.route("/") diff --git a/partitioncloud/partition.py b/partitioncloud/partition.py new file mode 100644 index 0000000..e6843fb --- /dev/null +++ b/partitioncloud/partition.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +""" +Partitions module +""" +import os + +from flask import (Blueprint, render_template, + send_file) + + +bp = Blueprint("partition", __name__, url_prefix="/partition") + +@bp.route("//preview") +def preview(uuid): + """ + Renvoie la prévisualisation d'un fichier pdf + """ + if not os.path.exists(f"partitioncloud/thumbnails/{uuid}.jpg"): + os.system( + f'/usr/bin/convert -thumbnail\ + "178^>" -background white -alpha \ + remove -crop 178x178+0+0 \ + partitioncloud/partitions/{uuid}.pdf[0] \ + partitioncloud/thumbnails/{uuid}.jpg' + ) + + return send_file(f"thumbnails/{uuid}.jpg") \ No newline at end of file diff --git a/partitioncloud/templates/albums/album.html b/partitioncloud/templates/albums/album.html index 48d7126..622b9fa 100644 --- a/partitioncloud/templates/albums/album.html +++ b/partitioncloud/templates/albums/album.html @@ -6,19 +6,21 @@ {% block content %} {% if not_participant %} - - - + + + {% endif %} {% if partitions|length != 0 %} - {% for partition in partitions %} - -
- {{ partition["name"] }} -
-
- {% endfor %} +{% for partition in partitions %} + +
+ +
{{ partition["name"] }}
+
{{ partition["author"] }}
+
+
+{% endfor %} {% else %} -
Aucune partition disponible
+
Aucune partition disponible
{% endif %} {% endblock %} \ No newline at end of file