1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 22:39:36 +02:00

Update entrypoint

This commit is contained in:
Sean Morley 2024-09-11 09:31:25 -04:00
parent 9ba5b25ab5
commit bd6d60d24d
5 changed files with 10 additions and 11 deletions

View file

@ -34,7 +34,7 @@ EOF
fi fi
# Sync the countries and world travel regions # Sync the countries and world travel regions
python manage.py worldtravel-seed --force python manage.py download-countries
# Start Django server # Start Django server
python manage.py runserver 0.0.0.0:8000 python manage.py runserver 0.0.0.0:8000

View file

@ -1,19 +1,17 @@
import os import os
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
import requests import requests
from worldtravel.models import Country, Region from worldtravel.models import Country, Region
from django.db import transaction from django.db import transaction
from django.contrib.gis.geos import GEOSGeometry, Polygon, MultiPolygon
from django.contrib.gis.geos.error import GEOSException
import json import json
from django.conf import settings from django.conf import settings
media_root = settings.MEDIA_ROOT media_root = settings.MEDIA_ROOT
def saveCountryFlag(country_code): def saveCountryFlag(country_code):
# For standards, use the lowercase country_code
country_code = country_code.lower()
flags_dir = os.path.join(media_root, 'flags') flags_dir = os.path.join(media_root, 'flags')
# Check if the flags directory exists, if not, create it # 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') print(f'Flag for {country_code} already exists')
return 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: if res.status_code == 200:
with open(flag_path, 'wb') as f: with open(flag_path, 'wb') as f:
f.write(res.content) f.write(res.content)

View file

@ -16,13 +16,13 @@ class CountrySerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Country model = Country
fields = '__all__' # Serialize all fields of the Adventure model 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 RegionSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Region model = Region
fields = '__all__' # Serialize all fields of the Adventure model 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 VisitedRegionSerializer(serializers.ModelSerializer):
class Meta: class Meta:

View file

@ -21,7 +21,7 @@
</figure> </figure>
<div class="card-body"> <div class="card-body">
<h2 class="card-title overflow-ellipsis">{country.name}</h2> <h2 class="card-title overflow-ellipsis">{country.name}</h2>
<div class="badge badge-primary">{continentCodeToString(country.continent)}</div> <div class="badge badge-primary">{country.subregion}</div>
<div class="card-actions justify-end"> <div class="card-actions justify-end">
<!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> --> <!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> -->
<button class="btn btn-primary" on:click={nav}>Open</button> <button class="btn btn-primary" on:click={nav}>Open</button>

View file

@ -39,15 +39,16 @@ export type Country = {
id: number; id: number;
name: string; name: string;
country_code: string; country_code: string;
continent: string; subregion: string;
flag_url: string; flag_url: string;
}; };
export type Region = { export type Region = {
id: number; id: number;
name: string; name: string;
name_en?: string;
country: number; country: number;
latitude: number;
longitude: number;
}; };
export type VisitedRegion = { export type VisitedRegion = {