Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting post-az projects above Z #75

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ node_modules/bower/bin/bower:


test: install
bin/flake8 trs
bin/pytest | tee trs/pytest-coverage.txt


Expand Down
3 changes: 3 additions & 0 deletions trs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
def make_code_sortable(code):
# Main goal: make P1234.10 sort numerically compared to P1234.2
code = code.lower()
if code.startswith("20"):
# Post a-z code, prefix with zz to get them to the front.
code = "zz" + code
if "." not in code:
return code
parts = code.split(".")
Expand Down
6 changes: 6 additions & 0 deletions trs/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def test_sorting3(self):
# before .10 as it isn't normally a numerical sort.
self.assertEqual(models.Project.objects.all()[0].code, "P1234.10")

def test_sorting4(self):
factories.ProjectFactory.create(code="Z1234.1")
factories.ProjectFactory.create(code="20251234.1")
# Sort new-style yyyy projects before a-z projects.
self.assertEqual(models.Project.objects.all()[0].code, "20251234.1")

def test_make_code_sortable1(self):
self.assertEqual(models.make_code_sortable("P1234"), "p1234")

Expand Down