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

Ajout route t_medias #588

Merged
merged 3 commits into from
Dec 6, 2024
Merged
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
17 changes: 15 additions & 2 deletions apptax/taxonomie/routestmedias.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from flask import json, Blueprint, request, current_app, send_file, abort


from .models import TMedias
from .schemas import TMediasSchema
from .models import TMedias, BibTypesMedia
from .schemas import TMediasSchema, BibTypesMediaSchema

from .filemanager import FILEMANAGER

Expand All @@ -29,6 +29,19 @@ def get_tmedias(id=None):
return TMediasSchema().dump(medias, many=True)


@adresses.route("/types", methods=["GET"])
@adresses.route("/types/<int:id>", methods=["GET"])
def get_type_tmedias(id=None):
"""
Liste des types de médias
"""
if id:
type_media = BibTypesMedia.query.get(id)
return BibTypesMediaSchema().dump(type_media)
types_media = BibTypesMedia.query.all()
return BibTypesMediaSchema().dump(types_media, many=True)


@adresses.route("/bycdref/<cd_ref>", methods=["GET"])
def get_tmediasbyTaxon(cd_ref):
"""
Expand Down
16 changes: 16 additions & 0 deletions apptax/tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
AppUser,
)
from pypnusershub.tests.utils import set_logged_user_cookie
from schema import Schema, Optional, Or

from .fixtures import noms_example, attribut_example, liste

Expand All @@ -40,6 +41,21 @@ def user():

@pytest.mark.usefixtures("client_class", "temporary_transaction")
class TestAPIMedia:

type_media_schema = Schema(
[{"desc_type_media": Or(None, str), "id_type": int, "nom_type_media": str}]
)

def test_get_type_tmedias(self):
response = self.client.get(url_for("t_media.get_type_tmedias"))
assert response.status_code == 200
assert self.type_media_schema.is_valid(response.json)

def test_get_type_tmedias_one(self):
response = self.client.get(url_for("t_media.get_type_tmedias", id=1))
assert response.status_code == 200
assert response.json["nom_type_media"] == "Photo_principale"

def test_get_tmediasbyTaxon(self, noms_example):
response = self.client.get(url_for("t_media.get_tmediasbyTaxon", cd_ref=67111))
assert response.status_code == 200
Expand Down
15 changes: 15 additions & 0 deletions docs/developpement.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,18 @@

> Ces valeurs sont issues de la charte des codes couleurs pour les statuts Liste rouge, définis internationalement par l'Union internationale pour la conservation de la nature (UICN) \
> <https://uicn.fr/wp-content/uploads/2018/04/guide-pratique-listes-rouges-regionales-especes-menacees.pdf> (page 55)

## Médias

- `/tmedias/thumbnail/<int:id_media>` : Retourne un média redimensionné aux dimensions spécifiées (vignette)
- Params :
- id_media : identifiant du média
- h (defaut = 300) : hauteur souhaitée
- w (defaut = 400) : largeur souhaitée
- regenerate : force la régénération du fichier thumbnail
- `/tmedias/types` : Retourne la liste des types de médias
- `/tmedias/types/<int:id>` : Retourne le détail d'un type de média
- `/tmedias/` : Retourne la liste de tous les médias de TaxHub
- Attention route non paginée et sans filtre, donc peut crasher si il y a beaucoup de médias
- `/tmedias/<int:id>` : Retourne le détail d'un média
- `/tmedias/bycdref/<cd_ref>` : Retourne la liste des médias associés à un taxon
Loading