|
19 | 19 | from ref_geo.models import BibAreasTypes, LAreas, LiMunicipalities |
20 | 20 | from geonature.utils.config import config |
21 | 21 | from geonature.utils.env import DB, ROOT_DIR, BACKEND_DIR |
22 | | -from pypnnomenclature.models import TNomenclatures |
| 22 | +from pypnnomenclature.models import TNomenclatures, BibNomenclaturesTypes |
23 | 23 | from pypnusershub.db.models import Organisme, User |
24 | 24 | from sqlalchemy import desc, func, text, select, update, delete |
25 | 25 | from sqlalchemy.orm import aliased |
@@ -360,6 +360,8 @@ def get_pbf_complete(): |
360 | 360 | tz.menaces, |
361 | 361 | tz.diagnostic_bio, |
362 | 362 | tz.diagnostic_hydro, |
| 363 | + tz.product_owner, |
| 364 | + tz.input_scale, |
363 | 365 | Json_build_object('criteres_delim', tz.criteres_delim, |
364 | 366 | 'communes', |
365 | 367 | tz.communes, |
@@ -452,6 +454,119 @@ def get_ref_autocomplete(): |
452 | 454 | DB.session.close() |
453 | 455 |
|
454 | 456 |
|
| 457 | +@blueprint.route("/product_owner/autocomplete", methods=["GET"]) |
| 458 | +@permissions.check_cruved_scope("R", module_code="ZONES_HUMIDES") |
| 459 | +@json_resp |
| 460 | +def get_product_owner_autocomplete(): |
| 461 | + try: |
| 462 | + params = request.args |
| 463 | + search_product_owner = params.get("search_product_owner") |
| 464 | + # search_title = 'MCD' |
| 465 | + q = select( |
| 466 | + BibOrganismes, |
| 467 | + func.similarity(BibOrganismes.name, search_product_owner).label("idx_trgm"), |
| 468 | + ) |
| 469 | + |
| 470 | + search_product_owner = search_product_owner.replace(" ", "%") |
| 471 | + q = ( |
| 472 | + q.where(BibOrganismes.name.ilike("%" + search_product_owner + "%")) |
| 473 | + .where(BibOrganismes.is_product_owner == True) |
| 474 | + .order_by(desc("idx_trgm")) |
| 475 | + ) |
| 476 | + |
| 477 | + limit = request.args.get("limit", 20) |
| 478 | + data = DB.session.execute(q.limit(limit)).all() |
| 479 | + if data: |
| 480 | + return [d[0].as_dict() for d in data] |
| 481 | + else: |
| 482 | + return "No Result", 404 |
| 483 | + except Exception as e: |
| 484 | + if e.__class__.__name__ == "ZHApiError": |
| 485 | + raise ZHApiError(message=str(e.message), details=str(e.details)) |
| 486 | + exc_type, value, tb = sys.exc_info() |
| 487 | + raise ZHApiError( |
| 488 | + message="get_product_owner_autocomplete_error", |
| 489 | + details=str(exc_type) + ": " + str(e.with_traceback(tb)), |
| 490 | + ) |
| 491 | + finally: |
| 492 | + DB.session.close() |
| 493 | + |
| 494 | + |
| 495 | +@blueprint.route("/input_scale/autocomplete", methods=["GET"]) |
| 496 | +@permissions.check_cruved_scope("R", module_code="ZONES_HUMIDES") |
| 497 | +@json_resp |
| 498 | +def get_input_scale_autocomplete(): |
| 499 | + try: |
| 500 | + params = request.args |
| 501 | + search_input_scale = params.get("search_input_scale") |
| 502 | + id_nommenclature_type = DB.session.execute( |
| 503 | + select(BibNomenclaturesTypes.id_type).where( |
| 504 | + BibNomenclaturesTypes.mnemonique.like("INPUT_SCALE") |
| 505 | + ) |
| 506 | + ).scalar_one() |
| 507 | + q = ( |
| 508 | + select(TNomenclatures.mnemonique) |
| 509 | + .where(TNomenclatures.id_type == id_nommenclature_type) |
| 510 | + .where(TNomenclatures.mnemonique.ilike("%" + search_input_scale + "%")) |
| 511 | + ) |
| 512 | + |
| 513 | + limit = request.args.get("limit", 20) |
| 514 | + data = DB.session.execute(q.limit(limit)).all() |
| 515 | + |
| 516 | + if data: |
| 517 | + return [d[0] for d in data] |
| 518 | + else: |
| 519 | + return "No Result", 404 |
| 520 | + except Exception as e: |
| 521 | + if e.__class__.__name__ == "ZHApiError": |
| 522 | + raise ZHApiError(message=str(e.message), details=str(e.details)) |
| 523 | + exc_type, value, tb = sys.exc_info() |
| 524 | + raise ZHApiError( |
| 525 | + message="get_input_scale_autocomplete_error", |
| 526 | + details=str(exc_type) + ": " + str(e.with_traceback(tb)), |
| 527 | + ) |
| 528 | + finally: |
| 529 | + DB.session.close() |
| 530 | + |
| 531 | + |
| 532 | +@blueprint.route("/input_ref_geo/autocomplete", methods=["GET"]) |
| 533 | +@permissions.check_cruved_scope("R", module_code="ZONES_HUMIDES") |
| 534 | +@json_resp |
| 535 | +def get_input_ref_geo_autocomplete(): |
| 536 | + try: |
| 537 | + params = request.args |
| 538 | + search_input_ref_geo = params.get("search_input_ref_geo") |
| 539 | + id_nommenclature_type = DB.session.execute( |
| 540 | + select(BibNomenclaturesTypes.id_type).where( |
| 541 | + BibNomenclaturesTypes.mnemonique.like("INPUT_REF_GEO") |
| 542 | + ) |
| 543 | + ).scalar_one() |
| 544 | + q = ( |
| 545 | + select(TNomenclatures.mnemonique) |
| 546 | + .where(TNomenclatures.id_type == id_nommenclature_type) |
| 547 | + .where(TNomenclatures.mnemonique.ilike("%" + search_input_ref_geo + "%")) |
| 548 | + ) |
| 549 | + |
| 550 | + limit = request.args.get("limit", 20) |
| 551 | + data = DB.session.execute(q.limit(limit)).all() |
| 552 | + |
| 553 | + if data: |
| 554 | + return [d[0] for d in data] |
| 555 | + else: |
| 556 | + return "No Result", 404 |
| 557 | + |
| 558 | + except Exception as e: |
| 559 | + if e.__class__.__name__ == "ZHApiError": |
| 560 | + raise ZHApiError(message=str(e.message), details=str(e.details)) |
| 561 | + exc_type, value, tb = sys.exc_info() |
| 562 | + raise ZHApiError( |
| 563 | + message="get_input_ref_geo_autocomplete_error", |
| 564 | + details=str(exc_type) + ": " + str(e.with_traceback(tb)), |
| 565 | + ) |
| 566 | + finally: |
| 567 | + DB.session.close() |
| 568 | + |
| 569 | + |
455 | 570 | @blueprint.route("/<int:id_zh>/files", methods=["GET"]) |
456 | 571 | @permissions.check_cruved_scope("R", module_code="ZONES_HUMIDES") |
457 | 572 | @json_resp_accept_empty_list |
@@ -628,7 +743,6 @@ def get_tab_data(id_tab): |
628 | 743 | raise BadRequest( |
629 | 744 | "Géométrie manquante", |
630 | 745 | ) |
631 | | - |
632 | 746 | # POST / PATCH |
633 | 747 | if "id_zh" not in form_data.keys(): |
634 | 748 | # set geometry from coordinates |
|
0 commit comments