Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ajout liens importants taxons #608

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ def ficheEspece(cd_nom):
articles = vmMedias.getLinks_and_articles(
connection, cd_ref, current_app.config["ATTR_LIEN"], current_app.config["ATTR_PDF"]
)

liens_importants = []
if current_app.config.get("TYPES_MEDIAS_LIENS_IMPORTANTS"):
liens_config = current_app.config["TYPES_MEDIAS_LIENS_IMPORTANTS"]
media_type_ids = list({t["type_media_id"] for t in liens_config})
liens_importants = vmMedias.get_liens_importants(connection, cd_ref, media_type_ids)
icones_by_media_type = {
i["type_media_id"]: i["icon"] for i in liens_config if i.get("icon")
}
for lien in liens_importants:
lien["icon"] = icones_by_media_type.get(lien["id_type"], "")

taxonDescription = vmCorTaxonAttribut.getAttributesTaxon(
connection,
cd_ref,
Expand Down Expand Up @@ -281,6 +293,7 @@ def ficheEspece(cd_nom):
photoCarousel=photoCarousel,
videoAudio=videoAudio,
articles=articles,
liensImportants=liens_importants,
taxonDescription=taxonDescription,
observers=observers,
organisms=organisms,
Expand Down
23 changes: 23 additions & 0 deletions atlas/configuration/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,29 @@ ATTR_VIMEO = 9
# Coupe le nom_vernaculaire à la 1ere virgule sur les fiches espèces
SPLIT_NOM_VERN = True

# Permet de définir des types de médias TaxHub comme « Liens importants » de la fiche taxon.
# Les liens importants sont mis en avant dans l'affichage de la fiche.
# - `type_media_id` : l'ID d'un type de média définit dans l'instance TaxHub.
# - `icon` (optionnel) : l'URL d'une image à ajouter sur le bouton du lien.
#
# Une classe CSS `lien-important-type-XX` est ajoutée sur l'élément HTML du lien avec XX l'ID du type
# de média. Cela permet de personnaliser l'apparence des liens, par type, dans `custom.css`.
#
# Exemple de configuration :
# (les types médias et les icones sont des exemples et n'existent pas de base
# sur une instance Atlas/TaxHub)
TYPES_MEDIAS_LIENS_IMPORTANTS = [
{
'type_media_id': 10, # Lien participation campagne d'observation
'icon': '/static/custom/images/jumelles.svg'
},
{
'type_media_id': 11, # Lien vers fiche focus territoire
'icon': '/static/custom/images/logo_fiche_focus.png'
}
]


############################################
#### FICHE COMMUNE ET RANG TAXONOMIQUE #####
############################################
Expand Down
11 changes: 11 additions & 0 deletions atlas/modeles/repositories/vmMedias.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ def getLinks_and_articles(connection, cd_ref, id3, id4):
return [_format_media(r) for r in req]


def get_liens_importants(connection, cd_ref, media_ids):
sql = """
SELECT *
FROM atlas.vm_medias
WHERE id_type = ANY(:media_ids) AND cd_ref = :thiscdref
ORDER BY date_media DESC
"""
req = connection.execute(text(sql), thiscdref=cd_ref, media_ids=media_ids)
return [_format_media(r) for r in req]


def getPhotosGallery(connection, id1, id2):
sql = """
SELECT m.*, t.nom_vern, t.lb_nom, t.nb_obs
Expand Down
26 changes: 26 additions & 0 deletions atlas/static/css/ficheEspece.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ p.imgDescription.main {
padding: 0px;
}

/* Liens importants */

.liens-importants-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.7rem 0;
}

.lien-important {
display: flex;
background-color: var(--main-color);
color: white;
text-decoration: none;
border-radius: 10px;
padding: 0.5rem 1rem;
gap: 0.5rem;
align-items: center;
}

.lien-important:hover {
background-color: var(--second-color);
color: white;
text-decoration: none;
}

/*Medias*/

i.btn-more {
Expand Down
14 changes: 14 additions & 0 deletions atlas/templates/speciesSheet/_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@
<!--Left row-->
<div class="col-lg-7 col-md-8 col-sm-12 col-xs-12">
{% include 'templates/speciesSheet/identityCard.html' %}
{% if liensImportants %}
<div class="liens-importants-container mt-4">
{% for lien in liensImportants %}
<a
class="lien-important lien-important-type-{{ lien.id_type }}"
href="{{ lien.path }}">
{% if lien.icon %}
<img src="{{ lien.icon }}" alt="" />
{% endif %}
<span>{{ lien.title }}</span>
</a>
{% endfor %}
</div>
{% endif %}
{% include 'templates/speciesSheet/map.html' %}
{% include 'templates/speciesSheet/otherInformations.html' %}
</div>
Expand Down