From 7426061719a2c88fa8e96aed19c48535b5e2c76b Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Thu, 27 May 2021 22:48:50 +0200
Subject: [PATCH] Refactoring: vaccination

---
 .../blueprints/data_owid/owid_model.py        |  5 +-
 .../blueprints/data_owid/owid_views.py        |  8 +--
 .../all/owid_continent_all_table.html         |  2 +-
 .../country/all/owid_country_all_table.html   |  6 +-
 .../owid/owid_data/owid_data_table.html       | 72 +++++++++----------
 5 files changed, 46 insertions(+), 47 deletions(-)

diff --git a/src/flask_covid19/blueprints/data_owid/owid_model.py b/src/flask_covid19/blueprints/data_owid/owid_model.py
index f20afa2e..217038ae 100644
--- a/src/flask_covid19/blueprints/data_owid/owid_model.py
+++ b/src/flask_covid19/blueprints/data_owid/owid_model.py
@@ -108,11 +108,11 @@ class OwidCountry(BlueprintLocation):
 
     @classmethod
     def get_countries_for_continent(cls, owid_continent_one: OwidContinent, page: int):
-        return db.session.query(cls).filter(cls.continent == owid_continent_one).paginate(page, per_page=ITEMS_PER_PAGE)
+        return db.session.query(cls).filter(cls.location_group == owid_continent_one).paginate(page, per_page=ITEMS_PER_PAGE)
 
     @classmethod
     def get_all_countries_for_continent(cls, owid_continent_one: OwidContinent):
-        return db.session.query(cls).filter(cls.continent == owid_continent_one).all()
+        return db.session.query(cls).filter(cls.location_group == owid_continent_one).all()
 
     @classmethod
     def find_by_iso_code_and_location(cls, iso_code, location):
@@ -211,7 +211,6 @@ class OwidData(BlueprintFactTable):
     @classmethod
     def get_by_location(cls, location: OwidCountry, page: int):
         return cls.__query_by_location(location) \
-            .order_by(cls.date_reported.datum.desc())\
             .paginate(page, per_page=ITEMS_PER_PAGE)
 
     @classmethod
diff --git a/src/flask_covid19/blueprints/data_owid/owid_views.py b/src/flask_covid19/blueprints/data_owid/owid_views.py
index a8735e0c..3a10e796 100644
--- a/src/flask_covid19/blueprints/data_owid/owid_views.py
+++ b/src/flask_covid19/blueprints/data_owid/owid_views.py
@@ -217,9 +217,9 @@ def url_owid_continent_all(page: int = 1):
 def url_owid_continent_one(continent_id: int, page: int = 1):
     owid_continent_one = OwidContinent.get_by_id(continent_id)
     page_info = WebPageContent(
-        "continent: " + owid_continent_one.region,
+        "continent: " + owid_continent_one.location_group,
         'OWID',
-        "countries for OWID continent " + owid_continent_one.region + " "
+        "countries for OWID continent " + owid_continent_one.location_group + " "
     )
     try:
         page_data = OwidCountry.get_countries_for_continent(owid_continent_one, page)
@@ -258,10 +258,10 @@ def url_owid_country_one(country_id: int, page: int = 1):
     page_info = WebPageContent(
         "country: " + owid_country_one.location,
         'OWID',
-        "on continent " + owid_country_one.continent.region + " "
+        "on continent " + owid_country_one.location_group.location_group + " "
     )
     try:
-        page_data = OwidData.get_data_for_country(owid_country_one, page)
+        page_data = OwidData.get_by_location(owid_country_one, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html
index 801f9299..3b3aaeef 100644
--- a/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html
+++ b/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html
@@ -10,7 +10,7 @@
                         <tr>
                             <td>
                                 <a href="{{ url_for('owid.url_owid_continent_one', continent_id=data_item.id) }}">
-                                    {{ data_item.region }}
+                                    {{ data_item.location_group }}
                                 </a>
                             </td>
                         </tr>
diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html
index a9696453..c2b4b4cf 100644
--- a/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html
+++ b/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html
@@ -8,12 +8,12 @@
             <tr>
                 <td>
                     <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid_country.id) }}">
-                    {{ owid_country.iso_code }}
+                    {{ owid_country.location_code }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid_country.continent.id) }}">
-                        {{ owid_country.continent.region }}
+                    <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid_country.location_group.id) }}">
+                        {{ owid_country.location_group.location_group }}
                     </a>
                 </td>
                 <td>
diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html
index 243d9463..25ddca08 100644
--- a/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html
+++ b/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html
@@ -7,18 +7,18 @@
         {% for owid in page_data.items %}
             <tr>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.iso_code }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.location_code }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid.country.continent.id) }}">
-                        {{ owid.country.continent.region }}
+                    <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid.location.location_group.id) }}">
+                        {{ owid.location.location_group.location_group }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.location }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.location }}
                     </a>
                 </td>
                 <td>
@@ -67,78 +67,78 @@
                 <td>{{ owid.new_vaccinations_smoothed_per_million }}</td>
                 <td>{{ owid.stringency_index }}</td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.population }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.population }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.population_density }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.population_density }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.median_age }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.median_age }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.aged_65_older }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.aged_65_older }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                        {{ owid.country.aged_70_older }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                        {{ owid.location.aged_70_older }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.gdp_per_capita }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.gdp_per_capita }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                        {{ owid.country.extreme_poverty }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                        {{ owid.location.extreme_poverty }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                        {{ owid.country.cardiovasc_death_rate }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                        {{ owid.location.cardiovasc_death_rate }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.diabetes_prevalence }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.diabetes_prevalence }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.female_smokers }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.female_smokers }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                        {{ owid.country.male_smokers }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                        {{ owid.location.male_smokers }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.handwashing_facilities }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.handwashing_facilities }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                        {{ owid.country.hospital_beds_per_thousand }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                        {{ owid.location.hospital_beds_per_thousand }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.life_expectancy }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.life_expectancy }}
                     </a>
                 </td>
                 <td>
-                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}">
-                    {{ owid.country.human_development_index }}
+                    <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}">
+                    {{ owid.location.human_development_index }}
                     </a>
                 </td>
             </tr>
-- 
GitLab