From 422d304d6f52c11ccf007302c3072c1f2a191654 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 28 Mar 2017 12:45:30 +0200
Subject: [PATCH] error when subjcet contains invalid screening number handled
 properly

---
 smash/web/forms.py                     | 5 ++++-
 smash/web/tests/test_SubjectAddForm.py | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/smash/web/forms.py b/smash/web/forms.py
index 2294dd24..80e00359 100644
--- a/smash/web/forms.py
+++ b/smash/web/forms.py
@@ -88,7 +88,10 @@ def get_new_screening_number(screening_number_prefix):
             screening_number = screening_number.strip()
             if screening_number.startswith(screening_number_prefix):
                 number = screening_number[len(screening_number_prefix):]
-                result_number = max(result_number, int(number))
+                try:
+                    result_number = max(result_number, int(number))
+                except ValueError:
+                    pass
 
     return screening_number_prefix + str(result_number + 1).zfill(3)
 
diff --git a/smash/web/tests/test_SubjectAddForm.py b/smash/web/tests/test_SubjectAddForm.py
index de00468a..15881450 100644
--- a/smash/web/tests/test_SubjectAddForm.py
+++ b/smash/web/tests/test_SubjectAddForm.py
@@ -135,3 +135,12 @@ class SubjectAddFormTests(TestCase):
 
         new_screening_number = get_new_screening_number(prefix)
         self.assertEqual(prefix + "201", new_screening_number)
+
+    def test_get_new_screening_number_6(self):
+        prefix = "X-"
+        subject = create_subject()
+        subject.screening_number = "X-"
+        subject.save()
+
+        new_screening_number = get_new_screening_number(prefix)
+        self.assertEqual(prefix + "001", new_screening_number)
-- 
GitLab