diff --git a/admin/c2cgeoportal_admin/views/dimension_layers.py b/admin/c2cgeoportal_admin/views/dimension_layers.py index b951e8f430..169627eb40 100644 --- a/admin/c2cgeoportal_admin/views/dimension_layers.py +++ b/admin/c2cgeoportal_admin/views/dimension_layers.py @@ -37,7 +37,7 @@ from c2cgeoportal_admin.views.layers import LayerViews from c2cgeoportal_commons.models.main import DimensionLayer -_list_field = partial(ListField, DimensionLayer) # type: ignore[var-annotated] +_list_field = partial(ListField, DimensionLayer) _T = TypeVar("_T", bound=DimensionLayer) diff --git a/admin/c2cgeoportal_admin/views/functionalities.py b/admin/c2cgeoportal_admin/views/functionalities.py index 0ba136d76d..71de35fcfc 100644 --- a/admin/c2cgeoportal_admin/views/functionalities.py +++ b/admin/c2cgeoportal_admin/views/functionalities.py @@ -47,7 +47,7 @@ from c2cgeoportal_admin.views.logged_views import LoggedViews from c2cgeoportal_commons.models.main import Functionality -_list_field = partial(ListField, Functionality) # type: ignore[var-annotated] +_list_field = partial(ListField, Functionality) def _translate_available_functionality( diff --git a/admin/c2cgeoportal_admin/views/interfaces.py b/admin/c2cgeoportal_admin/views/interfaces.py index 7198ea7d08..806534cc6a 100644 --- a/admin/c2cgeoportal_admin/views/interfaces.py +++ b/admin/c2cgeoportal_admin/views/interfaces.py @@ -42,7 +42,7 @@ from c2cgeoportal_admin.views.logged_views import LoggedViews from c2cgeoportal_commons.models.main import Interface -_list_field = partial(ListField, Interface) # type: ignore[var-annotated] +_list_field = partial(ListField, Interface) base_schema = GeoFormSchemaNode(Interface) diff --git a/admin/c2cgeoportal_admin/views/layer_groups.py b/admin/c2cgeoportal_admin/views/layer_groups.py index 51e473ed06..fc5a61d93a 100644 --- a/admin/c2cgeoportal_admin/views/layer_groups.py +++ b/admin/c2cgeoportal_admin/views/layer_groups.py @@ -48,7 +48,7 @@ from c2cgeoportal_admin.views.treeitems import TreeItemViews from c2cgeoportal_commons.models.main import LayerGroup, TreeGroup -_list_field = partial(ListField, LayerGroup) # type: ignore[var-annotated] +_list_field = partial(ListField, LayerGroup) base_schema = GeoFormSchemaNode(LayerGroup, widget=FormWidget(fields_template="layer_group_fields")) base_schema.add(children_schema_node()) diff --git a/admin/c2cgeoportal_admin/views/layers.py b/admin/c2cgeoportal_admin/views/layers.py index b456fdc781..038472b15f 100644 --- a/admin/c2cgeoportal_admin/views/layers.py +++ b/admin/c2cgeoportal_admin/views/layers.py @@ -37,7 +37,7 @@ from c2cgeoportal_admin.views.treeitems import TreeItemViews from c2cgeoportal_commons.models.main import Interface, Layer -_list_field = partial(ListField, Layer) # type: ignore[var-annotated] +_list_field = partial(ListField, Layer) _T = TypeVar("_T", bound=Layer) diff --git a/admin/c2cgeoportal_admin/views/layers_cog.py b/admin/c2cgeoportal_admin/views/layers_cog.py index 69acff38ab..7ba329eba9 100644 --- a/admin/c2cgeoportal_admin/views/layers_cog.py +++ b/admin/c2cgeoportal_admin/views/layers_cog.py @@ -53,7 +53,7 @@ from c2cgeoportal_commons.lib.literal import Literal from c2cgeoportal_commons.models.main import LayerCOG, LayerGroup -_list_field = partial(ListField, LayerCOG) # type: ignore[var-annotated] +_list_field = partial(ListField, LayerCOG) base_schema = GeoFormSchemaNode(LayerCOG, widget=FormWidget(fields_template="layer_fields")) diff --git a/admin/c2cgeoportal_admin/views/layers_vectortiles.py b/admin/c2cgeoportal_admin/views/layers_vectortiles.py index 6c71d2767a..c451da4128 100644 --- a/admin/c2cgeoportal_admin/views/layers_vectortiles.py +++ b/admin/c2cgeoportal_admin/views/layers_vectortiles.py @@ -53,7 +53,7 @@ from c2cgeoportal_commons.lib.literal import Literal from c2cgeoportal_commons.models.main import LayerGroup, LayerVectorTiles -_list_field = partial(ListField, LayerVectorTiles) # type: ignore[var-annotated] +_list_field = partial(ListField, LayerVectorTiles) base_schema = GeoFormSchemaNode(LayerVectorTiles, widget=FormWidget(fields_template="layer_fields")) diff --git a/admin/c2cgeoportal_admin/views/layers_wms.py b/admin/c2cgeoportal_admin/views/layers_wms.py index 2101ce9a8d..8acd8bab2b 100644 --- a/admin/c2cgeoportal_admin/views/layers_wms.py +++ b/admin/c2cgeoportal_admin/views/layers_wms.py @@ -54,7 +54,7 @@ from c2cgeoportal_admin.views.dimension_layers import DimensionLayerViews from c2cgeoportal_commons.models.main import LayerGroup, LayerWMS, LayerWMTS, LogAction, OGCServer, TreeItem -_list_field = partial(ListField, LayerWMS) # type: ignore[var-annotated] +_list_field = partial(ListField, LayerWMS) base_schema = GeoFormSchemaNode(LayerWMS, widget=FormWidget(fields_template="layer_fields")) base_schema.add(dimensions_schema_node(LayerWMS.dimensions)) diff --git a/admin/c2cgeoportal_admin/views/layers_wmts.py b/admin/c2cgeoportal_admin/views/layers_wmts.py index 49361ada41..1798d6317c 100644 --- a/admin/c2cgeoportal_admin/views/layers_wmts.py +++ b/admin/c2cgeoportal_admin/views/layers_wmts.py @@ -54,7 +54,7 @@ from c2cgeoportal_admin.views.dimension_layers import DimensionLayerViews from c2cgeoportal_commons.models.main import LayerGroup, LayerWMS, LayerWMTS, LogAction, OGCServer, TreeItem -_list_field = partial(ListField, LayerWMTS) # type: ignore[var-annotated] +_list_field = partial(ListField, LayerWMTS) base_schema = GeoFormSchemaNode(LayerWMTS, widget=FormWidget(fields_template="layer_fields")) base_schema.add(dimensions_schema_node(LayerWMTS.dimensions)) diff --git a/admin/c2cgeoportal_admin/views/logs.py b/admin/c2cgeoportal_admin/views/logs.py index a94e1d0cc9..922df76cb0 100644 --- a/admin/c2cgeoportal_admin/views/logs.py +++ b/admin/c2cgeoportal_admin/views/logs.py @@ -34,7 +34,7 @@ from c2cgeoportal_commons.models import _ from c2cgeoportal_commons.models.main import AbstractLog -_list_field = partial(ListField, AbstractLog) # type: ignore[var-annotated] +_list_field = partial(ListField, AbstractLog) @view_defaults(match_param="table=logs") diff --git a/admin/c2cgeoportal_admin/views/oauth2_clients.py b/admin/c2cgeoportal_admin/views/oauth2_clients.py index 02a4b8792a..e30d5618a5 100644 --- a/admin/c2cgeoportal_admin/views/oauth2_clients.py +++ b/admin/c2cgeoportal_admin/views/oauth2_clients.py @@ -42,7 +42,7 @@ from c2cgeoportal_admin.views.logged_views import LoggedViews from c2cgeoportal_commons.models.static import Log, OAuth2Client -_list_field = partial(ListField, OAuth2Client) # type: ignore[var-annotated] +_list_field = partial(ListField, OAuth2Client) base_schema = GeoFormSchemaNode(OAuth2Client) base_schema.add_unique_validator(OAuth2Client.client_id, OAuth2Client.id) diff --git a/admin/c2cgeoportal_admin/views/ogc_servers.py b/admin/c2cgeoportal_admin/views/ogc_servers.py index 1a3472a4f8..92e97c6b44 100644 --- a/admin/c2cgeoportal_admin/views/ogc_servers.py +++ b/admin/c2cgeoportal_admin/views/ogc_servers.py @@ -57,7 +57,7 @@ from c2cgeoportal_commons.models import cache_invalidate_cb from c2cgeoportal_commons.models.main import LogAction, OGCServer -_list_field = partial(ListField, OGCServer) # type: ignore[var-annotated] +_list_field = partial(ListField, OGCServer) base_schema = GeoFormSchemaNode(OGCServer, widget=FormWidget(fields_template="ogcserver_fields")) base_schema.add_unique_validator(OGCServer.name, OGCServer.id) diff --git a/admin/c2cgeoportal_admin/views/restriction_areas.py b/admin/c2cgeoportal_admin/views/restriction_areas.py index 4fdc721e93..17b63d499f 100644 --- a/admin/c2cgeoportal_admin/views/restriction_areas.py +++ b/admin/c2cgeoportal_admin/views/restriction_areas.py @@ -49,7 +49,7 @@ from c2cgeoportal_admin.widgets import ChildrenWidget, ChildWidget from c2cgeoportal_commons.models.main import Layer, RestrictionArea -_list_field = partial(ListField, RestrictionArea) # type: ignore[var-annotated] +_list_field = partial(ListField, RestrictionArea) base_schema = GeoFormSchemaNode(RestrictionArea, widget=FormWidget(fields_template="restriction_area_fields")) base_schema.add_before("area", roles_schema_node(RestrictionArea.roles)) diff --git a/admin/c2cgeoportal_admin/views/roles.py b/admin/c2cgeoportal_admin/views/roles.py index a646a7b60d..ec8ee1706d 100644 --- a/admin/c2cgeoportal_admin/views/roles.py +++ b/admin/c2cgeoportal_admin/views/roles.py @@ -50,7 +50,7 @@ from c2cgeoportal_commons.models.main import Role from c2cgeoportal_commons.models.static import User -_list_field = partial(ListField, Role) # type: ignore[var-annotated] +_list_field = partial(ListField, Role) base_schema = GeoFormSchemaNode(Role, widget=FormWidget(fields_template="role_fields")) base_schema.add_before("extent", functionalities_schema_node(Role.functionalities, Role)) diff --git a/admin/c2cgeoportal_admin/views/themes.py b/admin/c2cgeoportal_admin/views/themes.py index 43982260c0..15fc45980d 100644 --- a/admin/c2cgeoportal_admin/views/themes.py +++ b/admin/c2cgeoportal_admin/views/themes.py @@ -52,7 +52,7 @@ from c2cgeoportal_admin.views.treeitems import TreeItemViews from c2cgeoportal_commons.models.main import Functionality, Interface, Role, Theme -_list_field = partial(ListField, Theme) # type: ignore[var-annotated] +_list_field = partial(ListField, Theme) base_schema = GeoFormSchemaNode(Theme, widget=FormWidget(fields_template="theme_fields")) base_schema.add(children_schema_node(only_groups=True)) diff --git a/admin/c2cgeoportal_admin/views/treeitems.py b/admin/c2cgeoportal_admin/views/treeitems.py index fb5762cf2b..f762d9f22b 100644 --- a/admin/c2cgeoportal_admin/views/treeitems.py +++ b/admin/c2cgeoportal_admin/views/treeitems.py @@ -38,7 +38,7 @@ from c2cgeoportal_admin.views.logged_views import LoggedViews from c2cgeoportal_commons.models.main import LayergroupTreeitem, Metadata, TreeGroup, TreeItem -_list_field = partial(ListField, TreeItem) # type: ignore[var-annotated] +_list_field = partial(ListField, TreeItem) _T = TypeVar("_T", bound=TreeItem) diff --git a/admin/c2cgeoportal_admin/views/users.py b/admin/c2cgeoportal_admin/views/users.py index a706bf88c0..769de9aa64 100644 --- a/admin/c2cgeoportal_admin/views/users.py +++ b/admin/c2cgeoportal_admin/views/users.py @@ -50,7 +50,7 @@ from c2cgeoportal_commons.models.main import Role from c2cgeoportal_commons.models.static import Log, User -_list_field = partial(ListField, User) # type: ignore[var-annotated] +_list_field = partial(ListField, User) base_schema = GeoFormSchemaNode(User, widget=FormWidget(fields_template="user_fields")) base_schema.add(roles_schema_node(User.roles)) diff --git a/commons/c2cgeoportal_commons/models/static.py b/commons/c2cgeoportal_commons/models/static.py index 13db361c7a..0e60d1f80d 100644 --- a/commons/c2cgeoportal_commons/models/static.py +++ b/commons/c2cgeoportal_commons/models/static.py @@ -378,7 +378,7 @@ class Shorturl(Base): # type: ignore id: Mapped[int] = mapped_column(Integer, primary_key=True) url: Mapped[str] = mapped_column(Unicode) ref: Mapped[str] = mapped_column(String(20), index=True, unique=True, nullable=False) - creator_email: Mapped[str] = mapped_column(Unicode(200), nullable=True) + creator_email: Mapped[str | None] = mapped_column(Unicode(200), nullable=True) creation: Mapped[datetime] = mapped_column(DateTime) last_hit: Mapped[datetime] = mapped_column(DateTime, nullable=True) nb_hits: Mapped[int] = mapped_column(Integer) diff --git a/geoportal/c2cgeoportal_geoportal/views/shortener.py b/geoportal/c2cgeoportal_geoportal/views/shortener.py index 848d171dda..2480734a62 100644 --- a/geoportal/c2cgeoportal_geoportal/views/shortener.py +++ b/geoportal/c2cgeoportal_geoportal/views/shortener.py @@ -30,6 +30,7 @@ import random import string from datetime import datetime +from typing import cast from urllib.parse import urlparse import pyramid.request @@ -37,8 +38,7 @@ from pyramid.view import view_config from c2cgeoportal_commons.lib.email_ import send_email_config -from c2cgeoportal_commons.models import DBSession -from c2cgeoportal_commons.models.static import Shorturl +from c2cgeoportal_commons.models import DBSession, static from c2cgeoportal_geoportal import is_allowed_url from c2cgeoportal_geoportal.lib.common_headers import Cache, set_common_headers @@ -60,7 +60,7 @@ def get(self) -> HTTPFound: assert DBSession is not None ref = self.request.matchdict["ref"] - short_urls = DBSession.query(Shorturl).filter(Shorturl.ref == ref).all() + short_urls = DBSession.query(static.Shorturl).filter(static.Shorturl.ref == ref).all() if len(short_urls) != 1: raise HTTPNotFound(f"Ref '{ref!s}' not found") @@ -110,7 +110,7 @@ def create(self) -> dict[str, str]: random.choice(string.ascii_letters + string.digits) # nosec for i in range(self.settings.get("length", 4)) ) - test_url = DBSession.query(Shorturl).filter(Shorturl.ref == ref).all() + test_url = DBSession.query(static.Shorturl).filter(static.Shorturl.ref == ref).all() if not test_url: break tries += 1 @@ -119,10 +119,10 @@ def create(self) -> dict[str, str]: logger.error(message) raise HTTPInternalServerError(message) - user_email = self.request.user.email if self.request.user is not None else None + user_email = cast(static.User, self.request.user).email if self.request.user is not None else None email = self.request.params.get("email") if not shortened: - short_url = Shorturl() + short_url = static.Shorturl() short_url.url = url short_url.ref = ref short_url.creator_email = user_email