Skip to content

Commit

Permalink
Merge branch 'feature/use-only-departments-with-unit-organization-fil…
Browse files Browse the repository at this point in the history
…ter' into feature/unit-add-geometry3d
  • Loading branch information
juuso-j committed Jul 4, 2024
2 parents 73801a4 + c66f56f commit c2f5bbd
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 @@ -939,8 +939,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 @@ -950,16 +960,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 c2f5bbd

Please sign in to comment.