Skip to content

Commit

Permalink
Sorting post-az projects above Z
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Dec 16, 2024
1 parent 4f80d29 commit 6e1648b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 6e1648b

Please sign in to comment.