Browse Source

Add thumbnailing support

pull/1/head
Dashie der otter 1 year ago
parent
commit
c43c57ba27
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755

+ 3
- 0
app.py View File

@@ -13,6 +13,7 @@ from flask_security.utils import hash_password
from flask_security import signals as FlaskSecuritySignals
from flask_security import confirmable as FSConfirmable
from flask_uploads import configure_uploads, UploadSet, patch_request_class
from flask_thumbnails import Thumbnail

from forms import ExtendedRegisterForm
from models import db, user_datastore, Role
@@ -139,6 +140,8 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T
configure_uploads(app, pictures)
patch_request_class(app, 10 * 1024 * 1024) # 10m limit

thumb = Thumbnail(app) # noqa: F841

if register_blueprints:
from controllers.main import bp_main


+ 5
- 0
config.py.sample View File

@@ -61,3 +61,8 @@ BOOTSTRAP_USE_MINIFIED = True
BOOTSTRAP_SERVE_LOCAL = True
BOOTSTRAP_QUERYSTRING_REVVING = True
BABEL_DEFAULT_TIMEZONE = "UTC"

THUMBNAIL_MEDIA_THUMBNAIL_ROOT = UPLOADED_PICTURES_DEST
THUMBNAIL_MEDIA_ROOT = THUMBNAIL_MEDIA_THUMBNAIL_ROOT
THUMBNAIL_MEDIA_THUMBNAIL_URL = ""
THUMBNAIL_DEFAUL_FORMAT = "JPEG"

+ 10
- 3
controllers/accessories.py View File

@@ -97,9 +97,16 @@ def delete(accessory_id):
db.session.delete(accessory)
db.session.commit()

f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
if os.path.isfile(f):
os.remove(f)
if pic_filename:
f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
print(f"Removing: {f}")
if os.path.isfile(f):
os.remove(f)
thumb_filename, thumb_ext = os.path.splitext(pic_filename)
thumbf = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], thumb_filename + "_200x200_aaa_90.jpg")
print(f"Removing: {thumbf}")
if os.path.isfile(thumbf):
os.remove(thumbf)

flash("Successfully deleted accessory", "success")
return redirect(url_for("bp_users.accessories", name=current_user.name))

+ 10
- 3
controllers/cameras.py View File

@@ -125,9 +125,16 @@ def delete(camera_id):
db.session.delete(camera)
db.session.commit()

f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
if os.path.isfile(f):
os.remove(f)
if pic_filename:
f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
print(f"Removing: {f}")
if os.path.isfile(f):
os.remove(f)
thumb_filename, thumb_ext = os.path.splitext(pic_filename)
thumbf = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], thumb_filename + "_200x200_aaa_90.jpg")
print(f"Removing: {thumbf}")
if os.path.isfile(thumbf):
os.remove(thumbf)

flash("Successfully deleted camera", "success")
return redirect(url_for("bp_users.cameras", name=current_user.name))

+ 10
- 3
controllers/lenses.py View File

@@ -111,9 +111,16 @@ def delete(lense_id):
db.session.delete(lense)
db.session.commit()

f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
if os.path.isfile(f):
os.remove(f)
if pic_filename:
f = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], pic_filename)
print(f"Removing: {f}")
if os.path.isfile(f):
os.remove(f)
thumb_filename, thumb_ext = os.path.splitext(pic_filename)
thumbf = os.path.join(current_app.config["UPLOADED_PICTURES_DEST"], thumb_filename + "_200x200_aaa_90.jpg")
print(f"Removing: {thumbf}")
if os.path.isfile(thumbf):
os.remove(thumbf)

flash("Successfully deleted lense", "success")
return redirect(url_for("bp_users.lenses", name=current_user.name))

+ 2
- 0
requirements.txt View File

@@ -17,3 +17,5 @@ flask_debugtoolbar==0.10.1
Bootstrap-Flask==1.0.9
git+https://github.com/mattupstate/flask-security#egg=Flask-Security
Click==7.0
Pillow==5.3.0
Flask-thumbnails==1.0.6

+ 2
- 0
setup.py View File

@@ -27,6 +27,7 @@ setup(
"Flask-SQLAlchemy",
"Flask-Uploads",
"Flask-WTF",
"Flask-thumbnails",
"bcrypt",
"psycopg2-binary",
"unidecode",
@@ -34,6 +35,7 @@ setup(
"texttable",
"python-slugify",
"python-magic",
"Pillow",
],
setup_requires=["pytest-runner"],
tests_require=["pytest", "pytest-cov"],

+ 3
- 1
templates/users/accessories.jinja2 View File

@@ -32,7 +32,9 @@
</tr>
{% for accessory in accessories %}
<tr>
<td rowspan="2"><img src="/uploads/pictures/{{ accessory.pic_filename }}"></td>
<td rowspan="2" width="210px">
{% if accessory.pic_filename %}<img src="/uploads/pictures/{{ accessory.pic_filename | thumbnail('200x200', crop='aaa', quality=90) }}">{% endif %}
</td>
<td>{% if accessory.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ accessory.manufacturer }}</td>
<td>{% if accessory.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ accessory.model }}</td>
<td>{{ accessory.state_str() }}</td>

+ 7
- 2
templates/users/cameras.jinja2 View File

@@ -22,18 +22,20 @@
<div class="col-lg-12">
<table class="table table-sm table-stripped table-bordered">
<tr>
<th>{{ gettext("Picture") }}</th>
<th>{{ gettext("Manufacturer") }}</th>
<th>{{ gettext("Model") }}</th>
<th>{{ gettext("State") }}</th>
<th>{{ gettext("Description") }}</th>
<th>{{ gettext("Actions") }}</th>
</tr>
{% for camera in cameras %}
<tr>
<td rowspan="2" width="210px">
{% if camera.pic_filename %}<img src="/uploads/pictures/{{ camera.pic_filename | thumbnail('200x200', crop='aaa', quality=90) }}">{% endif %}
</td>
<td>{% if camera.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ camera.manufacturer }}</td>
<td>{% if camera.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ camera.model }}</td>
<td>{{ camera.state_str() }}</td>
<td>{{ camera.description }}</td>
{% if current_user.is_authenticated and user == current_user %}
<td>
<a href="{{ url_for("bp_cameras.edit", camera_id=camera.id) }}"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
@@ -41,6 +43,9 @@
</td>
{% endif %}
</tr>
<tr>
<td colspan="10">Description: {{ camera.description }}</td>
</tr>
{% endfor %}
</table>


+ 7
- 3
templates/users/lenses.jinja2 View File

@@ -22,6 +22,7 @@
<div class="col-lg-12">
<table class="table table-sm table-stripped table-bordered">
<tr>
<th>{{ gettext("Picture") }}</th>
<th>{{ gettext("Manufacturer") }}</th>
<th>{{ gettext("Model") }}</th>
<th>{{ gettext("State") }}</th>
@@ -34,6 +35,9 @@
</tr>
{% for lense in lenses %}
<tr>
<td rowspan="2" width="210px">
{% if lense.pic_filename %}<img src="/uploads/pictures/{{ lense.pic_filename | thumbnail('200x200', crop='aaa', quality=90) }}">{% endif %}
</td>
<td>{% if lense.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ lense.manufacturer }}</td>
<td>{% if lense.private %}<i class="fa fa-lock" aria-hidden="true"></i> {% endif %}{{ lense.model }}</td>
<td>{{ lense.state_str() }}</td>
@@ -49,9 +53,9 @@
</td>
{% endif %}
</tr>
{% if lense.description %}
<tr><td colspan="20">{{ gettext("Description:") }} {{ lense.description }}</td></tr>
{% endif %}
<tr>
<td colspan="10">Description: {{ lense.description }}</td>
</tr>
{% endfor %}
</table>


Loading…
Cancel
Save