Skip to content

Commit

Permalink
refactor!: Columns filterable and sortable are empty by default
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jun 30, 2024
1 parent 0ad5295 commit aeb3950
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ckanext/collection/tests/utils/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_names(self, collection: Collection):
assert obj.names == names
assert obj.hidden == set()
assert obj.visible == set(names)
assert obj.sortable == set(names)
assert obj.filterable == set(names)
assert obj.sortable == set()
assert obj.filterable == set()
assert obj.labels == {n: n for n in names}

def test_hidden(self, collection: Collection):
Expand Down
34 changes: 29 additions & 5 deletions ckanext/collection/utils/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Default(shared.Sentinel, enum.Enum):
names: list[str] = shared.configurable_attribute(default_factory=lambda self: [])
hidden: set[str] = shared.configurable_attribute(default_factory=lambda self: set())
visible: set[str] = shared.configurable_attribute(Default.NOT_HIDDEN)
sortable: set[str] = shared.configurable_attribute(Default.ALL)
filterable: set[str] = shared.configurable_attribute(Default.ALL)
sortable: set[str] = shared.configurable_attribute(Default.NONE)
filterable: set[str] = shared.configurable_attribute(Default.NONE)
searchable: set[str] = shared.configurable_attribute(Default.NONE)
labels: dict[str, str] = shared.configurable_attribute(Default.ALL)

Expand Down Expand Up @@ -74,15 +74,39 @@ def _compute_set(self, value: Default | set[str]):
return value

def get_primary_order(self, name: str) -> str:
"""Format column name for usage as a primary order value.
"""Format column name as a primary(asc) order value.
Examples:
Hehe haha
>>> col = Collection()
>>> col.columns.get_primary_order("name")
"name"
Args:
name: the name of sorted column
name: the name of the sorted column
Returns:
column name adapted for primary(ascending) sorting.
"""
return name

def get_secondary_order(self, name: str) -> str:
"""Format column name for usage as a secondary order value."""
"""Format column name as a secondary(desc) order value.
Examples:
>>> col = Collection()
>>> col.columns.get_secondary_order("name")
"-name"
Args:
name: the name of the sorted column
Returns:
column name adapted for secondary(descending) sorting.
"""
return f"-{name}"


Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ plugins:
handlers:
python:
options:
show_root_full_path: false
show_root_toc_entry: false
show_symbol_type_heading: true
show_source: false

docstring_section_style: spacy
- search:
separator: '[\s\-\.\_]+'

Expand Down

0 comments on commit aeb3950

Please sign in to comment.