From 7cd7a05d847ede3b8c2d763ad45390f17080bc84 Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Sun, 24 Jan 2021 23:44:37 +0100 Subject: [PATCH] work --- app.py | 60 ++++++++++++++++ org/woehlke/covid19/who/who_model.py | 44 ++++++++++++ ...ragment_who_global_data_table_country.html | 66 +++++++++++++++++ templates/who/who_country_germany.html | 2 +- templates/who/who_country_one.html | 2 +- .../who/who_country_one_cases_cumulative.html | 71 +++++++++++++++++++ templates/who/who_country_one_cases_new.html | 71 +++++++++++++++++++ .../who_country_one_deaths_cumulative.html | 71 +++++++++++++++++++ templates/who/who_country_one_deaths_new.html | 71 +++++++++++++++++++ 9 files changed, 456 insertions(+), 2 deletions(-) create mode 100644 templates/who/fragment_who_global_data_table_country.html create mode 100644 templates/who/who_country_one_cases_cumulative.html create mode 100644 templates/who/who_country_one_cases_new.html create mode 100644 templates/who/who_country_one_deaths_cumulative.html create mode 100644 templates/who/who_country_one_deaths_new.html diff --git a/app.py b/app.py index 825b8b73..1a189826 100644 --- a/app.py +++ b/app.py @@ -389,6 +389,66 @@ def url_who_country(country_id, page=1): page_info=page_info) +@app.route('/who/country/<int:country_id>/cases_new/page/<int:page>') +@app.route('/who/country/<int:country_id>/cases_new') +def url_who_country_cases_new(country_id, page=1): + who_country = WhoCountry.get_by_id(country_id) + page_data = WhoGlobalData.get_data_for_country_order_by_cases_new(who_country, page) + page_info = ApplicationPage(who_country.country, + "Country "+who_country.country_code, + "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region) + return render_template( + 'who/who_country_one_cases_new.html', + who_country=who_country, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/country/<int:country_id>/cases_cumulative/page/<int:page>') +@app.route('/who/country/<int:country_id>/cases_cumulative') +def url_who_country_cases_cumulative(country_id, page=1): + who_country = WhoCountry.get_by_id(country_id) + page_data = WhoGlobalData.get_data_for_country_order_by_cases_cumulative(who_country, page) + page_info = ApplicationPage(who_country.country, + "Country "+who_country.country_code, + "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region) + return render_template( + 'who/who_country_one_cases_cumulative.html', + who_country=who_country, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/country/<int:country_id>/deaths_new/page/<int:page>') +@app.route('/who/country/<int:country_id>/deaths_new') +def url_who_country_deaths_new(country_id, page=1): + who_country = WhoCountry.get_by_id(country_id) + page_data = WhoGlobalData.get_data_for_country_order_by_deaths_new(who_country, page) + page_info = ApplicationPage(who_country.country, + "Country "+who_country.country_code, + "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region) + return render_template( + 'who/who_country_one_deaths_new.html', + who_country=who_country, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/country/<int:country_id>/deaths_cumulative/page/<int:page>') +@app.route('/who/country/<int:country_id>/deaths_cumulative') +def url_who_country_deaths_cumulative(country_id, page=1): + who_country = WhoCountry.get_by_id(country_id) + page_data = WhoGlobalData.get_data_for_country_order_by_deaths_cumulative(who_country, page) + page_info = ApplicationPage(who_country.country, + "Country "+who_country.country_code, + "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region) + return render_template( + 'who/who_country_one_deaths_cumulative.html', + who_country=who_country, + page_data=page_data, + page_info=page_info) + + @app.route('/who/germany/page/<int:page>') @app.route('/who/germany') def url_who_germany(page=1): diff --git a/org/woehlke/covid19/who/who_model.py b/org/woehlke/covid19/who/who_model.py index 63cbc0f5..714bb2d8 100644 --- a/org/woehlke/covid19/who/who_model.py +++ b/org/woehlke/covid19/who/who_model.py @@ -256,6 +256,50 @@ class WhoGlobalData(db.Model): cls.deaths_cumulative.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) + @classmethod + def get_data_for_country_order_by_cases_new(cls, who_country, page): + return db.session.query(cls).filter( + cls.country_id == who_country.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.cases_new.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_country_order_by_cases_cumulative(cls, who_country, page): + return db.session.query(cls).filter( + cls.country_id == who_country.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.cases_cumulative.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_country_order_by_deaths_new(cls, who_country, page): + return db.session.query(cls).filter( + cls.country_id == who_country.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.deaths_new.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_country_order_by_deaths_cumulative(cls, who_country, page): + return db.session.query(cls).filter( + cls.country_id == who_country.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.deaths_cumulative.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + class WhoGlobalDataImportTable(db.Model): __tablename__ = 'who_global_data_import' diff --git a/templates/who/fragment_who_global_data_table_country.html b/templates/who/fragment_who_global_data_table_country.html new file mode 100644 index 00000000..3ff6ffa4 --- /dev/null +++ b/templates/who/fragment_who_global_data_table_country.html @@ -0,0 +1,66 @@ + <table class="table table-hover table-striped table-dark"> + <thead> + <tr> + <th scope="col">date reported</th> + <th scope="col"> + <a href="/who/country/{{ who_country.id }}/deaths_new"> + deaths new + </a> + </th> + <th scope="col"> + <a href="/who/country/{{ who_country.id }}/cases_new"> + cases new + </a> + </th> + <th scope="col"> + <a href="/who/country/{{ who_country.id }}/deaths_cumulative"> + deaths cumulative + </a> + </th> + <th scope="col"> + <a href="/who/country/{{ who_country.id }}/cases_cumulative"> + cases cumulative + </a> + </th> + <th scope="col">country code</th> + <th scope="col">country</th> + <th scope="col">region</th> + </tr> + </thead> + <tbody> + {% for who_global_data in page_data.items %} + <tr> + <th> + {{ who_global_data.date_reported.date_reported }} + </th> + <td> + {{ who_global_data.deaths_new }} + </td> + <td> + {{ who_global_data.cases_new }} + </td> + <td> + {{ who_global_data.deaths_cumulative }} + </td> + <td> + {{ who_global_data.cases_cumulative }} + </td> + <td> + <a href="/who/country/{{ who_global_data.country.id }}"> + {{ who_global_data.country.country_code }} + </a> + </td> + <td> + <a href="/who/country/{{ who_global_data.country.id }}"> + {{ who_global_data.country.country }} + </a> + </td> + <th> + <a href="/who/region/{{ who_global_data.country.region.id }}"> + {{ who_global_data.country.region.region }} + </a> + </th> + </tr> + {% endfor %} + </tbody> + </table> \ No newline at end of file diff --git a/templates/who/who_country_germany.html b/templates/who/who_country_germany.html index 1b719585..419ba32e 100644 --- a/templates/who/who_country_germany.html +++ b/templates/who/who_country_germany.html @@ -57,7 +57,7 @@ </ul> {% endif %} - {% include 'who/fragment_who_global_data_table.html' %} + {% include 'who/fragment_who_global_data_table_country.html' %} {% endblock %} diff --git a/templates/who/who_country_one.html b/templates/who/who_country_one.html index cb7d837b..f4b18ed1 100644 --- a/templates/who/who_country_one.html +++ b/templates/who/who_country_one.html @@ -57,7 +57,7 @@ </ul> {% endif %} - {% include 'who/fragment_who_global_data_table.html' %} + {% include 'who/fragment_who_global_data_table_country.html' %} {% endblock %} diff --git a/templates/who/who_country_one_cases_cumulative.html b/templates/who/who_country_one_cases_cumulative.html new file mode 100644 index 00000000..77bc7e9c --- /dev/null +++ b/templates/who/who_country_one_cases_cumulative.html @@ -0,0 +1,71 @@ +{% extends 'page_layout.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + +{% block main_container %} + + {% if page_data.pages > 1 %} + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_cumulative', country_id=who_country.id, page=page_data.prev_num) }}"> + Previous + </a> + </li> + {% endif %} + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_cumulative', country_id=who_country.id, page=page_num) }}"> + {{ page_num }} + </a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_cumulative', country_id=who_country.id, page=page_data.next_num) }}"> + Next + </a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_country.html' %} + +{% endblock %} + + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_country_one_cases_new.html b/templates/who/who_country_one_cases_new.html new file mode 100644 index 00000000..1b4409c4 --- /dev/null +++ b/templates/who/who_country_one_cases_new.html @@ -0,0 +1,71 @@ +{% extends 'page_layout.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + +{% block main_container %} + + {% if page_data.pages > 1 %} + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_new', country_id=who_country.id, page=page_data.prev_num) }}"> + Previous + </a> + </li> + {% endif %} + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_new', country_id=who_country.id, page=page_num) }}"> + {{ page_num }} + </a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_cases_new', country_id=who_country.id, page=page_data.next_num) }}"> + Next + </a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_country.html' %} + +{% endblock %} + + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_country_one_deaths_cumulative.html b/templates/who/who_country_one_deaths_cumulative.html new file mode 100644 index 00000000..e447cc21 --- /dev/null +++ b/templates/who/who_country_one_deaths_cumulative.html @@ -0,0 +1,71 @@ +{% extends 'page_layout.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + +{% block main_container %} + + {% if page_data.pages > 1 %} + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_cumulative', country_id=who_country.id, page=page_data.prev_num) }}"> + Previous + </a> + </li> + {% endif %} + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_cumulative', country_id=who_country.id, page=page_num) }}"> + {{ page_num }} + </a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_cumulative', country_id=who_country.id, page=page_data.next_num) }}"> + Next + </a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_country.html' %} + +{% endblock %} + + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_country_one_deaths_new.html b/templates/who/who_country_one_deaths_new.html new file mode 100644 index 00000000..62eec9a1 --- /dev/null +++ b/templates/who/who_country_one_deaths_new.html @@ -0,0 +1,71 @@ +{% extends 'page_layout.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + +{% block main_container %} + + {% if page_data.pages > 1 %} + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_new', country_id=who_country.id, page=page_data.prev_num) }}"> + Previous + </a> + </li> + {% endif %} + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_new', country_id=who_country.id, page=page_num) }}"> + {{ page_num }} + </a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for( 'url_who_country_deaths_new', country_id=who_country.id, page=page_data.next_num) }}"> + Next + </a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_country.html' %} + +{% endblock %} + + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file -- GitLab