Skip to content

Commit

Permalink
Use only departments with unit organization-filter
Browse files Browse the repository at this point in the history
Filter with unit root_departments and departments with organization-filter.
Do not auto-include department's municipalities.
  • Loading branch information
juuso-j committed Jul 3, 2024
1 parent 0f8ac32 commit c66f56f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,18 @@ def get_queryset(self):

queryset = queryset.filter(muni_sq)

if "city_as_department" in filters:
val = filters["city_as_department"].lower().strip()
if "organization" in filters or "city_as_department" in filters:
val = (
filters["organization"].lower().strip()
if "organization" in filters
else ""
)
if len(val) == 0:
val = (
filters["city_as_department"].lower().strip()
if "city_as_department" in filters
else ""
)

if len(val) > 0:
deps_uuids = val.split(",")
Expand All @@ -875,16 +885,12 @@ def get_queryset(self):
uuid.UUID(deps_uuid)
except ValueError:
raise serializers.ValidationError(
"'city_as_department' value must be a valid UUID"
"'organization' value must be a valid UUID"
)

deps = Department.objects.filter(uuid__in=deps_uuids).select_related(
"municipality"
)
munis = [d.municipality for d in deps]

queryset = queryset.filter(root_department__in=deps) | queryset.filter(
municipality__in=munis
deps = Department.objects.filter(uuid__in=deps_uuids)
queryset = queryset.filter(department__in=deps) | queryset.filter(
root_department__in=deps
)

if "provider_type" in filters:
Expand Down

0 comments on commit c66f56f

Please sign in to comment.