Skip to content

Commit

Permalink
Merge pull request #61 from naturalsolutions/fix/species_list
Browse files Browse the repository at this point in the history
fix / error 500 'générer la liste des espèces'
  • Loading branch information
edelclaux authored Jun 28, 2024
2 parents 60480a8 + 2f7efc7 commit 88593e6
Show file tree
Hide file tree
Showing 11 changed files with 721 additions and 13 deletions.
5 changes: 4 additions & 1 deletion backend/gn_module_zh/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from utils_flask_sqla.response import json_resp_accept_empty_list, json_resp

from .api_error import ZHApiError
from . import tasks # noqa: F401
from .forms import (
create_zh,
post_file_info,
Expand Down Expand Up @@ -81,6 +82,7 @@
get_main_picture_id,
get_user_cruved,
)
import gn_module_zh.tasks

blueprint = Blueprint("pr_zh", __name__, "./static", template_folder="templates")

Expand Down Expand Up @@ -810,8 +812,9 @@ def write_csv(id_zh):
tableName=blueprint.config[i]["table_name"],
schemaName=blueprint.config[i]["schema_name"],
filters={"id_zh": id_zh, "orderby": "id_zh"},
limit=100,
# TODO: limit=-1 when version 0.4.2 of Utils-Flask-SQLAlchemy will be released
)

results = query.return_query().get("items", [])
current_date = dt.now()
if results:
Expand Down
7 changes: 4 additions & 3 deletions backend/gn_module_zh/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class MapListConfig(Schema):

vertebrates_view_name = {
"schema_name": "pr_zh",
"table_name": "vertebrates",
"table_name": "vm_vertebrates",
"category": "vertebrates",
}

invertebrates_view_name = {
"schema_name": "pr_zh",
"table_name": "invertebrates",
"table_name": "vm_invertebrates",
"category": "invertebrates",
}

flora_view_name = {"schema_name": "pr_zh", "table_name": "flora", "category": "flora"}
flora_view_name = {"schema_name": "pr_zh", "table_name": "vm_flora", "category": "flora"}

# Name of the source of species data (tab5)
species_source_name = "GeoNature"
Expand Down Expand Up @@ -178,3 +178,4 @@ class GnModuleSchemaConf(Schema):
pdf_small_layer_number = fields.Integer(load_default=pdf_small_layer_number)
pdf_last_page_img = fields.String(load_default=pdf_last_page_img)
pdf_title = fields.String(load_default=pdf_title)
TAXON_VM_CRONTAB = fields.String(load_default="0 0,12 * * *")
2 changes: 1 addition & 1 deletion backend/gn_module_zh/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ def __check_if_rules(self):
raise ZHApiError(
message="no_rb_rules",
details="no existing rules for the river basin",
status_code=400,
)
except ZHApiError:
raise
Expand Down Expand Up @@ -1235,7 +1236,6 @@ def get_all_hierarchy_fields(id_rb: int):
tableName="all_rb_rules",
schemaName="pr_zh",
filters={"id_rb": id_rb, "orderby": "name"},
limit=100000,
)

results = query.return_query()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""create_vm_taxon_refresh_function
Revision ID: 76e89c793961
Revises: c0c4748a597a
Create Date: 2024-04-16 08:12:41.346540
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "76e89c793961"
down_revision = "c0c4748a597a"
branch_labels = None
depends_on = None


def upgrade():
op.execute(
"""
CREATE OR REPLACE FUNCTION pr_zh.refresh_taxon_materialized_views()
RETURNS void
LANGUAGE plpgsql
AS $function$
BEGIN
REFRESH MATERIALIZED VIEW pr_zh.vm_vertebrates;
REFRESH MATERIALIZED VIEW pr_zh.vm_invertebrates;
REFRESH MATERIALIZED VIEW pr_zh.vm_flora;
END;
$function$
;
"""
)


def downgrade():
op.execute(
"""
DROP FUNCTION pr_zh.refresh_taxon_materialized_views();
"""
)
Loading

0 comments on commit 88593e6

Please sign in to comment.