From a2be3baf9c5823ae9b9f1db19715bb4cbccbb361 Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Thu, 25 Jan 2024 14:41:30 +0100 Subject: [PATCH 1/5] Filter None from report, catch all possible exceptions during upload and do not stage the project --- daily_read/__main__.py | 28 +++++++++++------------ daily_read/templates/daily_report.html.j2 | 16 +++++-------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/daily_read/__main__.py b/daily_read/__main__.py index 2a25ad7..3195989 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -93,20 +93,20 @@ def generate_all(upload=False, develop=False): for owner in modified_orders: if upload: report = daily_rep.populate_and_write_report(owner, modified_orders[owner], config_values.STATUS_PRIORITY) - # Publish reports - for status in modified_orders[owner]["projects"].keys(): - for project in modified_orders[owner]["projects"][status]: - uploaded = False - uploaded = op.upload_report_to_order_portal(report, project, "published") - if uploaded: - op.projects_data.stage_data_for_project(project) - # Hide old reports - for status in modified_orders[owner]["delete_report_for"].keys(): - for project in modified_orders[owner]["delete_report_for"][status]: - uploaded = False - uploaded = op.upload_report_to_order_portal("", project, "review") - if uploaded: - op.projects_data.stage_data_for_project(project) + # Publish reports with published, hide reports with review + for upload_category, report_state in {"projects": "published", "delete_report_for": "review"}.items(): + for status in modified_orders[owner][upload_category].keys(): + for project in modified_orders[owner][upload_category][status]: + uploaded = False + report_upload = report if upload_category == "projects" else "" + try: + uploaded = op.upload_report_to_order_portal(report_upload, project, report_state) + # Stage changes only if report was uploaded + if uploaded: + op.projects_data.stage_data_for_project(project) + # catch any and every exception during upload + except Exception as e: + log.error(f"Theres was an issue in uploading/hiding reports for {project.project_id}: {e}") # Commit all uploaded projects op.projects_data.commit_staged_data(f"Commit reports updates for {datetime.datetime.now()}") diff --git a/daily_read/templates/daily_report.html.j2 b/daily_read/templates/daily_report.html.j2 index fc509d4..68a5ba2 100644 --- a/daily_read/templates/daily_report.html.j2 +++ b/daily_read/templates/daily_report.html.j2 @@ -1,8 +1,6 @@ - - + ' width="120%" height="2000" frameborder="0" sandbox="allow-scripts allow-top-navigation"> + + \ No newline at end of file From 4a007de2c6a4907eb128f5b443b2121cc029ad08 Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Fri, 26 Jan 2024 12:29:53 +0100 Subject: [PATCH 2/5] JA review: differentiate report update msg in log --- daily_read/order_portal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daily_read/order_portal.py b/daily_read/order_portal.py index ff7b072..1b58224 100644 --- a/daily_read/order_portal.py +++ b/daily_read/order_portal.py @@ -162,7 +162,8 @@ def upload_report_to_order_portal(self, report, project, status): response = requests.post(url, headers=self.headers, json=indata) if response.status_code == 200: - log.info(f"Updated report for order with project id: {project.project_id}") + operation = "Updated" if report else "Hid" + log.info(f"{operation} report for order with project id: {project.project_id}") return True else: log.error( From fe75bbd25ed719d2856a447c448e8718ef19306a Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Fri, 26 Jan 2024 12:32:49 +0100 Subject: [PATCH 3/5] JA review: make msg more threatening --- daily_read/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daily_read/__main__.py b/daily_read/__main__.py index 3195989..c82ae35 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -106,7 +106,7 @@ def generate_all(upload=False, develop=False): op.projects_data.stage_data_for_project(project) # catch any and every exception during upload except Exception as e: - log.error(f"Theres was an issue in uploading/hiding reports for {project.project_id}: {e}") + log.error(f"Exception Raised: Issue in uploading/hiding reports for {project.project_id}: {e}\nContinuing to next project") # Commit all uploaded projects op.projects_data.commit_staged_data(f"Commit reports updates for {datetime.datetime.now()}") From 835477610f7f25f4ad66defa98ef3239c3a49e1e Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Fri, 26 Jan 2024 12:37:01 +0100 Subject: [PATCH 4/5] Black --- daily_read/__main__.py | 4 +++- daily_read/statusdb.py | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/daily_read/__main__.py b/daily_read/__main__.py index c82ae35..2bfad8a 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -106,7 +106,9 @@ def generate_all(upload=False, develop=False): op.projects_data.stage_data_for_project(project) # catch any and every exception during upload except Exception as e: - log.error(f"Exception Raised: Issue in uploading/hiding reports for {project.project_id}: {e}\nContinuing to next project") + log.error( + f"Exception Raised: Issue in uploading/hiding reports for {project.project_id}: {e}\nContinuing to next project" + ) # Commit all uploaded projects op.projects_data.commit_staged_data(f"Commit reports updates for {datetime.datetime.now()}") diff --git a/daily_read/statusdb.py b/daily_read/statusdb.py index c542c9e..0f5f42c 100644 --- a/daily_read/statusdb.py +++ b/daily_read/statusdb.py @@ -1,9 +1,8 @@ """Classes for handling various utility functions""" -import logging - import couchdb +import logging log = logging.getLogger(__name__) From 2a9909a9fab41377c54f4221152690131f6a4f2e Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Fri, 26 Jan 2024 12:40:59 +0100 Subject: [PATCH 5/5] Black again --- daily_read/statusdb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/daily_read/statusdb.py b/daily_read/statusdb.py index 0f5f42c..978742b 100644 --- a/daily_read/statusdb.py +++ b/daily_read/statusdb.py @@ -1,6 +1,5 @@ """Classes for handling various utility functions""" - import couchdb import logging