From bd6d60d24d79aca36b0a0a5e41ad89f893b228e9 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 11 Sep 2024 09:31:25 -0400 Subject: [PATCH] Update entrypoint --- backend/entrypoint.sh | 2 +- .../worldtravel/management/commands/download-countries.py | 8 +++----- backend/server/worldtravel/serializers.py | 4 ++-- frontend/src/lib/components/CountryCard.svelte | 2 +- frontend/src/lib/types.ts | 5 +++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index 269a5aa..cbb40db 100644 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -34,7 +34,7 @@ EOF fi # Sync the countries and world travel regions -python manage.py worldtravel-seed --force +python manage.py download-countries # Start Django server python manage.py runserver 0.0.0.0:8000 diff --git a/backend/server/worldtravel/management/commands/download-countries.py b/backend/server/worldtravel/management/commands/download-countries.py index aff0f2e..d0929a0 100644 --- a/backend/server/worldtravel/management/commands/download-countries.py +++ b/backend/server/worldtravel/management/commands/download-countries.py @@ -1,19 +1,17 @@ import os from django.core.management.base import BaseCommand -from django.contrib.auth import get_user_model import requests from worldtravel.models import Country, Region from django.db import transaction -from django.contrib.gis.geos import GEOSGeometry, Polygon, MultiPolygon -from django.contrib.gis.geos.error import GEOSException import json from django.conf import settings media_root = settings.MEDIA_ROOT - def saveCountryFlag(country_code): + # For standards, use the lowercase country_code + country_code = country_code.lower() flags_dir = os.path.join(media_root, 'flags') # Check if the flags directory exists, if not, create it @@ -26,7 +24,7 @@ def saveCountryFlag(country_code): print(f'Flag for {country_code} already exists') return - res = requests.get(f'https://flagcdn.com/h240/{country_code.lower()}.png'.lower()) + res = requests.get(f'https://flagcdn.com/h240/{country_code}.png'.lower()) if res.status_code == 200: with open(flag_path, 'wb') as f: f.write(res.content) diff --git a/backend/server/worldtravel/serializers.py b/backend/server/worldtravel/serializers.py index 6cb9c46..4e529c5 100644 --- a/backend/server/worldtravel/serializers.py +++ b/backend/server/worldtravel/serializers.py @@ -16,13 +16,13 @@ class CountrySerializer(serializers.ModelSerializer): class Meta: model = Country fields = '__all__' # Serialize all fields of the Adventure model - read_only_fields = ['id', 'name', 'country_code', 'continent', 'flag_url'] + read_only_fields = ['id', 'name', 'country_code', 'subregion', 'flag_url'] class RegionSerializer(serializers.ModelSerializer): class Meta: model = Region fields = '__all__' # Serialize all fields of the Adventure model - read_only_fields = ['id', 'name', 'country', 'name_en', 'geometry'] + read_only_fields = ['id', 'name', 'country', 'longitude', 'latitude'] class VisitedRegionSerializer(serializers.ModelSerializer): class Meta: diff --git a/frontend/src/lib/components/CountryCard.svelte b/frontend/src/lib/components/CountryCard.svelte index 0fbdace..95fbde8 100644 --- a/frontend/src/lib/components/CountryCard.svelte +++ b/frontend/src/lib/components/CountryCard.svelte @@ -21,7 +21,7 @@

{country.name}

-
{continentCodeToString(country.continent)}
+
{country.subregion}
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 5e5060a..8fade57 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -39,15 +39,16 @@ export type Country = { id: number; name: string; country_code: string; - continent: string; + subregion: string; flag_url: string; }; export type Region = { id: number; name: string; - name_en?: string; country: number; + latitude: number; + longitude: number; }; export type VisitedRegion = {