Skip to content

Commit

Permalink
Merge pull request #95 from gm3dmo/w44
Browse files Browse the repository at this point in the history
w44
  • Loading branch information
gm3dmo authored Nov 4, 2023
2 parents e37c3bc + 8093e00 commit 03834b8
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 342 deletions.
289 changes: 0 additions & 289 deletions cmp/migrations/0001_initial.py

This file was deleted.

23 changes: 0 additions & 23 deletions cmp/migrations/0002_alter_cemetery_country.py

This file was deleted.

10 changes: 5 additions & 5 deletions cmp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class PowCamp(models.Model):
name = models.CharField(max_length=255, unique=True, default='')
nearestCity = models.CharField(max_length=255, unique=False, default='')
notes = models.CharField(max_length=255, unique=False, default='')
wartimeCountry = models.ForeignKey('Country', on_delete=models.CASCADE)
presentCountry = models.CharField(max_length=255, unique=False, default='')
latitude = models.FloatField() # latitude
longitude = models.FloatField() # longitude
presentCountry = models.ForeignKey('Country', to_field='CountryNumber', on_delete=models.CASCADE, related_name='powcamps')
wartimeCountry = models.CharField(max_length=255, unique=False, default='')
latitude = models.CharField(max_length=255, unique=False, default='')
longitude = models.CharField(max_length=255, unique=False, default='')

def __str__(self):
return self.name
Expand Down Expand Up @@ -122,7 +122,7 @@ class Country(models.Model):
Alpha2 = models.CharField(max_length=2, unique=True, default='')
Alpha3 = models.CharField(max_length=3, unique=True, default='')
CountryNumber = models.CharField(max_length=3, unique=True, default='')
Flag = models.CharField(max_length=255, default='')
Flag = models.CharField(max_length=255, default='')

def __str__(self):
return self.name
Expand Down
5 changes: 1 addition & 4 deletions cmp/static/cmp/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
margin-top: 5%;
font-size: 18px;
}
h1 {
color: #8B0000;
}
h2 {
h1, h3, h3, h4, h5, h6 {
color: #8B0000;
}
.input-text {
Expand Down
1 change: 1 addition & 0 deletions cmp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def edit_countries(request, country_id):
return HttpResponse("Country Added")
return render(request, "cmp/edit-countries.html", {"form": form})


def detail_countries(request, country_id):
# get or return a 404
country = get_object_or_404(Country, pk=country_id)
Expand Down
2 changes: 1 addition & 1 deletion railway.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py runscript add-flags-to-countries && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
Expand Down
30 changes: 30 additions & 0 deletions scripts/add-flags-to-countries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

def run():

import sys
import urllib3
import csv
from cmp.models import Country

ref_data_url = "https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.csv"
http = urllib3.PoolManager()
r = http.request('GET', ref_data_url)
print(r.status)
# load the response into a csv dictionary reader
reader = csv.DictReader(r.data.decode('utf-8').splitlines())

# create a dictionary from the reader with key ccna2 and value flag
flags = {row['cca2']: row['flag'] for row in reader}

print(flags['GB'])

# for every country in the database, add the flag if the country is in the dictionary
for country in Country.objects.all():
if country.Alpha2 in flags:
country.Flag = flags[country.Alpha2]
country.save()
print(f"""{country.name} {country.Alpha2} {country.Flag}""")
else:
print(f"""{country.name} {country.Alpha2} no flag""")


Loading

0 comments on commit 03834b8

Please sign in to comment.