Skip to content

Commit

Permalink
Add display_name to ReverseGeocode response and update AdventureModal
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 committed Nov 1, 2024
1 parent 25ed72a commit a7a4922
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
22 changes: 21 additions & 1 deletion backend/server/adventures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,19 +1084,39 @@ def extractIsoCode(self, data):
Returns a dictionary containing the region name, country name, and ISO code if found.
"""
iso_code = None
town = None
city = None
county = None
display_name = None
country_code = None
if 'address' in data.keys():
keys = data['address'].keys()
for key in keys:
if key.find("ISO") != -1:
iso_code = data['address'][key]
if 'town' in keys:
town = data['address']['town']
if 'county' in keys:
county = data['address']['county']
if 'city' in keys:
city = data['address']['city']
print(iso_code)
region = Region.objects.filter(id=iso_code).first()
visited_region = VisitedRegion.objects.filter(region=region).first()
is_visited = False
country_code = iso_code[:2]

if city:
display_name = f"{city}, {region.name}, {country_code}"
elif town and region.name:
display_name = f"{town}, {region.name}, {country_code}"
elif county and region.name:
display_name = f"{county}, {region.name}, {country_code}"

if visited_region:
is_visited = True
if region:
return {"id": iso_code, "region": region.name, "country": region.country.name, "is_visited": is_visited}
return {"id": iso_code, "region": region.name, "country": region.country.name, "is_visited": is_visited, "display_name": display_name}
return {"error": "No region found"}

@action(detail=False, methods=['get'])
Expand Down
14 changes: 0 additions & 14 deletions docker-compose-traefik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ services:
- "traefik.http.routers.adventurelog.tls=true"
- "traefik.http.routers.adventurelog.tls.certresolver=letsencrypt"

nginx:
image: nginx:latest
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.entrypoints=websecure"
- "traefik.http.routers.nginx.rule=Host(`yourdomain.com`) && PathPrefix(`/media`)" # Replace with your domain
- "traefik.http.routers.nginx.tls=true"
- "traefik.http.routers.nginx.tls.certresolver=letsencrypt"
- "traefik.http.middlewares.nginx-stripprefix.stripprefix.prefixes=/media"
- "traefik.http.routers.nginx.middlewares=nginx-stripprefix"
volumes:
- adventurelog-media:/usr/share/nginx/html

server:
image: ghcr.io/seanmorley15/adventurelog-backend:latest
restart: unless-stopped
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/components/AdventureModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@
markers = [];
}
$: {
if (
reverseGeocodePlace?.display_name &&
adventure.location != reverseGeocodePlace.display_name
) {
adventure.location = reverseGeocodePlace.display_name;
}
}
let imageSearch: string = adventure.name || '';
async function removeImage(id: string) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,5 @@ export type ReverseGeocode = {
region: string;
country: string;
is_visited: boolean;
display_name: string;
};

0 comments on commit a7a4922

Please sign in to comment.