From 27e36917e190e39dd3f4cab4cc3439491e1b4dd7 Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Mon, 24 May 2021 08:49:36 +0200
Subject: [PATCH] Refactoring: rename covid19 to flask_covid19ssaas

---
 .../blueprints/data_rki_cases/rki_model.py      | 15 ++++-----------
 .../data_rki_cases/rki_model_import.py          |  2 +-
 .../data_rki_cases/rki_service_update.py        | 17 +++++++++++++++++
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/flask_covid19/blueprints/data_rki_cases/rki_model.py b/src/flask_covid19/blueprints/data_rki_cases/rki_model.py
index 445c6c3c..d013f2af 100644
--- a/src/flask_covid19/blueprints/data_rki_cases/rki_model.py
+++ b/src/flask_covid19/blueprints/data_rki_cases/rki_model.py
@@ -1,7 +1,7 @@
 from sqlalchemy import and_
 
 from database import db, ITEMS_PER_PAGE
-from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup
+from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup, BlueprintLocation
 
 
 class RkiMeldedatum(BlueprintDateReported):
@@ -70,14 +70,15 @@ class RkiBundesland(BlueprintLocationGroup):
     processed_full_update = db.Column(db.Boolean, nullable=False)
 
 
-class RkiLandkreis(db.Model):
+class RkiLandkreis(BlueprintLocation):
     __tablename__ = 'rki_landkreis'
+    __mapper_args__ = {'concrete': True}
     __table_args__ = (
         db.UniqueConstraint('location', 'id_landkreis', name="uix_rki_landkreis"),
     )
 
     def __str__(self):
-        return " " + self.landkreis + " | " + self.id_landkreis + " -> " + self.bundesland + " "
+        return " " + self.location + " ( " + self.id_landkreis + " ) -> " + str(self.location_group) + " "
 
     id = db.Column(db.Integer, primary_key=True)
     id_landkreis = db.Column(db.String(255), nullable=False)
@@ -91,14 +92,6 @@ class RkiLandkreis(db.Model):
     processed_update = db.Column(db.Boolean, nullable=False)
     processed_full_update = db.Column(db.Boolean, nullable=False)
 
-    def __str__(self):
-        result = ""
-        result += self.landkreis
-        result += " -> "
-        result += self.location_group.location_group
-        result += " "
-        return result
-
     @classmethod
     def remove_all(cls):
         num_rows_deleted = 0
diff --git a/src/flask_covid19/blueprints/data_rki_cases/rki_model_import.py b/src/flask_covid19/blueprints/data_rki_cases/rki_model_import.py
index 74e5ea7e..bfe5896d 100644
--- a/src/flask_covid19/blueprints/data_rki_cases/rki_model_import.py
+++ b/src/flask_covid19/blueprints/data_rki_cases/rki_model_import.py
@@ -92,7 +92,7 @@ class RkiImport(db.Model):
 
     @classmethod
     def get_landkreis_for_bundesland(cls, bundesland:str):
-        return db.session.query(cls.landkreis) \
+        return db.session.query(cls.landkreis, cls.id_landkreis) \
             .filter(cls.bundesland == bundesland) \
             .distinct() \
             .order_by(cls.landkreis.asc()) \
diff --git a/src/flask_covid19/blueprints/data_rki_cases/rki_service_update.py b/src/flask_covid19/blueprints/data_rki_cases/rki_service_update.py
index 3c427016..e882eb8a 100644
--- a/src/flask_covid19/blueprints/data_rki_cases/rki_service_update.py
+++ b/src/flask_covid19/blueprints/data_rki_cases/rki_service_update.py
@@ -70,9 +70,26 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase):
         app.logger.info("------------------------------------------------------------")
         RkiLandkreis.remove_all()
         self.__full_update_bundesland()
+        i = 0
+        output_lines = []
         for bundesland in RkiBundesland.get_all():
+            app.logger.info(" full update RKI landkreis for bundesland: " + bundesland.location_group)
             for landkreis_from_import in RkiImport.get_landkreis_for_bundesland(bundesland=bundesland.location_group):
+                i += 1
                 app.logger.info("landkreis_from_import: "+str(landkreis_from_import))
+                o = RkiLandkreis(
+                    location=landkreis_from_import[0],
+                    id_landkreis=landkreis_from_import[1],
+                    location_group=bundesland,
+                    processed_update=False,
+                    processed_full_update=True,
+                )
+                db.session.add(o)
+                output = " full update RKI landkreis ... " + str(o) + "   [ " + str(i) + " ] "
+                output_lines.append(output)
+            db.session.commit()
+            for output in output_lines:
+                app.logger.info(output)
         app.logger.info("------------------------------------------------------------")
         app.logger.info("")
         app.logger.info(" RkiServiceUpdateFull.__full_update_landkreis [done]")
-- 
GitLab