-
-
Notifications
You must be signed in to change notification settings - Fork 145
Feature: Add geometry filters #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
e3ed66b
fb3a065
3fc6b2c
2e3e35b
744c260
a0bfa66
17ce3f8
a097404
95dab27
e68b416
2b1db9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ | |||||
from strawberry.file_uploads.scalars import Upload | ||||||
from strawberry.scalars import JSON | ||||||
from strawberry.types.enum import EnumValueDefinition | ||||||
from strawberry.types.scalar import ScalarWrapper | ||||||
from strawberry.utils.str_converters import capitalize_first, to_camel_case | ||||||
|
||||||
from strawberry_django import filters | ||||||
|
@@ -348,7 +349,7 @@ | |||||
Geometry = strawberry.scalar( | ||||||
NewType("Geometry", geos.GEOSGeometry), | ||||||
serialize=lambda v: v.tuple if isinstance(v, geos.GEOSGeometry) else v, # type: ignore | ||||||
parse_value=lambda v: geos.GeometryCollection, | ||||||
parse_value=lambda v: geos.GEOSGeometry(v), | ||||||
description=( | ||||||
"An arbitrary geographical object. One of Point, " | ||||||
"LineString, LinearRing, Polygon, MultiPoint, MultiLineString, MultiPolygon." | ||||||
|
@@ -557,9 +558,11 @@ | |||||
): | ||||||
if using_old_filters: | ||||||
field_type = filters.FilterLookup[field_type] | ||||||
elif type(field_type) is ScalarWrapper and field_type._scalar_definition.name in ("Point", "LineString", "LinearRing", "Polygon", "MultiPoint", "MultilineString", "MultiPolygon", "Geometry"): | ||||||
|
elif type(field_type) is ScalarWrapper and field_type._scalar_definition.name in ("Point", "LineString", "LinearRing", "Polygon", "MultiPoint", "MultilineString", "MultiPolygon", "Geometry"): | |
elif isinstance(field_type, ScalarWrapper) and field_type._scalar_definition.name in ("Point", "LineString", "LinearRing", "Polygon", "MultiPoint", "MultilineString", "MultiPolygon", "Geometry"): |
Check failure on line 565 in strawberry_django/fields/types.py
GitHub Actions / Typing
Argument of type "Any | type[bool] | ScalarWrapper" cannot be assigned to parameter "key" of type "type[ID] | type[bool] | type[date] | type[datetime] | type[time] | type[Decimal] | type[float] | type[int] | type[str] | type[UUID]" in function "get"
Type "Any | type[bool] | ScalarWrapper" is not assignable to type "type[ID] | type[bool] | type[date] | type[datetime] | type[time] | type[Decimal] | type[float] | type[int] | type[str] | type[UUID]"
Type "ScalarWrapper" is not assignable to type "type[ID] | type[bool] | type[date] | type[datetime] | type[time] | type[Decimal] | type[float] | type[int] | type[str] | type[UUID]"
Type "ScalarWrapper" is not assignable to type "type[ID]"
Type "ScalarWrapper" is not assignable to type "type[bool]"
Type "ScalarWrapper" is not assignable to type "type[date]"
Type "ScalarWrapper" is not assignable to type "type[datetime]"
Type "ScalarWrapper" is not assignable to type "type[time]"
Type "ScalarWrapper" is not assignable to type "type[Decimal]"
... (reportArgumentType)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider dynamically generating the geometry fields to reduce code duplication.
Consider reducing the repetitive field definitions by generating the geometry fields dynamically. For example, you can define a list of method names and then use a helper to build your fields. This will reduce the nesting and repetitive code without changing functionality. For instance:
This refactoring maintains all functionality while reducing the duplication and nesting in your class definition.