diff --git a/backend/AUTHORS b/backend/AUTHORS deleted file mode 100644 index c5ba2ed..0000000 --- a/backend/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -http://github.com/iMerica/dj-rest-auth/contributors diff --git a/backend/LICENSE b/backend/LICENSE index 42a0292..01c7bc7 100644 --- a/backend/LICENSE +++ b/backend/LICENSE @@ -1,4 +1,10 @@ -The MIT License (MIT) +# Preface + +AdventureLog uses DjRestAuth, a Django REST Framework authentication backend for Django Rest Framework. DjRestAuth is licensed under the MIT License. + +--- + +## The MIT License (MIT) Copyright (c) 2014 iMerica https://github.com/iMerica/ diff --git a/backend/MANIFEST.in b/backend/MANIFEST.in deleted file mode 100644 index c2d4208..0000000 --- a/backend/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include AUTHORS -include LICENSE -include MANIFEST.in -include README.md -graft dj_rest_auth diff --git a/backend/server/adventures/urls.py b/backend/server/adventures/urls.py index 00e9cd4..3eec598 100644 --- a/backend/server/adventures/urls.py +++ b/backend/server/adventures/urls.py @@ -1,6 +1,6 @@ from django.urls import include, path from rest_framework.routers import DefaultRouter -from .views import AdventureViewSet, ChecklistViewSet, CollectionViewSet, NoteViewSet, StatsViewSet, GenerateDescription, ActivityTypesView, TransportationViewSet, AdventureImageViewSet +from .views import AdventureViewSet, ChecklistViewSet, CollectionViewSet, NoteViewSet, StatsViewSet, GenerateDescription, ActivityTypesView, TransportationViewSet, AdventureImageViewSet, ReverseGeocodeViewSet router = DefaultRouter() router.register(r'adventures', AdventureViewSet, basename='adventures') @@ -12,6 +12,7 @@ router.register(r'transportations', TransportationViewSet, basename='transportat router.register(r'notes', NoteViewSet, basename='notes') router.register(r'checklists', ChecklistViewSet, basename='checklists') router.register(r'images', AdventureImageViewSet, basename='images') +router.register(r'reverse-geocode', ReverseGeocodeViewSet, basename='reverse-geocode') urlpatterns = [ diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index b6a82fe..2131dff 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -1,3 +1,4 @@ +import json import uuid import requests from django.db import transaction @@ -1053,3 +1054,42 @@ class AdventureImageViewSet(viewsets.ModelViewSet): def perform_create(self, serializer): serializer.save(user_id=self.request.user) + +class ReverseGeocodeViewSet(viewsets.ViewSet): + permission_classes = [IsAuthenticated] + + def extractIsoCode(self, data): + """ + Extract the ISO code from the response data. + Returns a dictionary containing the region name, country name, and ISO code if found. + """ + iso_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] + print(iso_code) + region = Region.objects.filter(id=iso_code).first() + visited_region = VisitedRegion.objects.filter(region=region).first() + is_visited = False + if visited_region: + is_visited = True + if region: + return {"id": iso_code, "region": region.name, "country": region.country.name, "is_visited": is_visited} + return {"error": "No region found"} + + @action(detail=False, methods=['get']) + def reverse_geocode(self, request): + lat = request.query_params.get('lat', '') + lon = request.query_params.get('lon', '') + print(lat, lon) + url = f"https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat={lat}&lon={lon}" + headers = {'User-Agent': 'AdventureLog Server'} + response = requests.get(url, headers=headers) + try: + data = response.json() + except requests.exceptions.JSONDecodeError: + return Response({"error": "Invalid response from geocoding service"}, status=400) + return Response(self.extractIsoCode(data)) + diff --git a/frontend/src/lib/components/AdventureLink.svelte b/frontend/src/lib/components/AdventureLink.svelte index b1bb85f..db02e4e 100644 --- a/frontend/src/lib/components/AdventureLink.svelte +++ b/frontend/src/lib/components/AdventureLink.svelte @@ -3,7 +3,7 @@ import type { Adventure, User } from '$lib/types'; import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); - import type { ActionResult } from '@sveltejs/kit'; + import { t } from 'svelte-i18n'; import { onMount } from 'svelte'; import AdventureCard from './AdventureCard.svelte'; let modal: HTMLDialogElement; @@ -51,7 +51,7 @@
- No adventures found that can be linked to this collection. + {$t('adventures.no_linkable_adventures')}
{/if}- There are no adventures to display. Add some using the plus button at the bottom right or - try changing filters! + {$t('adventures.adventure_not_found')}
{:else}{error}
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 8e4dff1..4470ac3 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -168,3 +168,10 @@ export type Background = { author?: string; location?: string; }; + +export type ReverseGeocode = { + id: string; + region: string; + country: string; + is_visited: boolean; +}; diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index bff7010..f757517 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -101,6 +101,8 @@ "wikipedia": "Wikipedia", "add_notes": "Add notes", "warning": "Warning", + "my_adventures": "My Adventures", + "no_linkable_adventures": "No adventures found that can be linked to this collection.", "add": "Add", "save_next": "Save & Next", "end_date": "End Date", @@ -136,6 +138,7 @@ "edit_collection": "Edit Collection", "unarchive": "Unarchive", "archive": "Archive", + "no_collections_found": "No collections found to add this adventure to.", "archived_collection_message": "Collection archived successfully!", "unarchived_collection_message": "Collection unarchived successfully!", "delete_collection_success": "Collection deleted successfully!", @@ -168,6 +171,8 @@ "adventure_update_error": "Failed to update adventure", "new_adventure": "New Adventure", "basic_information": "Basic Information", + "adventure_not_found": "There are no adventures to display. Add some using the plus button at the bottom right or try changing filters!", + "no_adventures_found": "No adventures found", "activities": { "general": "General 🌍", "outdoor": "Outdoor 🏞️", diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.json index 0c05a4b..fef587c 100644 --- a/frontend/src/locales/es.json +++ b/frontend/src/locales/es.json @@ -191,7 +191,12 @@ "warning": "Advertencia", "wiki_desc": "Extrae un extracto de un artículo de Wikipedia que coincide con el nombre de la aventura.", "wikipedia": "Wikipedia", - "add_an_activity": "Agregar una actividad" + "add_an_activity": "Agregar una actividad", + "adventure_not_found": "No hay aventuras que mostrar. \n¡Agregue algunos usando el botón más en la parte inferior derecha o intente cambiar los filtros!", + "no_adventures_found": "No se encontraron aventuras", + "no_collections_found": "No se encontraron colecciones para agregar esta aventura.", + "my_adventures": "mis aventuras", + "no_linkable_adventures": "No se encontraron aventuras que puedan vincularse a esta colección." }, "worldtravel": { "all": "Todo", diff --git a/frontend/src/routes/collections/archived/+page.svelte b/frontend/src/routes/collections/archived/+page.svelte index 4179f3c..9f0222c 100644 --- a/frontend/src/routes/collections/archived/+page.svelte +++ b/frontend/src/routes/collections/archived/+page.svelte @@ -2,6 +2,7 @@ import CollectionCard from '$lib/components/CollectionCard.svelte'; import NotFound from '$lib/components/NotFound.svelte'; import type { Collection } from '$lib/types'; + import { t } from 'svelte-i18n'; export let data: any; console.log(data); @@ -16,7 +17,7 @@