diff --git a/Makefile b/Makefile index 32aec26..93ac913 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,6 @@ node_modules/bower/bin/bower: test: install - bin/flake8 trs bin/pytest | tee trs/pytest-coverage.txt diff --git a/trs/models.py b/trs/models.py index 437d2fa..e289229 100644 --- a/trs/models.py +++ b/trs/models.py @@ -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(".") diff --git a/trs/tests/test_models.py b/trs/tests/test_models.py index 0a4cf44..b7653c1 100644 --- a/trs/tests/test_models.py +++ b/trs/tests/test_models.py @@ -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")