Changeset 10105 for main/waeup.futminna
- Timestamp:
- 29 Apr 2013, 08:18:41 (12 years ago)
- Location:
- main/waeup.futminna/trunk/src/waeup/futminna/applicants
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser.py
r10096 r10105 82 82 html = '' 83 83 pdf = getUtility(IExtFileStore).getFileByContext( 84 self.context, attr=' formextension.pdf')84 self.context, attr='extraform.pdf') 85 85 if pdf: 86 html += '<a href="formextension.pdf">Offline Form Extension</a>' 86 html += '<a href="extraform.pdf">Extra Applicant Information Form</a>, ' 87 pdf = getUtility(IExtFileStore).getFileByContext( 88 self.context, attr='refereeform.pdf') 89 if pdf: 90 html += '<a href="refereeform.pdf">Referee\'s Form</a>' 87 91 return html 88 92 … … 113 117 def update(self): 114 118 super(CustomApplicantDisplayFormPage, self).update() 115 self.formextension_url = self.url(self.context, 'formextension.pdf') 119 self.extraform_url = self.url(self.context, 'extraform.pdf') 120 self.referreeform_url = self.url(self.context, 'refereeform.pdf') 116 121 return 117 122 … … 161 166 def update(self): 162 167 super(CustomApplicantManageFormPage, self).update() 163 upload_formextension = self.request.form.get('form.formextension', None) 164 if upload_formextension: 165 # We got a fresh formextension upload 166 self.upload_success = handle_file_upload( 167 upload_formextension, self.context, self, attr='formextension.pdf') 168 if self.upload_success: 169 self.context.writeLogMessage(self, 'saved: formextension') 168 upload_extraform = self.request.form.get('form.extraform', None) 169 if upload_extraform: 170 # We got a fresh extraform upload 171 success = handle_file_upload( 172 upload_extraform, self.context, self, attr='extraform.pdf') 173 if success: 174 self.context.writeLogMessage(self, 'saved: extraform') 175 else: 176 self.upload_success = False 177 upload_refereeform = self.request.form.get('form.refereeform', None) 178 if upload_refereeform: 179 # We got a fresh refereeform upload 180 success = handle_file_upload( 181 upload_refereeform, self.context, self, attr='refereeform.pdf') 182 if success: 183 self.context.writeLogMessage(self, 'saved: refereeform') 184 else: 185 self.upload_success = False 170 186 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE) 171 187 return … … 195 211 if not store.getFileByContext(self.context, attr=u'passport.jpg'): 196 212 return _('No passport picture uploaded.') 197 if not store.getFileByContext(self.context, attr=u'formextension.pdf'): 198 return _('No form extension pdf file uploaded.') 213 if not store.getFileByContext(self.context, attr=u'extraform.pdf'): 214 return _('No extra information form pdf file uploaded.') 215 if not store.getFileByContext(self.context, attr=u'refereeform.pdf'): 216 return _('No referee form pdf file uploaded.') 199 217 if not self.request.form.get('confirm_passport', False): 200 218 return _('Passport picture confirmation box not ticked.') … … 208 226 return 209 227 super(CustomApplicantEditFormPage, self).update() 210 upload_formextension = self.request.form.get('form.formextension', None) 211 if upload_formextension: 212 # We got a fresh formextension upload 213 self.upload_success = handle_file_upload( 214 upload_formextension, self.context, self, attr='formextension.pdf') 228 upload_extraform = self.request.form.get('form.extraform', None) 229 if upload_extraform: 230 # We got a fresh extraform upload 231 success = handle_file_upload( 232 upload_extraform, self.context, self, attr='extraform.pdf') 233 if not success: 234 self.upload_success = False 235 upload_refereeform = self.request.form.get('form.refereeform', None) 236 if upload_refereeform: 237 # We got a fresh refereeform upload 238 success = handle_file_upload( 239 upload_refereeform, self.context, self, attr='refereeform.pdf') 240 if not success: 241 self.upload_success = False 215 242 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE) 216 243 return 217 244 218 class FormExtension(grok.View):245 class ExtraForm(grok.View): 219 246 """Renders the pdf form extension for applicants. 220 247 """ 221 grok.name(' formextension.pdf')248 grok.name('extraform.pdf') 222 249 grok.context(ICustomApplicant) 223 250 grok.require('waeup.viewApplication') … … 225 252 def render(self): 226 253 pdf = getUtility(IExtFileStore).getFileByContext( 227 self.context, attr=' formextension.pdf')254 self.context, attr='extraform.pdf') 228 255 self.response.setHeader('Content-Type', 'application/pdf') 229 256 return pdf 257 258 class RefereeForm(grok.View): 259 """Renders the pdf referee's form for applicants. 260 """ 261 grok.name('refereeform.pdf') 262 grok.context(ICustomApplicant) 263 grok.require('waeup.viewApplication') 264 265 def render(self): 266 pdf = getUtility(IExtFileStore).getFileByContext( 267 self.context, attr='refereeform.pdf') 268 self.response.setHeader('Content-Type', 'application/pdf') 269 return pdf -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser_templates/applicanteditpage.pt
r10096 r10105 18 18 Download, fill, scan and re-upload the following forms: 19 19 </span> 20 <a href="https://futminna.waeup.org/downloads/ApplicationFormExtension.pdf"20 <a href="https://futminna.waeup.org/downloads/ExtraApplicantInformationForm.pdf" 21 21 i18n:translate=""> 22 Offline Form Extension 22 Extra Applicant Information Form</a>, 23 <a href="https://futminna.waeup.org/downloads/RefereeForm.pdf" 24 i18n:translate=""> 25 Referee's Form 23 26 </a><br /><br /> 24 27 </div> … … 48 51 <tr> 49 52 <td class="fieldname" i18n:translate=""> 50 Offline Form Extension:53 Extra Applicant Information Form: 51 54 </td> 52 55 <td> 53 <p tal:condition="python: view.file_exists(' formextension.pdf')">54 <a href=" formextension.pdf"56 <p tal:condition="python: view.file_exists('extraform.pdf')"> 57 <a href="extraform.pdf" 55 58 i18n:translate=""> 56 59 Download pdf file 57 60 </a> 58 61 </p> 59 <input type="file" name="form.formextension" /> 62 <input type="file" name="form.extraform" /> 63 <br /> 64 <span i18n:translate=""> 65 Max. file size: 66 </span> 67 <span tal:replace="view/max_file_upload_size">10 KB</span> 68 </tr> 69 <tr> 70 <td class="fieldname" i18n:translate=""> 71 Referee's Form: 72 </td> 73 <td> 74 <p tal:condition="python: view.file_exists('refereeform.pdf')"> 75 <a href="refereeform.pdf" 76 i18n:translate=""> 77 Download pdf file 78 </a> 79 </p> 80 <input type="file" name="form.refereeform" /> 60 81 <br /> 61 82 <span i18n:translate=""> -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/tests/test_browser.py
r10096 r10105 65 65 self.assertTrue(img is None) 66 66 67 def test_upload_ formextension_by_student(self):67 def test_upload_extraform_by_student(self): 68 68 self.login() 69 69 self.browser.open(self.edit_path) … … 71 71 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size 72 72 pseudo_pdf = StringIO(pdf_content) 73 ctrl = self.browser.getControl(name='form. formextension')73 ctrl = self.browser.getControl(name='form.extraform') 74 74 file_ctrl = ctrl.mech_control 75 75 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') … … 81 81 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 82 82 pseudo_pdf = StringIO(pdf_content) 83 ctrl = self.browser.getControl(name='form. formextension')84 file_ctrl = ctrl.mech_control 85 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 86 self.browser.getControl("Save").click() # submit form 87 # Even though the form could not be saved ... 88 self.assertTrue('Required input is missing' in self.browser.contents) 89 # ... the file has been successfully uploaded 90 pdf_url = self.edit_path.replace('edit', ' formextension.pdf')83 ctrl = self.browser.getControl(name='form.extraform') 84 file_ctrl = ctrl.mech_control 85 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 86 self.browser.getControl("Save").click() # submit form 87 # Even though the form could not be saved ... 88 self.assertTrue('Required input is missing' in self.browser.contents) 89 # ... the file has been successfully uploaded 90 pdf_url = self.edit_path.replace('edit', 'extraform.pdf') 91 91 self.browser.open(pdf_url) 92 92 self.assertEqual( … … 96 96 storage = getUtility(IExtFileStore) 97 97 file_id = IFileStoreNameChooser(self.applicant).chooseName( 98 attr=' formextension.pdf')99 # The stored file can be fetched 100 fd = storage.getFile(file_id) 101 file_len = len(fd.read()) 102 self.assertEqual(file_len, 307200) 103 # A file link is displayed on the edit view ... 104 self.browser.open(self.edit_path) 105 self.assertTrue('<a href=" formextension.pdf">' in self.browser.contents)106 # ... and on the dislay view 107 self.browser.open(self.view_path) 108 self.assertTrue('<a href=" formextension.pdf">Offline Form Extension</a>'109 in self.browser.contents) 110 111 def test_upload_ formextension_by_manager(self):98 attr='extraform.pdf') 99 # The stored file can be fetched 100 fd = storage.getFile(file_id) 101 file_len = len(fd.read()) 102 self.assertEqual(file_len, 307200) 103 # A file link is displayed on the edit view ... 104 self.browser.open(self.edit_path) 105 self.assertTrue('<a href="extraform.pdf">' in self.browser.contents) 106 # ... and on the dislay view 107 self.browser.open(self.view_path) 108 self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>' 109 in self.browser.contents) 110 111 def test_upload_extraform_by_manager(self): 112 112 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 113 113 self.browser.open(self.manage_path) … … 115 115 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 116 116 pseudo_pdf = StringIO(pdf_content) 117 ctrl = self.browser.getControl(name='form. formextension')118 file_ctrl = ctrl.mech_control 119 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 120 self.browser.getControl("Save").click() # submit form 121 # Even though the form could not be saved ... 122 self.assertTrue('Required input is missing' in self.browser.contents) 123 # ... the file has been successfully uploaded 124 pdf_url = self.manage_path.replace('manage', ' formextension.pdf')117 ctrl = self.browser.getControl(name='form.extraform') 118 file_ctrl = ctrl.mech_control 119 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 120 self.browser.getControl("Save").click() # submit form 121 # Even though the form could not be saved ... 122 self.assertTrue('Required input is missing' in self.browser.contents) 123 # ... the file has been successfully uploaded 124 pdf_url = self.manage_path.replace('manage', 'extraform.pdf') 125 125 self.browser.open(pdf_url) 126 126 self.assertEqual( … … 130 130 storage = getUtility(IExtFileStore) 131 131 file_id = IFileStoreNameChooser(self.applicant).chooseName( 132 attr=' formextension.pdf')133 # The stored file can be fetched 134 fd = storage.getFile(file_id) 135 file_len = len(fd.read()) 136 self.assertEqual(file_len, 307200) 137 # A file link is displayed on the edit view ... 138 self.browser.open(self.manage_path) 139 self.assertTrue('<a href=" formextension.pdf">' in self.browser.contents)140 # ... and on the dislay view 141 self.browser.open(self.view_path) 142 self.assertTrue('<a href=" formextension.pdf">Offline Form Extension</a>'132 attr='extraform.pdf') 133 # The stored file can be fetched 134 fd = storage.getFile(file_id) 135 file_len = len(fd.read()) 136 self.assertEqual(file_len, 307200) 137 # A file link is displayed on the edit view ... 138 self.browser.open(self.manage_path) 139 self.assertTrue('<a href="extraform.pdf">' in self.browser.contents) 140 # ... and on the dislay view 141 self.browser.open(self.view_path) 142 self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>' 143 143 in self.browser.contents) 144 144 # Adding file is properly logged … … 148 148 self.assertTrue( 149 149 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 150 ' - %s - saved: formextension'150 ' - %s - saved: extraform' 151 151 % (self.applicant.applicant_id) 152 152 in logcontent) 153 154 def test_upload_refereeform_by_student(self): 155 self.login() 156 self.browser.open(self.edit_path) 157 # Create a pseudo file and select it to be uploaded in form 158 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size 159 pseudo_pdf = StringIO(pdf_content) 160 ctrl = self.browser.getControl(name='form.refereeform') 161 file_ctrl = ctrl.mech_control 162 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 163 self.browser.getControl("Save").click() # submit form 164 # We get a warning message 165 self.assertTrue( 166 'Uploaded file is too big' in self.browser.contents) 167 # Create a pseudo file with acceptable size 168 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 169 pseudo_pdf = StringIO(pdf_content) 170 ctrl = self.browser.getControl(name='form.refereeform') 171 file_ctrl = ctrl.mech_control 172 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 173 self.browser.getControl("Save").click() # submit form 174 # Even though the form could not be saved ... 175 self.assertTrue('Required input is missing' in self.browser.contents) 176 # ... the file has been successfully uploaded 177 pdf_url = self.edit_path.replace('edit', 'refereeform.pdf') 178 self.browser.open(pdf_url) 179 self.assertEqual( 180 self.browser.headers['content-type'], 'application/pdf') 181 self.assertEqual(len(self.browser.contents), 307200) 182 # There is really a file stored for the applicant 183 storage = getUtility(IExtFileStore) 184 file_id = IFileStoreNameChooser(self.applicant).chooseName( 185 attr='refereeform.pdf') 186 # The stored file can be fetched 187 fd = storage.getFile(file_id) 188 file_len = len(fd.read()) 189 self.assertEqual(file_len, 307200) 190 # A file link is displayed on the edit view ... 191 self.browser.open(self.edit_path) 192 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents) 193 # ... and on the dislay view 194 self.browser.open(self.view_path) 195 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>' 196 in self.browser.contents) 197 198 def test_upload_refereeform_by_manager(self): 199 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 200 self.browser.open(self.manage_path) 201 # Create a pseudo file with acceptable size 202 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 203 pseudo_pdf = StringIO(pdf_content) 204 ctrl = self.browser.getControl(name='form.refereeform') 205 file_ctrl = ctrl.mech_control 206 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 207 self.browser.getControl("Save").click() # submit form 208 # Even though the form could not be saved ... 209 self.assertTrue('Required input is missing' in self.browser.contents) 210 # ... the file has been successfully uploaded 211 pdf_url = self.manage_path.replace('manage', 'refereeform.pdf') 212 self.browser.open(pdf_url) 213 self.assertEqual( 214 self.browser.headers['content-type'], 'application/pdf') 215 self.assertEqual(len(self.browser.contents), 307200) 216 # There is rally a file stored for the applicant 217 storage = getUtility(IExtFileStore) 218 file_id = IFileStoreNameChooser(self.applicant).chooseName( 219 attr='refereeform.pdf') 220 # The stored file can be fetched 221 fd = storage.getFile(file_id) 222 file_len = len(fd.read()) 223 self.assertEqual(file_len, 307200) 224 # A file link is displayed on the edit view ... 225 self.browser.open(self.manage_path) 226 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents) 227 # ... and on the dislay view 228 self.browser.open(self.view_path) 229 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>' 230 in self.browser.contents) 231 # Adding file is properly logged 232 logfile = os.path.join( 233 self.app['datacenter'].storage, 'logs', 'applicants.log') 234 logcontent = open(logfile).read() 235 self.assertTrue( 236 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 237 ' - %s - saved: refereeform' 238 % (self.applicant.applicant_id) 239 in logcontent)
Note: See TracChangeset for help on using the changeset viewer.