This commit is contained in:
@@ -2,9 +2,33 @@ from __future__ import annotations
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
from apps.jobs.services.geocoding import LocationMatchResult, resolve_cached_location
|
||||
|
||||
from .models import ProfileRevision, SearchProfile
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def resolve_profile_home_location(profile: SearchProfile) -> LocationMatchResult:
|
||||
"""Resolve a user-entered postal code without exposing coordinate fields in the UI."""
|
||||
query = profile.home_postal_code.strip()
|
||||
result = (
|
||||
resolve_cached_location(query) if query else LocationMatchResult(query=query, location=None)
|
||||
)
|
||||
location = result.location
|
||||
profile.home_municipality = location.municipality or "" if location else ""
|
||||
profile.home_latitude = location.point.latitude if location and location.point else None
|
||||
profile.home_longitude = location.point.longitude if location and location.point else None
|
||||
profile.save(
|
||||
update_fields=[
|
||||
"home_municipality",
|
||||
"home_latitude",
|
||||
"home_longitude",
|
||||
"updated_at",
|
||||
]
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def save_profile_revision(profile: SearchProfile, *, reason: str) -> ProfileRevision:
|
||||
latest = profile.revisions.order_by("-version").first()
|
||||
|
||||
Reference in New Issue
Block a user