Skip to content

Commit

Permalink
Correction post review
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Jan 11, 2024
1 parent 04e74f3 commit 5b5f2f6
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions backend/gn_module_monitoring/command/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from pathlib import Path
from flask.cli import with_appcontext
from sqlalchemy.sql import text
from sqlalchemy.sql.expression import select
from sqlalchemy.sql import text, select

from geonature.utils.env import DB, BACKEND_DIR
from geonature.core.gn_synthese.models import TSources
Expand Down
12 changes: 6 additions & 6 deletions backend/gn_module_monitoring/command/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from pathlib import Path

from flask import current_app
from sqlalchemy import and_, text, delete
from sqlalchemy import and_, text, delete, select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import select
from sqlalchemy.orm.exc import NoResultFound

from sqlalchemy.dialects.postgresql import insert as pg_insert
Expand Down Expand Up @@ -153,10 +152,11 @@ def insert_module_available_permissions(module_code, perm_object_code, session):
).scalar_one()
try:
perm = session.execute(
select(PermissionAvailable)
.where(PermissionAvailable.module == module)
.where(PermissionAvailable.object == perm_object)
.where(PermissionAvailable.action == permaction)
select(PermissionAvailable).where(
PermissionAvailable.module == module,
PermissionAvailable.object == perm_object,
PermissionAvailable.action == permaction,
)
).scalar_one()
except NoResultFound:
perm = PermissionAvailable(
Expand Down
3 changes: 1 addition & 2 deletions backend/gn_module_monitoring/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from pathlib import Path
import json

from sqlalchemy import and_
from sqlalchemy.sql.expression import select
from sqlalchemy import and_, select
from sqlalchemy.exc import NoResultFound

from geonature.core.gn_commons.models import BibTablesLocation, TModules
Expand Down
12 changes: 4 additions & 8 deletions backend/gn_module_monitoring/monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,8 @@ class TMonitoringSitesGroups(DB.Model, PermissionModel, SitesGroupsQuery):
nb_visits = column_property(
select(func.count(TMonitoringVisits.id_base_site))
.where(
and_(
TMonitoringVisits.id_base_site == TMonitoringSites.id_base_site,
TMonitoringSites.id_sites_group == id_sites_group,
)
TMonitoringVisits.id_base_site == TMonitoringSites.id_base_site,
TMonitoringSites.id_sites_group == id_sites_group,
)
.scalar_subquery()
)
Expand Down Expand Up @@ -657,10 +655,8 @@ class TMonitoringModules(TModules, PermissionModel, MonitoringQuery):
TMonitoringSitesGroups.nb_visits = column_property(
select(func.count(TMonitoringVisits.id_base_site))
.where(
and_(
TMonitoringVisits.id_base_site == TMonitoringSites.id_base_site,
TMonitoringSites.id_sites_group == TMonitoringSitesGroups.id_sites_group,
)
TMonitoringVisits.id_base_site == TMonitoringSites.id_base_site,
TMonitoringSites.id_sites_group == TMonitoringSitesGroups.id_sites_group,
)
.scalar_subquery()
)
Expand Down
5 changes: 3 additions & 2 deletions backend/gn_module_monitoring/monitoring/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sqlalchemy import Unicode, and_, Unicode, func, or_, false, true
from sqlalchemy.orm import Query, load_only, joinedload
from sqlalchemy.types import DateTime
from sqlalchemy.sql.expression import Select
from werkzeug.datastructures import MultiDict


Expand All @@ -11,7 +12,7 @@

class GnMonitoringGenericFilter:
@classmethod
def filter_by_params(cls, query: Query, params: MultiDict = None, **kwargs):
def filter_by_params(cls, query: Select, params: MultiDict = None, **kwargs):
and_list = [
true(),
]
Expand All @@ -27,7 +28,7 @@ def filter_by_params(cls, query: Query, params: MultiDict = None, **kwargs):
return query.where(and_query)

@classmethod
def sort(cls, query: Query, label: str, direction: str):
def sort(cls, query: Select, label: str, direction: str):
order_by = getattr(cls, label)
if direction == "desc":
order_by = order_by.desc()
Expand Down
3 changes: 1 addition & 2 deletions backend/gn_module_monitoring/routes/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"""

from flask import request
from sqlalchemy import and_, inspect, cast
from sqlalchemy import and_, inspect, cast, select
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from sqlalchemy.sql.expression import select

from pypnnomenclature.models import TNomenclatures, BibNomenclaturesTypes
from pypnnomenclature.repository import get_nomenclature_list
Expand Down
2 changes: 1 addition & 1 deletion backend/gn_module_monitoring/routes/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from flask import request, send_from_directory, url_for, g, current_app
import datetime as dt

from sqlalchemy import select
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.expression import select

from utils_flask_sqla.response import json_resp, json_resp_accept_empty_list
from utils_flask_sqla.response import to_csv_resp, to_json_resp
Expand Down
3 changes: 1 addition & 2 deletions backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import json
from geonature.core.gn_commons.schemas import ModuleSchema
from geonature.utils.env import db
from sqlalchemy import and_
from sqlalchemy import and_, select
from sqlalchemy.orm import Load, joinedload
from sqlalchemy.sql import func
from sqlalchemy.sql.expression import select
from werkzeug.datastructures import MultiDict
from werkzeug.exceptions import Forbidden

Expand Down
2 changes: 1 addition & 1 deletion backend/gn_module_monitoring/tests/fixtures/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pypnusershub.db.models import User
from utils_flask_sqla_geo.generic import GenericQueryGeo

from sqlalchemy.sql.expression import select
from sqlalchemy import select
from flask import current_app
from pathlib import Path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from sqlalchemy.sql.expression import select
from sqlalchemy import select
from gn_module_monitoring.monitoring.models import TMonitoringSitesGroups


Expand Down
4 changes: 2 additions & 2 deletions backend/gn_module_monitoring/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from geonature.core.gn_permissions.models import TObjects, PermObject, PermissionAvailable
from geonature.utils.errors import GeoNatureError
from marshmallow import Schema
from sqlalchemy import cast, func, text
from sqlalchemy import cast, func, text, select
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import load_only, joinedload
from sqlalchemy.sql.expression import Select, select
from sqlalchemy.sql.expression import Select
from werkzeug.datastructures import MultiDict

from gn_module_monitoring.monitoring.schemas import paginate_schema
Expand Down

0 comments on commit 5b5f2f6

Please sign in to comment.