Index: /main/waeup.kofa/trunk/CHANGES.txt
===================================================================
--- /main/waeup.kofa/trunk/CHANGES.txt	(revision 12394)
+++ /main/waeup.kofa/trunk/CHANGES.txt	(revision 12395)
@@ -4,4 +4,7 @@
 1.3dev (unreleased)
 ===================
+
+* Catch traceback when creating an application slip with a corrupted
+  image file.
 
 * Remove deprecated HTML and REST widgets and use html2dict instead.
Index: /main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py	(revision 12394)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py	(revision 12395)
@@ -144,9 +144,15 @@
         except:
             return False, 'Unknown Error'
-        # Finally prove if the certificate still exists
+        # Prove if the certificate still exists
         try:
             StudentStudyCourse().certificate = self.course_admitted
         except ConstraintNotSatisfied, err:
             return False, 'ConstraintNotSatisfied: %s' % self.course_admitted.code
+        # Finally prove if an application slip can be created
+        try:
+            applicant_slip = getAdapter(self, IPDF, name='application_slip')(
+                view=view)
+        except IOError:
+            return False, _('IOError: Application Slip could not be created.')
         # Add student
         site = grok.getSite()
@@ -165,16 +171,11 @@
         notify(grok.ObjectModifiedEvent(student))
         # Save application slip
-        try:
-            self._createApplicationPDF(student, view=view)
-            return True, _('Student ${a} created', mapping = {'a':student.student_id})
-        except IOError:
-            return False, _('IOError: Application Slip could not be created.')
-
-    def _createApplicationPDF(self, student, view=None):
+        self._saveApplicationPDF(student, applicant_slip, view=view)
+        return True, _('Student ${a} created', mapping = {'a':student.student_id})
+
+    def _saveApplicationPDF(self, student, applicant_slip, view=None):
         """Create an application slip as PDF and store it in student folder.
         """
         file_store = getUtility(IExtFileStore)
-        applicant_slip = getAdapter(self, IPDF, name='application_slip')(
-            view=view)
         file_id = IFileStoreNameChooser(student).chooseName(
             attr="application_slip.pdf")
Index: /main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py	(revision 12394)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py	(revision 12395)
@@ -764,6 +764,12 @@
 
     def render(self):
-        pdfstream = getAdapter(self.context, IPDF, name='application_slip')(
-            view=self)
+        try:
+            pdfstream = getAdapter(self.context, IPDF, name='application_slip')(
+                view=self)
+        except IOError:
+            self.flash(
+                _('Your image file is corrupted. '
+                  'Please replace.'), type='danger')
+            return self.redirect(self.url(self.context))
         self.response.setHeader(
             'Content-Type', 'application/pdf')
Index: /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py	(revision 12394)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py	(revision 12395)
@@ -202,2 +202,33 @@
         (success, msg) = self.applicant.createStudent()
         self.assertTrue('created' in msg)
+
+    def test_copier_with_defective_passport_image(self):
+        IWorkflowState(self.applicant).setState('admitted')
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.manage_path)
+        self.fill_correct_values()
+        self.browser.getControl("Save").click()
+        # Upload a passport picture
+        ctrl = self.browser.getControl(name='form.passport')
+        # This file has really been uploaded by KwaraPoly student
+        # Until 4/1/15 these files resulted a traceback when opening
+        # the createallstudents page. The traceback is now catched.
+        file_obj = open(
+            os.path.join(os.path.dirname(__file__), 'fake_image.jpg'),'rb')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
+        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
+        self.browser.getControl("Save").click() # submit form
+        (success, msg) = self.applicant.createStudent()
+        self.assertTrue(msg == 'IOError: Application Slip could not be created.')
+        # The same in the UI
+        self.browser.open(self.manage_container_path)
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value=self.applicant.application_number).selected = True
+        self.browser.getControl("Create students from selected", index=0).click()
+        self.assertTrue('No student could be created.' in self.browser.contents)
+        self.browser.open(self.container_path + '/createallstudents')
+        self.assertTrue('No student could be created' in self.browser.contents)
+        logfile = os.path.join(self.app['datacenter'].storage, 'logs', 'applicants.log')
+        logcontent = open(logfile).read()
+        self.assertTrue('IOError: Application Slip could not be created.' in logcontent)
Index: /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 12394)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 12395)
@@ -781,4 +781,22 @@
             in logcontent)
 
+    def test_application_slip_with_non_jpg_image(self):
+        IWorkflowState(self.applicant).setState('submitted')
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.manage_path)
+        # Create a pseudo image file and select it to be uploaded in form
+        photo_content = 'A' * 1024 * 5  # A string of 5 KB size
+        pseudo_image = StringIO(photo_content)
+        ctrl = self.browser.getControl(name='form.passport')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
+        self.browser.getControl("Save").click() # submit form
+        self.browser.open(self.manage_path)
+        self.browser.getLink("Download application slip").click()
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertMatches(
+            '...Your image file is corrupted. Please replace...',
+            self.browser.contents)
+
     def test_pay_portal_application_fee(self):
         self.login()
