Skip to content

Commit

Permalink
Added filter_facilities_with_pending_updates method to FacilityFilter…
Browse files Browse the repository at this point in the history
… class in facility_filters.py
  • Loading branch information
ertush committed Aug 8, 2024
1 parent 9fd5483 commit 3683a6f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions facilities/filters/facility_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ def filter_approved_facilities(self, qs, name, value):
return qs.filter(Q(approved=True))
else:
return qs.filter(Q(approved=None) | Q(rejected=True))

def filter_facilities_with_pending_updates(self, qs, name, value):

if value in TRUTH_NESS:
facilities_pending_updates = qs.filter(has_edits=True)

facilities_latest_updates_ids = [f.id for f in facilities_pending_updates if f.latest_update is None]

return facilities_pending_updates.exclude(id__in=facilities_latest_updates_ids)

def filter_unpublished_facilities_national_level(self, qs, name, value):
"""
Expand Down Expand Up @@ -561,6 +570,8 @@ def filter_number_cots(self, qs, name, value):
method='filter_incomplete_facilities')
to_publish = django_filters.CharFilter(
method='filter_unpublished_facilities_national_level')
have_updates = django_filters.CharFilter(
method='filter_facilities_with_pending_updates')
approved_national_level = django_filters.TypedChoiceFilter(
choices=BOOLEAN_CHOICES,
coerce=strtobool)
Expand Down

0 comments on commit 3683a6f

Please sign in to comment.