Skip to content

Commit

Permalink
Adjust excel ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Aug 20, 2024
1 parent 041db69 commit 85941e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/data_common/dataset/resource_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ class DataResource:
def slug(self) -> str:
return self.path.stem

def get_order(self) -> int:
def get_order(self, native_order: int = 999) -> int:
"""
Get a sheet order if one has been set
"""
desc = self.get_resource()
return desc.get("_sheet_order", 999)
old_style = desc.get("_sheet_order", None)
if old_style:
return old_style
return desc.get("custom", []).get("dataset_order", native_order)

@property
def resource_path(self) -> Path:
Expand Down Expand Up @@ -797,7 +800,8 @@ def resources(self) -> dict[str, DataResource]:
)

resources.sort(key=lambda x: x.slug)
resources.sort(key=lambda x: x.get_order())
new_order = {r.slug: r.get_order(n) for n, r in enumerate(resources)}
resources.sort(key=lambda x: new_order[x.slug])
return {x.slug: x for x in resources}

@property
Expand Down

0 comments on commit 85941e1

Please sign in to comment.