From 14d8686940c84bcd42c410c81aed04042096729d Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Thu, 27 May 2021 01:13:37 +0200 Subject: [PATCH] Refactoring: vaccination --- src/flask_covid19/blueprints/data_ecdc/ecdc_model.py | 11 ++--------- src/flask_covid19/blueprints/data_ecdc/ecdc_views.py | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py index 0f7d1f30..3099cf3f 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py @@ -83,8 +83,6 @@ class EcdcCountry(BlueprintLocation): pop_data_2019 = db.Column(db.String(255), nullable=False) geo_id = db.Column(db.String(255), nullable=False) - - @classmethod def get_by(cls, location: str = '', geo_id: str = '', location_code: str = ''): return db.session.query(cls).filter(and_( @@ -161,14 +159,9 @@ class EcdcData(BlueprintFactTable): @classmethod def find_by_date_reported_order_by_cases_weekly(cls, date_reported: EcdcDateReported, page: int): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id) \ - .order_by(cls.cases.desc()) \ + return db.session.query(cls).filter(cls.date_reported == date_reported) \ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod def find_by_location(cls, location: EcdcCountry, page: int): - return db.session.query(cls).filter( - cls.location_id == location.id) \ - .order_by(cls.date_reported.desc()) \ - .paginate(page, per_page=ITEMS_PER_PAGE) + return db.session.query(cls).filter(cls.location == location).paginate(page, per_page=ITEMS_PER_PAGE) diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py index 5f3bcf69..04c24919 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py @@ -74,7 +74,7 @@ def url_ecdc_date_reported_all(page=1): def url_ecdc_date_reported_one_notification_rate(europe_date_reported_id, page=1): page_info = WebPageContent('Europe', "date_reported") europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.get_by_date_reported_notification_rate(europe_date_reported, page) + page_data = EcdcData.find_by_date_reported_order_by_notification_rate(europe_date_reported, page) return render_template( 'ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate.html', europe_date_reported=europe_date_reported, @@ -87,7 +87,7 @@ def url_ecdc_date_reported_one_notification_rate(europe_date_reported_id, page=1 def url_ecdc_date_reported_one_deaths_weekly(europe_date_reported_id, page=1): page_info = WebPageContent('Europe', "date_reported") europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.find_by_date_reported_deaths_weekly(europe_date_reported, page) + page_data = EcdcData.find_by_date_reported_order_by_deaths_weekly(europe_date_reported, page) return render_template( 'ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly.html', europe_date_reported=europe_date_reported, @@ -100,7 +100,7 @@ def url_ecdc_date_reported_one_deaths_weekly(europe_date_reported_id, page=1): def url_ecdc_date_reported_one_cases_weekly(europe_date_reported_id, page=1): page_info = WebPageContent('Europe', "date_reported") europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.find_by_date_reported_cases_weekly(europe_date_reported, page) + page_data = EcdcData.find_by_date_reported_order_by_cases_weekly(europe_date_reported, page) return render_template( 'ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly.html', europe_date_reported=europe_date_reported, @@ -148,7 +148,7 @@ def url_ecdc_country_all(page=1): def url_ecdc_country_one(country_id, page=1): page_info = WebPageContent('Europe', "country") europe_country = EcdcCountry.get_by_id(country_id) - page_data = EcdcData.find_by_country(europe_country, page) + page_data = EcdcData.find_by_location(europe_country, page) return render_template( 'ecdc/country/one/ecdc_country_one.html', europe_country=europe_country, @@ -160,11 +160,11 @@ def url_ecdc_country_one(country_id, page=1): @app_ecdc.route('/country/germany') def url_ecdc_country_germany(page=1): page_info = WebPageContent('Europe', "country: Germany") - europe_country = EcdcCountry.get_germany() + europe_country = EcdcCountry.find_germany() if europe_country is None: flash('country: Germany not found in Database', category='error') return redirect(url_for('ecdc.url_ecdc_tasks')) - page_data = EcdcData.find_by_country(europe_country, page) + page_data = EcdcData.find_by_location(europe_country, page) return render_template( 'ecdc/country/germany/ecdc_country_germany.html', europe_country=europe_country, -- GitLab