Skip to content

Commit

Permalink
fix: [website] Separate cases when search by UUID objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Oct 16, 2024
1 parent 427680e commit dec93bf
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions website/web/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from uuid import UUID

from flask import abort
from flask import Blueprint
from flask import flash
Expand Down Expand Up @@ -502,13 +504,25 @@ def list_sightings() -> str:
sighting_query = request.args.get("query", "")
sightings = Sighting.query
if sighting_query:
sightings = sightings.filter(
or_(
Sighting.uuid == sighting_query,
Sighting.type == sighting_query,
Sighting.author.has(name=sighting_query),
try:
uuid_obj = UUID(sighting_query)
except Exception:
uuid_obj = None
if uuid_obj:
sightings = sightings.filter(
or_(
Sighting.uuid == uuid_obj,
Sighting.type == sighting_query,
Sighting.author.has(login=sighting_query),
)
)
else:
sightings = sightings.filter(
or_(
Sighting.type == sighting_query,
Sighting.author.has(login=sighting_query),
)
)
)
sightings = sightings.order_by(Sighting.creation_timestamp.desc())
page, per_page, offset = get_page_args(
page_parameter="page", per_page_parameter="per_page"
Expand Down

0 comments on commit dec93bf

Please sign in to comment.