diff --git a/daily_read/__main__.py b/daily_read/__main__.py index 2a25ad7..2bfad8a 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -93,20 +93,22 @@ 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"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/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( diff --git a/daily_read/statusdb.py b/daily_read/statusdb.py index c542c9e..978742b 100644 --- a/daily_read/statusdb.py +++ b/daily_read/statusdb.py @@ -1,9 +1,7 @@ """Classes for handling various utility functions""" - -import logging - import couchdb +import logging log = logging.getLogger(__name__) 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