Skip to content

Commit

Permalink
Merge pull request #1984 from projectcaluma/feat-add-modified-at-filters
Browse files Browse the repository at this point in the history
feat(filters): add filters for modified_at
  • Loading branch information
winged authored Apr 13, 2023
2 parents 2317262 + 16fdb73 commit fcc5bd3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
10 changes: 10 additions & 0 deletions caluma/caluma_core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ class BaseFilterSet(GrapheneFilterSetMixin, FilterSet):
lookup_expr="gte",
label="Only return entries created at or after the given DateTime (inclusive)",
)
modified_before = DateTimeFilter(
field_name="modified_at",
lookup_expr="lt",
label="Only return entries modified before the given DateTime (exclusive)",
)
modified_after = DateTimeFilter(
field_name="modified_at",
lookup_expr="gte",
label="Only return entries modified at or after the given DateTime (inclusive)",
)


class JSONLookupMode(Enum):
Expand Down
30 changes: 23 additions & 7 deletions caluma/caluma_workflow/tests/test_date_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,53 @@
[
([{"createdBefore": "2020-04-21T00:00:00Z"}], [20]),
([{"createdBefore": "2020-04-22T00:00:00Z"}], [20, 21]),
([{"createdAfter": "2020-04-21T00:00:00Z"}], [21, 22, 23, 24]),
([{"createdAfter": "2020-04-22T00:00:00Z"}], [22, 23, 24]),
([{"createdAfter": "2020-04-21T00:00:00Z"}], [21, 22, 23, 24, 27]),
([{"createdAfter": "2020-04-22T00:00:00Z"}], [22, 23, 24, 27]),
# combinations
(
[
{"createdBefore": "2020-04-23T00:00:00Z"},
{"createdAfter": "2020-04-22T00:00:00Z"},
{"createdBefore": "2020-04-23T00:00:00Z"},
],
[22],
),
(
[
{"createdBefore": "2020-04-24T00:00:00Z"},
{"createdAfter": "2020-04-21T00:00:00Z"},
{"createdBefore": "2020-04-24T00:00:00Z"},
],
[21, 22, 23],
),
(
[
{"modifiedAfter": "2020-05-21T00:00:00Z"},
{"modifiedBefore": "2020-05-22T00:00:00Z"},
],
[20, 21, 22, 23, 24],
),
(
[
{"modifiedAfter": "2020-05-27T00:00:00Z"},
],
[27],
),
],
)
@pytest.mark.freeze_time("2020-05-21")
def test_before_after_filters(
db, case_factory, schema_executor, filter, expected_result
db, case_factory, schema_executor, filter, expected_result, freezer
):
# thanks, auto_now_add!
cases = case_factory.create_batch(5)
case_dict = {}
for day, case in zip(range(20, 25), cases):
case_dict[day] = case.pk
case.created_at = f"2020-04-{day} 00:00:00Z"
case.meta = {"test_created": day}
case.save()

# create another case at a different point in time to test modified_at filter
freezer.move_to("2020-05-27")
case_factory(meta={"test_created": 27})

query = """
query Q($filter: [CaseFilterSetType]) {
allCases(filter: $filter) {
Expand Down
24 changes: 24 additions & 0 deletions caluma/tests/__snapshots__/test_schema.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down Expand Up @@ -213,6 +215,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down Expand Up @@ -265,6 +269,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
questions: [ID]
Expand Down Expand Up @@ -508,6 +514,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
id: ID
Expand Down Expand Up @@ -923,6 +931,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
rootDocument: ID
Expand Down Expand Up @@ -1220,6 +1230,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
invert: Boolean
}

Expand Down Expand Up @@ -1295,6 +1307,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down Expand Up @@ -1842,6 +1856,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down Expand Up @@ -1959,6 +1975,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
excludeForms: [ID]
Expand Down Expand Up @@ -3254,6 +3272,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down Expand Up @@ -3432,6 +3452,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
id: ID
Expand Down Expand Up @@ -3527,6 +3549,8 @@
modifiedByGroup: String
createdBefore: DateTime
createdAfter: DateTime
modifiedBefore: DateTime
modifiedAfter: DateTime
metaHasKey: String
metaValue: [JSONValueFilterType]
search: String
Expand Down

0 comments on commit fcc5bd3

Please sign in to comment.