Skip to content

Commit

Permalink
generate validator ranges from header column indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
helen-m-lin committed Mar 28, 2024
1 parent a1b5e8e commit 6ea7085
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/aind_data_transfer_service/configs/job_upload_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class JobUploadTemplate:
"""Class to configure and create xlsx job upload template"""

FILE_NAME = "job_upload_template.xlsx"
NUM_TEMPLATE_ROWS = 20
HEADERS = [
"platform",
"acq_datetime",
Expand Down Expand Up @@ -55,12 +56,15 @@ class JobUploadTemplate:
{
"name": "platform",
"options": [p().abbreviation for p in Platform._ALL],
"ranges": ["A2:A20"],
"column_indexes": [HEADERS.index("platform")],
},
{
"name": "modality",
"options": [m().abbreviation for m in Modality._ALL],
"ranges": ["D2:D20", "F2:F20"],
"column_indexes": [
HEADERS.index("modality0"),
HEADERS.index("modality1"),
],
},
]

Expand All @@ -86,8 +90,9 @@ def create_job_template():
dv.promptTitle = validator["name"]
dv.prompt = f'Select a {validator["name"]} from the dropdown'
dv.error = f'Invalid {validator["name"]}.'
for r in validator["ranges"]:
dv.add(r)
for i in validator["column_indexes"]:
col = get_column_letter(i + 1)
dv.add(f"{col}2:{col}{JobUploadTemplate.NUM_TEMPLATE_ROWS}")
worksheet.add_data_validation(dv)
# formatting
bold = Font(bold=True)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_job_upload_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

from openpyxl import load_workbook
from openpyxl.utils import range_boundaries

from aind_data_transfer_service.configs.job_upload_template import (
JobUploadTemplate,
Expand Down Expand Up @@ -49,6 +50,15 @@ def test_create_job_template(self):
JobUploadTemplate.create_job_template(), True
)
self.assertEqual(expected_lines, template_lines)
for validator in template_validators:
validator["column_indexes"] = []
for r in validator["ranges"]:
rb = (col, *_) = range_boundaries(r)
self.assertTupleEqual(
(col, 2, col, JobUploadTemplate.NUM_TEMPLATE_ROWS), rb
)
validator["column_indexes"].append(col - 1)
del validator["ranges"]
self.assertCountEqual(
JobUploadTemplate.VALIDATORS, template_validators
)
Expand Down

0 comments on commit 6ea7085

Please sign in to comment.