Fix more vars, and re-worked Timestamp problems
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import secrets
|
import secrets
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from google.cloud.firestore_v1 import GeoPoint
|
from datetime import datetime
|
||||||
|
from google.cloud.firestore_v1 import GeoPoint, DocumentReference
|
||||||
|
|
||||||
from shared.firebase import get_db
|
from shared.firebase import get_db
|
||||||
from shared.exceptions import NotFoundError
|
from shared.exceptions import NotFoundError
|
||||||
@@ -39,14 +40,15 @@ def _ensure_unique_serial(db) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _convert_firestore_value(val):
|
def _convert_firestore_value(val):
|
||||||
"""Convert Firestore-specific types (Timestamp, GeoPoint) to strings."""
|
"""Convert Firestore-specific types (Timestamp, GeoPoint, DocumentReference) to strings."""
|
||||||
if hasattr(val, "seconds") and hasattr(val, "nanos"):
|
if isinstance(val, datetime):
|
||||||
# Firestore Timestamp → ISO string
|
# Firestore DatetimeWithNanoseconds is a datetime subclass
|
||||||
from datetime import datetime, timezone
|
return val.strftime("%d %B %Y at %H:%M:%S UTC%z")
|
||||||
dt = datetime.fromtimestamp(val.seconds + val.nanos / 1e9, tz=timezone.utc)
|
|
||||||
return dt.strftime("%d %B %Y at %H:%M:%S UTC")
|
|
||||||
if isinstance(val, GeoPoint):
|
if isinstance(val, GeoPoint):
|
||||||
return f"{val.latitude}° N, {val.longitude}° E"
|
return f"{val.latitude}° N, {val.longitude}° E"
|
||||||
|
if isinstance(val, DocumentReference):
|
||||||
|
# Store the document path (e.g. "users/abc123")
|
||||||
|
return val.path
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user