Skip to content

Commit

Permalink
fix: keep /refresh route and remove unused code
Browse files Browse the repository at this point in the history
- Remove unused code according to list taxhub loaded in backend
- Keep /refresh route to allow taxhub to refresh its list of taxref
calling 'biblistes' API route.

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Jan 2, 2025
1 parent 5d5c37f commit 9196bdb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
10 changes: 9 additions & 1 deletion backend/gncitizen/core/taxonomy/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
reformat_taxa,
get_taxa_by_cd_nom,
get_all_medias_types,
get_all_attributes
get_all_attributes,
refresh_taxonlist
)

taxo_api = Blueprint("taxonomy", __name__)

@taxo_api.route("/taxonomy/refresh", methods=["GET"])
@json_resp
def refresh():
lists = refresh_taxonlist()
return lists


@taxo_api.route("/taxonomy/lists", methods=["GET"])
@json_resp
def get_lists():
Expand Down
26 changes: 5 additions & 21 deletions backend/gncitizen/utils/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ def taxhub_rest_get_all_lists() -> Optional[Dict]:
return None


# TODO: [LIMIT100-TAXON-COMPAT-THV2] normalement à enlever
def make_taxon_repository(taxhub_list_id: int) -> List[Taxon]:
taxa = taxhub_rest_get_taxon_list(taxhub_list_id)
if isinstance(taxa, dict) and "items" in taxa:
reformatted_taxa = reformat_taxa(taxa)
else:
reformatted_taxa = []
return reformatted_taxa


def get_specie_from_cd_nom(cd_nom) -> Dict:
"""get specie datas from taxref id (cd_nom)
Expand Down Expand Up @@ -121,21 +112,14 @@ def get_specie_from_cd_nom(cd_nom) -> Dict:
taxref[k] = official_taxa.get(k, "")
return taxref

# TODO: [LIMIT100-TAXON-COMPAT-THV2] normalement à enlever

def refresh_taxonlist() -> Dict:
"""refresh taxon list"""
logger.info("Pre loading taxhub data (taxa lists and medias)")
logger.info("Pre loading taxhub lists information (nb lists, list names)")
taxhub_lists = taxhub_rest_get_all_lists()
if taxhub_lists:
count = 0
for taxhub_list in taxhub_lists:
count += 1
logger.info(f"loading list {count}/{len(taxhub_lists)}")
r = make_taxon_repository(taxhub_list["id_liste"])
taxhub_full_lists[taxhub_list["id_liste"]] = r
else:
if not taxhub_lists:
logger.warning("ERROR: No taxhub lists available")
return taxhub_full_lists
return taxhub_lists

def get_all_medias_types() -> Dict:
"""get all medias types"""
Expand Down Expand Up @@ -170,7 +154,7 @@ def get_all_attributes() -> Dict:
return attributes
return None

# TODO: [LIMIT100-TAXON-COMPAT-THV2] normalement à enlever

daemon = Thread(target=refresh_taxonlist, daemon=True, name="Monitor")
daemon.start()

Expand Down
2 changes: 1 addition & 1 deletion backend/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'admin/master.html' %}

{% block body %}
<!-- # TODO: [LIMIT100-TAXON-COMPAT-THV2] normalement à enlever -->

<div class="container">
<h2>Refresh TaxHub lists</h2>
<p>
Expand Down

0 comments on commit 9196bdb

Please sign in to comment.