Skip to content
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

Add backend logic for column filtering #35846

Merged
merged 19 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
23746c5
CaseSearchES xpath_query does not support ends-with, only starts-with
biyeun Feb 25, 2025
fc65bc9
empty vs null is not supported in CaseSearchES
biyeun Feb 25, 2025
2f96aa1
make separate lte, gte match type choices
biyeun Feb 25, 2025
3986d67
move empty, missing match types to own category applying to all data …
biyeun Feb 25, 2025
a58d11d
sort DataTypes into filter categories so that correct filter choices …
biyeun Feb 25, 2025
a60b119
add validation utility (for forms) for data_type match_type combinations
biyeun Feb 25, 2025
d4ff670
add filter_query utility to BulkEditColumnFilters
biyeun Feb 25, 2025
cb26c25
add utility for retrieving xpath_expression for BulkEditColumnFilter
biyeun Feb 25, 2025
df53fe4
add utility to session for adding column filters
biyeun Feb 25, 2025
7073f98
add unique ids to reorderable BulkEdit Columns and Filters
biyeun Feb 25, 2025
c2d86c2
add a migration for all of the most recent model updates
biyeun Feb 25, 2025
f96a28d
add utility to session for reordering column filters
biyeun Feb 25, 2025
a6e45ff
add utility for getting the queryset from the session
biyeun Feb 25, 2025
7b28932
update table view to use session.get_queryset()
biyeun Feb 25, 2025
a02022a
replacing with more fake email (whoops)
biyeun Feb 25, 2025
312c2cd
update docstring
biyeun Feb 26, 2025
234198e
update quote style for consistency
biyeun Feb 26, 2025
6550776
update tests for clarity
biyeun Feb 26, 2025
685294b
Merge branch 'master' of github.com:dimagi/commcare-hq into bmb/dc/fi…
biyeun Feb 26, 2025
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
12 changes: 12 additions & 0 deletions corehq/apps/data_cleaning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def add_column_filter(self, prop_id, data_type, match_type, value=None):
value=value,
)

def reorder_column_filters(self, filter_ids):
"""
This updates the order of column filters for this session
:param filter_ids: list of uuids matching filter_id field of BulkEditColumnFilters
"""
if len(filter_ids) != self.column_filters.count():
raise ValueError("the lengths of column_ids and available column filters do not match")
for index, filter_id in enumerate(filter_ids):
column_filter = self.column_filters.get(filter_id=filter_id)
column_filter.index = index
column_filter.save()


class DataType:
TEXT = 'text'
Expand Down
25 changes: 25 additions & 0 deletions corehq/apps/data_cleaning/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,28 @@ def test_add_column_filters(self):
for index, prop_id in enumerate(['watered_on', 'name', 'num_leaves', 'pot_type', 'height_cm']):
self.assertEqual(column_filters[index].prop_id, prop_id)
self.assertEqual(column_filters[index].index, index)

def test_reorder_column_filters(self):
session = BulkEditSession.new_case_session(self.django_user, self.domain_name, self.case_type)
session.add_column_filter('watered_on', DataType.DATE, FilterMatchType.IS_NOT_MISSING)
session.add_column_filter('name', DataType.TEXT, FilterMatchType.PHONETIC, "lowkey")
session.add_column_filter('num_leaves', DataType.INTEGER, FilterMatchType.GREATER_THAN, "2")
session.add_column_filter('pot_type', DataType.DATE, FilterMatchType.IS_EMPTY)
session.add_column_filter('height_cm', DataType.DECIMAL, FilterMatchType.LESS_THAN_EQUAL, "11.0")
column_filters = session.column_filters.all()
new_order = [column_filters[1].filter_id, column_filters[2].filter_id]
with self.assertRaises(ValueError):
session.reorder_column_filters(new_order)
new_order_final = [
column_filters[1].filter_id,
column_filters[0].filter_id,
column_filters[2].filter_id,
column_filters[4].filter_id,
column_filters[3].filter_id,
]
session.reorder_column_filters(new_order_final)
reordered_prop_ids = [c.prop_id for c in session.column_filters.all()]
self.assertEqual(
reordered_prop_ids,
['name', 'watered_on', 'num_leaves', 'height_cm', 'pot_type']
)