diff --git a/.gitignore b/.gitignore index a27e6fa..a52b68f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Remove all development files -uploads/ +gallery/user/uploads/* gallery/static/theme/* .idea diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..bf4d341 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include gallery/schema.sql +graft gallery/static +graft gallery/templates +graft gallery/user +global-exclude *.pyc \ No newline at end of file diff --git a/gallery/__init__.py b/gallery/__init__.py index ea5c7e1..47ae973 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -32,7 +32,7 @@ def create_app(test_config=None): SECRET_KEY=os.environ.get('FLASK_SECRET'), DATABASE=os.path.join(app.instance_path, 'gallery.sqlite'), UPLOAD_FOLDER=os.path.join(app.root_path, 'user', 'uploads'), - ALLOWED_EXTENSIONS=['png', 'jpg', 'jpeg', 'webp'], + ALLOWED_EXTENSIONS=os.environ.get('FLASK_EXTENSIONS'), ) if test_config is None: diff --git a/gallery/gallery.py b/gallery/gallery.py index 1b9a991..2443eeb 100644 --- a/gallery/gallery.py +++ b/gallery/gallery.py @@ -5,6 +5,8 @@ from gallery.auth import login_required from gallery.db import get_db import os import datetime +from PIL import Image +from PIL.ExifTags import TAGS dt = datetime.datetime.now() blueprint = Blueprint('gallery', __name__) @@ -23,16 +25,29 @@ def index(): @blueprint.route('/image/') def image(id): db = get_db() - post = db.execute( + image = db.execute( 'SELECT * FROM posts' ' WHERE id = ?', (id,) ).fetchone() - if post is None: + if image is None: abort(404) - return render_template('image.html', fileName=post['file_name'], id=id) + file = Image.open(os.path.join(current_app.config['UPLOAD_FOLDER'], 'original', image['file_name'])) + + raw_exif = file.getexif() + human_exif = {} + for tag in raw_exif: + name = TAGS.get(tag, tag) + value = raw_exif.get(tag) + + if isinstance(value, bytes): + value = value.decode() + + human_exif[name] = value + + return render_template('image.html', image=image, exif=human_exif) @blueprint.route('/group') diff --git a/gallery/templates/image.html b/gallery/templates/image.html index 93d9742..26ffe27 100644 --- a/gallery/templates/image.html +++ b/gallery/templates/image.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block header %} - leaves + leaves {% endblock %} {% block content %} @@ -9,13 +9,19 @@
-

{{ fileName }}

-

{{ id }}

+

{{ image['file_name'] }}

+

{{ image['id'] }}

+

{{ image['author_id'] }}

+
+
+ {% for tag in exif %} +

{{ tag }}: {{ exif[tag] }}

+ {% endfor %}
{% endblock %} \ No newline at end of file diff --git a/gallery/templates/layout.html b/gallery/templates/layout.html index 4b84abd..82ab5a7 100644 --- a/gallery/templates/layout.html +++ b/gallery/templates/layout.html @@ -59,15 +59,18 @@ {% block content %} {% endblock %} - + + +