diff --git a/apptax/admin/admin_view.py b/apptax/admin/admin_view.py
index 97951aab..a1f92c33 100644
--- a/apptax/admin/admin_view.py
+++ b/apptax/admin/admin_view.py
@@ -563,10 +563,9 @@ def can_delete(self):
column_exclude_list = ("url",)
form_extra_fields = {
"chemin": ImageUploadFieldWithoutDelete(
- label="Image",
+ label="Téléverser un fichier",
base_path=Path(current_app.config["MEDIA_FOLDER"], "taxhub").absolute(),
namegen=taxref_media_file_name,
- thumbnail_size=(150, 150, True),
endpoint="media_taxhub",
)
}
@@ -579,8 +578,8 @@ def _list_thumbnail(view, context, model, name):
html = ""
if model.types.nom_type_media in ("Photo", "Photo_principale"):
html = f"""
-
-
+
+
"""
elif model.types.nom_type_media in ("Audio"):
diff --git a/apptax/admin/templates/admin/details_taxref.html b/apptax/admin/templates/admin/details_taxref.html
index 5051df6a..51440571 100644
--- a/apptax/admin/templates/admin/details_taxref.html
+++ b/apptax/admin/templates/admin/details_taxref.html
@@ -173,7 +173,7 @@
{{theme}}
{% if media.types.nom_type_media in ("Photo", "Photo_principale") %}
-
+
{% elif media.types.nom_type_media in ("Audio")%}
diff --git a/apptax/migrations/versions/52d1b5dd965e_strip_static_media_from_path.py b/apptax/migrations/versions/52d1b5dd965e_strip_static_media_from_path.py
index f97a79a2..86552698 100644
--- a/apptax/migrations/versions/52d1b5dd965e_strip_static_media_from_path.py
+++ b/apptax/migrations/versions/52d1b5dd965e_strip_static_media_from_path.py
@@ -25,7 +25,7 @@ def upgrade():
SET
chemin = regexp_replace(chemin, '^static/medias/', '')
WHERE
- chemin IS NOT NULL AND url IS NULL
+ NULLIF(chemin, '') IS NOT NULL AND NULLIF(url, '') IS NULL
"""
)
diff --git a/apptax/taxonomie/models.py b/apptax/taxonomie/models.py
index 090bf105..ac7e2663 100644
--- a/apptax/taxonomie/models.py
+++ b/apptax/taxonomie/models.py
@@ -320,7 +320,7 @@ class TMedias(db.Model):
def media_url(self):
if self.url:
return self.url
- else:
+ elif self.chemin:
return url_for("media_taxhub", filename=self.chemin, _external=True)
def __repr__(self):
diff --git a/apptax/tests/fixtures.py b/apptax/tests/fixtures.py
index b2abdb28..e35103e7 100644
--- a/apptax/tests/fixtures.py
+++ b/apptax/tests/fixtures.py
@@ -149,6 +149,19 @@ def nom_with_media():
taxon.medias.append(media)
+@pytest.fixture
+def nom_with_media_chemin():
+ with db.session.begin_nested():
+ taxon = Taxref.query.get(60577)
+ media = TMedias(
+ titre="test",
+ chemin="mon_image.jpg",
+ is_public=True,
+ types=BibTypesMedia.query.first(),
+ )
+ taxon.medias.append(media)
+
+
@pytest.fixture(scope="session")
def users(app):
users = {}
diff --git a/apptax/tests/test_models.py b/apptax/tests/test_models.py
index b59ab1e1..4f307b45 100644
--- a/apptax/tests/test_models.py
+++ b/apptax/tests/test_models.py
@@ -44,3 +44,13 @@ def test_taxref_comparison(self):
assert not animalia <= cinnamon
assert not cinnamon <= capra_ibex
assert not capra_ibex <= cinnamon
+
+ def test_tmedias_media_url_url(self, nom_with_media):
+ taxon = db.session.execute(sa.select(Taxref).where(Taxref.cd_nom == 60577)).scalar_one()
+ assert len(taxon.medias) == 1
+ assert taxon.medias[0].media_url == "http://photo.com"
+
+ def test_tmedias_media_url_chemin(self, nom_with_media_chemin):
+ taxon = db.session.execute(sa.select(Taxref).where(Taxref.cd_nom == 60577)).scalar_one()
+ assert len(taxon.medias) == 1
+ assert taxon.medias[0].media_url.endswith("media/taxhub/mon_image.jpg")
|