Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class HasValueEmptyFilterSupport:
def get_in_array_empty_value(self, field: "Field") -> Any:
"""
Returns a sigle value or a list of values to use for filtering empty values in
Returns a single value or a list of values to use for filtering empty values in
an arrays with the `get_jsonb_has_any_in_value_filter_expr`. See
`get_in_array_empty_query` and `get_all_empty_query` for more details
on how this value is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

from django.contrib.postgres.fields import ArrayField, JSONField
from django.db import models
from django.db.models import Expression, F, Func, Q, QuerySet, TextField, Value
from django.db.models import Expression, F
from django.db.models import Field as DjangoField
from django.db.models import Func, Q, QuerySet, TextField, Value
from django.db.models.functions import Cast, Concat

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


class BaserowFormulaMultipleCollaboratorsType(
HasValueEmptyFilterSupport, BaserowJSONBObjectBaseType
HasValueContainsWordFilterSupport,
HasValueContainsFilterSupport,
HasValueEmptyFilterSupport,
HasValueEqualFilterSupport,
BaserowJSONBObjectBaseType,
):
type = "multiple_collaborators"
baserow_field_type = "multiple_collaborators"
can_order_by = False
can_order_by_in_array = False
can_group_by = False

def get_in_array_contains_word_query(
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
) -> OptionallyAnnotatedQ:
return get_jsonb_contains_word_filter_expr(
model_field, value, query_path="$[*].value.first_name"
)

def get_in_array_contains_query(
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
) -> OptionallyAnnotatedQ:
return get_jsonb_contains_filter_expr(
model_field, value, query_path="$[*].value.first_name"
)

def get_in_array_is_query(
self, field_name: str, value: str, model_field: DjangoField, field: "Field"
) -> OptionallyAnnotatedQ:
try:
value = [int(value)]

except (TypeError, ValueError):
return Q()

return get_jsonb_has_any_in_value_filter_expr(
model_field, value, query_path="$[*].value.id"
)

def get_in_array_empty_query(
self, field_name: str, model_field: DjangoField, field: "Field"
) -> OptionallyAnnotatedQ:
return get_jsonb_has_any_in_value_filter_expr(
model_field, [0], query_path="$[*].value.size()"
)

def get_all_empty_query(
self, field_name: str, model_field: Field, field, in_array: bool = True
) -> OptionallyAnnotatedQ:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from baserow.contrib.database.fields.registries import field_type_registry
from baserow.contrib.database.formula import (
BaserowFormulaMultipleCollaboratorsType,
BaserowFormulaNumberType,
BaserowFormulaTextType,
)
Expand Down Expand Up @@ -53,6 +54,7 @@ class HasEmptyValueViewFilterType(ViewFilterType):
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
),
]

Expand Down Expand Up @@ -121,6 +123,7 @@ class HasValueEqualViewFilterType(ComparisonHasValueFilter):
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
),
]

Expand Down Expand Up @@ -153,6 +156,7 @@ class HasValueContainsViewFilterType(ViewFilterType):
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaNumberType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
),
]

Expand Down Expand Up @@ -185,6 +189,7 @@ class HasValueContainsWordViewFilterType(ViewFilterType):
FormulaFieldType.array_of(BaserowFormulaURLType.type),
FormulaFieldType.array_of(BaserowFormulaSingleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleSelectType.type),
FormulaFieldType.array_of(BaserowFormulaMultipleCollaboratorsType.type),
),
]

Expand Down
2 changes: 2 additions & 0 deletions backend/tests/baserow/contrib/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class LookupFieldSetup:
target_field: Field
row_handler: RowHandler
view_handler: ViewHandler
extra: dict


@dataclasses.dataclass
Expand Down Expand Up @@ -253,6 +254,7 @@ def setup_linked_table_and_lookup(
lookup_field=lookup_field,
view_handler=view_handler,
model=model,
extra={},
)


Expand Down
Loading
Loading