Skip to content

Commit

Permalink
Merge pull request #497 from camptocamp/fix-type
Browse files Browse the repository at this point in the history
Fix `sort_column` and `filter_column` can also be `InstrumentedAttribute`
  • Loading branch information
sbrunner authored Nov 5, 2024
2 parents e37d2a5 + 260da75 commit 5bca24d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions c2cgeoform/views/abstract_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ def __init__(
key: Optional[str] = None,
label: Optional[str] = None,
renderer: Optional[Callable[[T], JSON]] = None,
sort_column: Optional[sqlalchemy.sql.elements.ColumnElement[Any]] = None,
filter_column: Optional[sqlalchemy.sql.elements.ColumnElement[Any]] = None,
sort_column: Optional[
Union[
sqlalchemy.sql.elements.ColumnElement[Any],
sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
]
] = None,
filter_column: Optional[
Union[
sqlalchemy.sql.elements.ColumnElement[Any],
sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
]
] = None,
visible: bool = True,
):
self._attr = _getattr(model, attr)
Expand Down Expand Up @@ -140,7 +150,12 @@ def sortable(self) -> bool:
def filtrable(self) -> bool:
return self._filter_column is not None and isinstance(self._filter_column.type, types.String)

def sort_column(self) -> sqlalchemy.sql.expression.ColumnElement[Any]:
def sort_column(
self,
) -> Union[
sqlalchemy.sql.expression.ColumnElement[Any],
sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
]:
assert self._sort_column is not None
return self._sort_column

Expand Down

0 comments on commit 5bca24d

Please sign in to comment.