Skip to content

Commit b368c4f

Browse files
multiple collaborators lookup filters (baserow#4086)
* multiple collaborators lookup filters --------- Co-authored-by: Cezary Statkiewicz <cezary@baserow.io>
1 parent 4569825 commit b368c4f

11 files changed

Lines changed: 612 additions & 54 deletions

File tree

backend/src/baserow/contrib/database/fields/filter_support/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class HasValueEmptyFilterSupport:
3131
def get_in_array_empty_value(self, field: "Field") -> Any:
3232
"""
33-
Returns a sigle value or a list of values to use for filtering empty values in
33+
Returns a single value or a list of values to use for filtering empty values in
3434
an arrays with the `get_jsonb_has_any_in_value_filter_expr`. See
3535
`get_in_array_empty_query` and `get_all_empty_query` for more details
3636
on how this value is used.

backend/src/baserow/contrib/database/formula/types/formula_types.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
from django.contrib.postgres.fields import ArrayField, JSONField
88
from django.db import models
9-
from django.db.models import Expression, F, Func, Q, QuerySet, TextField, Value
9+
from django.db.models import Expression, F
10+
from django.db.models import Field as DjangoField
11+
from django.db.models import Func, Q, QuerySet, TextField, Value
1012
from django.db.models.functions import Cast, Concat
1113

1214
from dateutil import parser
@@ -1694,14 +1696,52 @@ def contains_word_query(self, field_name, value, model_field, field):
16941696

16951697

16961698
class BaserowFormulaMultipleCollaboratorsType(
1697-
HasValueEmptyFilterSupport, BaserowJSONBObjectBaseType
1699+
HasValueContainsWordFilterSupport,
1700+
HasValueContainsFilterSupport,
1701+
HasValueEmptyFilterSupport,
1702+
HasValueEqualFilterSupport,
1703+
BaserowJSONBObjectBaseType,
16981704
):
16991705
type = "multiple_collaborators"
17001706
baserow_field_type = "multiple_collaborators"
17011707
can_order_by = False
17021708
can_order_by_in_array = False
17031709
can_group_by = False
17041710

1711+
def get_in_array_contains_word_query(
1712+
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
1713+
) -> OptionallyAnnotatedQ:
1714+
return get_jsonb_contains_word_filter_expr(
1715+
model_field, value, query_path="$[*].value.first_name"
1716+
)
1717+
1718+
def get_in_array_contains_query(
1719+
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
1720+
) -> OptionallyAnnotatedQ:
1721+
return get_jsonb_contains_filter_expr(
1722+
model_field, value, query_path="$[*].value.first_name"
1723+
)
1724+
1725+
def get_in_array_is_query(
1726+
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
1727+
) -> OptionallyAnnotatedQ:
1728+
try:
1729+
value = [int(value)]
1730+
1731+
except (TypeError, ValueError):
1732+
return Q()
1733+
1734+
return get_jsonb_has_any_in_value_filter_expr(
1735+
model_field, value, query_path="$[*].value.id"
1736+
)
1737+
1738+
def get_in_array_empty_query(
1739+
self, field_name: str, model_field: DjangoField, field: "Field"
1740+
) -> OptionallyAnnotatedQ:
1741+
return get_jsonb_has_any_in_value_filter_expr(
1742+
model_field, [0], query_path="$[*].value.size()"
1743+
)
1744+
17051745
def get_all_empty_query(
17061746
self, field_name: str, model_field: Field, field, in_array: bool = True
17071747
) -> OptionallyAnnotatedQ:

backend/src/baserow/contrib/database/views/array_view_filters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
from baserow.contrib.database.fields.registries import field_type_registry
2020
from baserow.contrib.database.formula import (
21+
BaserowFormulaMultipleCollaboratorsType,
2122
BaserowFormulaNumberType,
2223
BaserowFormulaTextType,
2324
)
@@ -53,6 +54,7 @@ class HasEmptyValueViewFilterType(ViewFilterType):
5354
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
5455
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
5556
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
57+
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
5658
),
5759
]
5860

@@ -121,6 +123,7 @@ class HasValueEqualViewFilterType(ComparisonHasValueFilter):
121123
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
122124
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
123125
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
126+
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
124127
),
125128
]
126129

@@ -153,6 +156,7 @@ class HasValueContainsViewFilterType(ViewFilterType):
153156
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
154157
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
155158
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
159+
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
156160
),
157161
]
158162

@@ -185,6 +189,7 @@ class HasValueContainsWordViewFilterType(ViewFilterType):
185189
FormulaFieldType.array_of(BaserowFormulaURLType.type),
186190
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
187191
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
192+
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
188193
),
189194
]
190195

backend/tests/baserow/contrib/database/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class LookupFieldSetup:
7474
target_field: Field
7575
row_handler: RowHandler
7676
view_handler: ViewHandler
77+
extra: dict
7778

7879

7980
@dataclasses.dataclass
@@ -253,6 +254,7 @@ def setup_linked_table_and_lookup(
253254
lookup_field=lookup_field,
254255
view_handler=view_handler,
255256
model=model,
257+
extra={},
256258
)
257259

258260

0 commit comments

Comments
 (0)