Skip to content

Commit

Permalink
Style media overview
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Aug 18, 2023
1 parent 7e296e0 commit 7deefdd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
35 changes: 20 additions & 15 deletions apptax/admin/admin_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def can_delete(self):

form_ajax_refs = {"taxon": TaxrefAjaxModelLoader("taxon")}

column_exclude_list = ("url",)
form_extra_fields = {
"chemin": form.ImageUploadField(
label="Image",
Expand All @@ -442,22 +443,26 @@ def can_delete(self):
)
}

def _list_thumbnail(view, context, model, name):
path = None
if model.chemin:
path = url_for(
"media",
filename=form.thumbgen_filename(model.chemin),
_external=True,
)
elif model.url:
path = model.url
def _list_titre(view, context, model, name):
return markupsafe.Markup(model.titre)

if not path:
return
return markupsafe.Markup(f"<img src='{path}'>")

column_formatters = {"chemin": _list_thumbnail}
def _list_thumbnail(view, context, model, name):
# format html
html = ""
if model.types.nom_type_media in ("Photo", "Photo_principale"):
html = f"""
<a target='_blank' href='{ url_for("t_media.getThumbnail_tmedias", id_media=model.id_media)}'>
<img width="100" src='{ url_for("t_media.getThumbnail_tmedias", id_media=model.id_media)}' alt="Taxon image">
</a>
"""
elif model.types.nom_type_media in ("Audio"):
html = f"<audio controls src='{model.media_url}'>"
else:
html = f"<a target='_blank' href='{model.media_url}'>Lien média</a>"

return markupsafe.Markup(html)

column_formatters = {"chemin": _list_thumbnail, "titre": _list_titre}

def on_model_change(self, form, model, is_created):
"""
Expand Down
30 changes: 18 additions & 12 deletions apptax/admin/templates/admin/details_taxref.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h5 class="col-11 card-title"> {{model.nom_complet}} {% if model.nom_vern %} - {
<h5 class="card-title col-1">
<a href="https://inpn.mnhn.fr/espece/cd_nom/{{model.cd_nom }}">
<img width="100" src="{{url_for("static", filename="logo_inpn.png")}}" alt="">
</a>
</a>
</h5>
</div>
<div class="card-subtitle mb-2 text-muted" id="taxonomie-hierarchy">
Expand Down Expand Up @@ -44,16 +44,16 @@ <h5 class="card-title col-1">
<div class="tab-pane fade mt-3" id="nav-status" role="tabpanel" aria-labelledby="nav-status-tab">
<a target="_blank" href="https://inpn.mnhn.fr/espece/cd_nom/{{model.cd_nom}}/tab/statut" class="btn mb-2 btn-primary ">
Voir les status sur la fiche INPN
</a>
</a>
{% for statut in model.status %}
<div class="alert alert-success">
{{statut.lb_type_statut}}
</div>
<b> {{statut.full_citation}} </b>
<b> {{statut.full_citation}} </b>
<p>
<b>Portée : </b> {{statut.niveau_admin}} - {{statut.cd_sig}} <br>
<b>Niveau : </b> {{statut.niveau_admin}} - {{statut.label_statut}} <br>
<a href="{{statut.doc_url}}"> Voir le texte</a>
<a href="{{statut.doc_url}}"> Voir le texte</a>
</p>
{% if statut.doc_url %}
{% endif %}
Expand Down Expand Up @@ -113,9 +113,9 @@ <h5 class="card-title col-1">
<tr>
<th class="col-5"> Rang </th>
<td class="col-5"> {{model.rang.nom_rang}} </th>
</tr>
</tr>
</table>

</div>

<div class="tab-pane fade" id="nav-lists" role="tabpanel" aria-labelledby="nav-lists-tab">
Expand Down Expand Up @@ -162,23 +162,29 @@ <h5 class="card-title"> {{theme}} </h5>
</thead>
{% for media in model.medias %}
<tr>
<td class="col-5">
<a href="{{ url_for('t_media.getThumbnail_tmedias', id_media=media.id_media)}}">
<img width="100" src="{{ url_for('t_media.getThumbnail_tmedias', id_media=media.id_media)}}" alt="Taxon image">
</a>
<td class="col-5">
{% if media.types.nom_type_media in ("Photo", "Photo_principale") %}
<a target='_blank' href='{{ url_for("t_media.getThumbnail_tmedias", id_media=media.id_media)}}'>
<img width="100" src='{{ url_for("t_media.getThumbnail_tmedias", id_media=media.id_media)}}' alt="Taxon image">
</a>
{% elif media.types.nom_type_media in ("Audio")%}
<audio controls src='{{ media.media_url }}'>
{% else%}
<a target='_blank' href='{{ media.media_url }}'>Lien média</a>
{% endif %}
</td>
<td> {{media.titre}} </td>
<td> {{media.desc_media}} </td>
<td> {{media.auteur}} </td>
<td> {{media.types.nom_type_media}} </td>
</tr>

{% endfor %}

</table>
</div>

</div>
</div>
<!-- END NAV CONTENT -->

</div>
Expand Down
8 changes: 8 additions & 0 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ class TMedias(db.Model):

taxon = db.relationship(Taxref, backref="medias")

@hybrid_property
def media_url(self):
if self.url:
return self.url
else:
path = f"/{current_app.config['MEDIA_FOLDER']}/{self.chemin}"
return path

def __repr__(self):
return self.titre

Expand Down

0 comments on commit 7deefdd

Please sign in to comment.