Skip to content

Commit

Permalink
#2676: excel_creation.py - Refactoring template names and paths (#2779
Browse files Browse the repository at this point in the history
)

* Splitting out templates.py

* Replacing name strings

* Lint

* Getting paths from excel.py

---------

Co-authored-by: Phil Dominguez <“[email protected]”>
  • Loading branch information
phildominguez-gsa and Phil Dominguez authored Nov 9, 2023
1 parent de03fae commit 5a8ec7f
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@
# before filling in the XLSX workbooks.
FieldMap = NT("FieldMap", "in_sheet in_db default type")

templates = {
"AdditionalUEIs": "additional-ueis-workbook.xlsx",
"AdditionalEINs": "additional-eins-workbook.xlsx",
"AuditFindingsText": "audit-findings-text-workbook.xlsx",
"CAP": "corrective-action-plan-workbook.xlsx",
"AuditFindings": "federal-awards-audit-findings-workbook.xlsx",
"FederalAwards": "federal-awards-workbook.xlsx",
"SEFA": "notes-to-sefa-workbook.xlsx",
"SecondaryAuditors": "secondary-auditors-workbook.xlsx",
}


def set_single_cell_range(wb, range_name, value):
the_range = wb.defined_names[range_name]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
WorkbookFieldInDissem,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
)


from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import
from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

Expand All @@ -25,7 +24,7 @@ def generate_additional_eins(dbkey, year, outfile):
logger.info(f"--- generate additional eins {dbkey} {year} ---")
Gen = dynamic_import("Gen", year)
Eins = dynamic_import("Eins", year)
wb = pyxl.load_workbook(templates["AdditionalEINs"])
wb = pyxl.load_workbook(sections_to_template_paths[FORM_SECTIONS.ADDITIONAL_EINS])

g = set_uei(Gen, wb, dbkey)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
WorkbookFieldInDissem,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
)


from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import
from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

Expand All @@ -25,7 +24,7 @@
def generate_additional_ueis(dbkey, year, outfile):
logger.info(f"--- generate additional ueis {dbkey} {year} ---")
Gen = dynamic_import("Gen", year)
wb = pyxl.load_workbook(templates["AdditionalUEIs"])
wb = pyxl.load_workbook(sections_to_template_paths[FORM_SECTIONS.ADDITIONAL_UEIS])
g = set_uei(Gen, wb, dbkey)
if int(year) >= 22:
Ueis = dynamic_import("Ueis", year)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
WorkbookFieldInDissem,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
test_pfix,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import
from audit.fixtures.excel import FORM_SECTIONS


import openpyxl as pyxl
Expand All @@ -22,7 +22,9 @@ def generate_corrective_action_plan(dbkey, year, outfile):
logger.info(f"--- generate corrective action plan {dbkey} {year} ---")
Gen = dynamic_import("Gen", year)
Captext = dynamic_import("Captext", year)
wb = pyxl.load_workbook(templates["CAP"])
wb = pyxl.load_workbook(
sections_to_template_paths[FORM_SECTIONS.CORRECTIVE_ACTION_PLAN]
)
mappings = [
FieldMap("reference_number", "findingrefnums", "finding_ref_number", None, str),
FieldMap("planned_action", "text", WorkbookFieldInDissem, None, test_pfix(3)),
Expand Down
17 changes: 0 additions & 17 deletions backend/census_historical_migration/workbooklib/excel_creation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import namedtuple as NT
from playhouse.shortcuts import model_to_dict
import os
import sys

import logging
Expand All @@ -17,22 +16,6 @@
FieldMap = NT("FieldMap", "in_sheet in_db in_dissem default type")
WorkbookFieldInDissem = 1000

templates_root = "schemas/output/excel/xlsx/"
templates_raw = {
"AdditionalUEIs": "additional-ueis-workbook.xlsx",
"AdditionalEINs": "additional-eins-workbook.xlsx",
"AuditFindingsText": "audit-findings-text-workbook.xlsx",
"CAP": "corrective-action-plan-workbook.xlsx",
"AuditFindings": "federal-awards-audit-findings-workbook.xlsx",
"FederalAwards": "federal-awards-workbook.xlsx",
"SEFA": "notes-to-sefa-workbook.xlsx",
"SecondaryAuditors": "secondary-auditors-workbook.xlsx",
}

templates = {}
for k, v in templates_raw.items():
templates[k] = os.path.join(templates_root, v)


def test_pfix(n):
def _test(o):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
WorkbookFieldInDissem,
templates,
set_uei,
set_single_cell_range,
map_simple_columns,
generate_dissemination_test_table,
set_range,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import

from audit.fixtures.excel import FORM_SECTIONS
from config import settings

import openpyxl as pyxl
Expand Down Expand Up @@ -197,7 +196,9 @@ def generate_federal_awards(dbkey, year, outfile):
Gen = dynamic_import("Gen", year)
Passthrough = dynamic_import("Passthrough", year)
Cfda = dynamic_import("Cfda", year)
wb = pyxl.load_workbook(templates["FederalAwards"])
wb = pyxl.load_workbook(
sections_to_template_paths[FORM_SECTIONS.FEDERAL_AWARDS_EXPENDED]
)
# In sheet : in DB

g = set_uei(Gen, wb, dbkey)
Expand Down
9 changes: 5 additions & 4 deletions backend/census_historical_migration/workbooklib/findings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
set_range,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import

from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

Expand Down Expand Up @@ -93,7 +92,9 @@ def generate_findings(dbkey, year, outfile):
Gen = dynamic_import("Gen", year)
Findings = dynamic_import("Findings", year)
Cfda = dynamic_import("Cfda", year)
wb = pyxl.load_workbook(templates["AuditFindings"])
wb = pyxl.load_workbook(
sections_to_template_paths[FORM_SECTIONS.FINDINGS_UNIFORM_GUIDANCE]
)
g = set_uei(Gen, wb, dbkey)

cfdas = Cfda.select().where(Cfda.dbkey == g.dbkey).order_by(Cfda.index)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
WorkbookFieldInDissem,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
test_pfix,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import
from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

Expand All @@ -29,7 +29,7 @@ def generate_findings_text(dbkey, year, outfile):
logger.info(f"--- generate findings text {dbkey} {year} ---")
Gen = dynamic_import("Gen", year)
Findingstext = dynamic_import("Findingstext", year)
wb = pyxl.load_workbook(templates["AuditFindingsText"])
wb = pyxl.load_workbook(sections_to_template_paths[FORM_SECTIONS.FINDINGS_TEXT])

g = set_uei(Gen, wb, dbkey)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
templates,
set_uei,
set_single_cell_range,
map_simple_columns,
generate_dissemination_test_table,
test_pfix,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.excel_creation import (
set_range,
)
from census_historical_migration.workbooklib.census_models.census import dynamic_import

from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

import re
import logging

# import unidecode

logger = logging.getLogger(__name__)

Expand All @@ -43,7 +42,7 @@ def generate_notes_to_sefa(dbkey, year, outfile):
logger.info(f"--- generate notes to sefa {dbkey} {year}---")
Gen = dynamic_import("Gen", year)
Notes = dynamic_import("Notes", year)
wb = pyxl.load_workbook(templates["SEFA"])
wb = pyxl.load_workbook(sections_to_template_paths[FORM_SECTIONS.NOTES_TO_SEFA])

g = set_uei(Gen, wb, dbkey)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from census_historical_migration.workbooklib.excel_creation import (
FieldMap,
templates,
set_uei,
map_simple_columns,
generate_dissemination_test_table,
test_pfix,
)

from census_historical_migration.workbooklib.templates import sections_to_template_paths
from census_historical_migration.workbooklib.census_models.census import dynamic_import


from census_historical_migration.workbooklib.sac_creation import add_hyphen_to_zip
from audit.fixtures.excel import FORM_SECTIONS

import openpyxl as pyxl

Expand Down Expand Up @@ -54,7 +52,9 @@ def generate_secondary_auditors(dbkey, year, outfile):
logger.info(f"--- generate secondary auditors {dbkey} {year} ---")
Gen = dynamic_import("Gen", year)
Cpas = dynamic_import("Cpas", year)
wb = pyxl.load_workbook(templates["SecondaryAuditors"])
wb = pyxl.load_workbook(
sections_to_template_paths[FORM_SECTIONS.SECONDARY_AUDITORS]
)

g = set_uei(Gen, wb, dbkey)

Expand Down
23 changes: 23 additions & 0 deletions backend/census_historical_migration/workbooklib/templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from audit.fixtures.excel import FORM_SECTIONS
from audit.fixtures.excel import (
ADDITIONAL_EINS_TEMPLATE,
ADDITIONAL_UEIS_TEMPLATE,
CORRECTIVE_ACTION_PLAN_TEMPLATE,
FEDERAL_AWARDS_TEMPLATE,
FINDINGS_TEXT_TEMPLATE,
FINDINGS_UNIFORM_GUIDANCE_TEMPLATE,
NOTES_TO_SEFA_TEMPLATE,
SECONDARY_AUDITORS_TEMPLATE,
)


sections_to_template_paths = {
FORM_SECTIONS.ADDITIONAL_EINS: ADDITIONAL_EINS_TEMPLATE,
FORM_SECTIONS.ADDITIONAL_UEIS: ADDITIONAL_UEIS_TEMPLATE,
FORM_SECTIONS.CORRECTIVE_ACTION_PLAN: CORRECTIVE_ACTION_PLAN_TEMPLATE,
FORM_SECTIONS.FEDERAL_AWARDS_EXPENDED: FEDERAL_AWARDS_TEMPLATE,
FORM_SECTIONS.FINDINGS_TEXT: FINDINGS_TEXT_TEMPLATE,
FORM_SECTIONS.FINDINGS_UNIFORM_GUIDANCE: FINDINGS_UNIFORM_GUIDANCE_TEMPLATE,
FORM_SECTIONS.NOTES_TO_SEFA: NOTES_TO_SEFA_TEMPLATE,
FORM_SECTIONS.SECONDARY_AUDITORS: SECONDARY_AUDITORS_TEMPLATE,
}

0 comments on commit 5a8ec7f

Please sign in to comment.