From b84c56c43b21280dcd4e303a40d2f3129a248908 Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Sun, 25 Apr 2021 16:17:42 +0200
Subject: [PATCH] work

---
 src/covid19/blueprints/ecdc/ecdc_model.py        | 16 +++++++++-------
 src/covid19/blueprints/owid/owid_model.py        |  8 ++++----
 .../rki/rki_vaccination/rki_vaccination_model.py |  4 ++--
 src/covid19/blueprints/who/who_model.py          |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/covid19/blueprints/ecdc/ecdc_model.py b/src/covid19/blueprints/ecdc/ecdc_model.py
index 067c8a2e..055aac10 100644
--- a/src/covid19/blueprints/ecdc/ecdc_model.py
+++ b/src/covid19/blueprints/ecdc/ecdc_model.py
@@ -22,10 +22,10 @@ class EcdcDateReported(ApplicationDateReported):
     week_of_year = db.Column(db.Integer, nullable=False)
 
     def get_name_for_datum(self):
-        return self.date_reported
+        return self.date_reported_import_str
 
     def get_date_import_format_from_date_reported(self):
-        my_date_parts = self.date_reported.split("-")
+        my_date_parts = self.date_reported_import_str.split("-")
         my_year = my_date_parts[0]
         my_month = my_date_parts[1]
         my_day = my_date_parts[2]
@@ -59,12 +59,12 @@ class EcdcDateReported(ApplicationDateReported):
     @classmethod
     def create_new_object_factory(cls, my_date_rep: str):
         (my_year, my_month, my_day) = cls.get_datum_parts(my_date_rep)
-        date_reported = super().get_datum_as_str(my_year, my_month, my_day)
+        date_reported_import_str = super().get_datum_as_str(my_year, my_month, my_day)
         my_datum = super().get_datum(my_year, my_month, my_day)
         (my_iso_year, week_number, weekday) = my_datum.isocalendar()
         my_year_week = super().my_year_week(my_iso_year, week_number)
         return EcdcDateReported(
-            date_reported_import_str=date_reported,
+            date_reported_import_str=date_reported_import_str,
             datum=my_datum,
             year=my_datum.year,
             month=my_datum.month,
@@ -195,15 +195,17 @@ class EcdcData(db.Model):
     ecdc_country_id = db.Column(db.Integer, db.ForeignKey('ecdc_country.id'), nullable=False)
     ecdc_country = db.relationship(
         'EcdcCountry',
-        lazy='subquery', cascade="all, delete",
+        lazy='subquery',
+        cascade='save-update',
         order_by='asc(EcdcCountry.countries_and_territories)'
     )
 
     ecdc_datereported_id = db.Column(db.Integer, db.ForeignKey('ecdc_datereported.id'), nullable=False)
     ecdc_datereported = db.relationship(
         'EcdcDateReported',
-        lazy='joined', cascade='all, delete',
-        order_by='desc(EcdcDateReported.date_reported)'
+        lazy='joined',
+        cascade='save-update',
+        order_by='desc(EcdcDateReported.date_reported_import_str)'
     )
 
     @classmethod
diff --git a/src/covid19/blueprints/owid/owid_model.py b/src/covid19/blueprints/owid/owid_model.py
index 2d5e529b..3aa69945 100644
--- a/src/covid19/blueprints/owid/owid_model.py
+++ b/src/covid19/blueprints/owid/owid_model.py
@@ -64,7 +64,7 @@ class OwidCountry(db.Model):
     continent = db.relationship(
         'OwidContinent',
         lazy='joined',
-        cascade='all, delete',
+        cascade='save-update',
         order_by='desc(OwidContinent.region)')
     iso_code = db.Column(db.String(255), nullable=False)
     location = db.Column(db.String(255), nullable=False)
@@ -137,14 +137,14 @@ class OwidData(db.Model):
     date_reported = db.relationship(
         'OwidDateReported',
         lazy='joined',
-        cascade='all, delete',
-        order_by='desc(OwidDateReported.date_reported)')
+        cascade='save-update',
+        order_by='desc(OwidDateReported.date_reported_import_str)')
     country_id = db.Column(db.Integer,
         db.ForeignKey('owid_country.id'), nullable=False)
     country = db.relationship(
         'OwidCountry',
         lazy='joined',
-        cascade='all, delete',
+        cascade='save-update',
         order_by='desc(OwidCountry.location)')
     total_cases = db.Column(db.String(255), nullable=False)
     new_cases = db.Column(db.String(255), nullable=False)
diff --git a/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py b/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py
index f90e5f99..b68f57bc 100644
--- a/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py
+++ b/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py
@@ -53,8 +53,8 @@ class RkiVaccinationData(db.Model):
     date_reported = db.relationship(
         'RkiVaccinationDateReported',
         lazy='joined',
-        cascade='all, delete',
-        order_by='desc(RkiVaccinationDateReported.date_reported)')
+        cascade='save-update',
+        order_by='desc(RkiVaccinationDateReported.date_reported_import_str)')
     dosen_kumulativ = db.Column(db.Integer, nullable=False)
     dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False)
     dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False)
diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py
index b75afba5..298b7cae 100644
--- a/src/covid19/blueprints/who/who_model.py
+++ b/src/covid19/blueprints/who/who_model.py
@@ -190,7 +190,7 @@ class WhoData(db.Model):
         'WhoDateReported',
         lazy='joined',
         cascade='save-update',
-        order_by='desc(WhoDateReported.date_reported)')
+        order_by='desc(WhoDateReported.date_reported_import_str)')
     country_id = db.Column(db.Integer,
         db.ForeignKey('who_country.id'), nullable=False)
     country = db.relationship(
-- 
GitLab