Changeset 10224
- Timestamp:
- 24 May 2013, 08:23:16 (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
r10220 r10224 38 38 PG_OMIT_PDF_FIELDS, 39 39 PG_OMIT_MANAGE_FIELDS, 40 PG_OMIT_EDIT_FIELDS, 40 41 PUTME_OMIT_EDIT_FIELDS, 41 42 PUTME_OMIT_DISPLAY_FIELDS, … … 101 102 @property 102 103 def form_fields(self): 103 target = getattr(self.context.__parent__, 'prefix', None) 104 if target is not None and target.startswith('pg'): 104 if self.target is not None and self.target.startswith('pg'): 105 105 form_fields = grok.AutoFields(ICustomPGApplicant) 106 106 for field in PG_OMIT_DISPLAY_FIELDS: … … 136 136 @property 137 137 def form_fields(self): 138 target = getattr(self.context.__parent__, 'prefix', None) 139 if target is not None and target.startswith('pg'): 138 if self.target is not None and self.target.startswith('pg'): 140 139 form_fields = grok.AutoFields(ICustomPGApplicant) 141 140 for field in PG_OMIT_PDF_FIELDS: 142 141 form_fields = form_fields.omit(field) 143 elif target is not None andtarget.startswith('putme'):142 elif self.target is not None and self.target.startswith('putme'): 144 143 form_fields = grok.AutoFields(ICustomUGApplicant) 145 144 if self._reduced_slip(): … … 169 168 @property 170 169 def form_fields(self): 171 target = getattr(self.context.__parent__, 'prefix', None) 172 if target is not None and target.startswith('pg'): 170 if self.target is not None and self.target.startswith('pg'): 173 171 form_fields = grok.AutoFields(ICustomPGApplicant) 174 172 for field in PG_OMIT_MANAGE_FIELDS: 175 173 form_fields = form_fields.omit(field) 176 elif target is not None andtarget.startswith('putme'):174 elif self.target is not None and self.target.startswith('putme'): 177 175 form_fields = grok.AutoFields(ICustomUGApplicant) 178 176 for field in PUTME_OMIT_MANAGE_FIELDS: … … 225 223 @property 226 224 def form_fields(self): 227 target = getattr(self.context.__parent__, 'prefix', None) 228 if target is not None and target.startswith('pg'): 225 if self.target is not None and self.target.startswith('pg'): 229 226 form_fields = grok.AutoFields(ICustomPGApplicantEdit) 230 227 for field in PG_OMIT_EDIT_FIELDS: 231 228 form_fields = form_fields.omit(field) 232 elif target is not None andtarget.startswith('putme'):229 elif self.target is not None and self.target.startswith('putme'): 233 230 form_fields = grok.AutoFields(ICustomUGApplicantEdit) 234 231 for field in PUTME_OMIT_EDIT_FIELDS: … … 252 249 if not store.getFileByContext(self.context, attr=u'refereeform.pdf'): 253 250 return _('No referee form pdf file uploaded.') 254 if not store.getFileByContext(self.context, attr=u'credentialform.pdf'): 251 if self.target is not None and self.target.startswith('pg') \ 252 and not store.getFileByContext(self.context, attr=u'credentialform.pdf'): 255 253 return _('No credential form pdf file uploaded.') 256 254 if not self.request.form.get('confirm_passport', False): -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser_templates/applicanteditpage.pt
r10220 r10224 85 85 <span tal:replace="view/max_file_upload_size">10 KB</span> 86 86 </tr> 87 <tr >87 <tr tal:condition="python: view.target.startswith('pg')"> 88 88 <td class="fieldname" i18n:translate=""> 89 89 Credential Form: -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/tests/test_browser.py
r10220 r10224 21 21 22 22 import os 23 import pytz 23 24 import grok 25 from datetime import datetime, date, timedelta 24 26 from zope.event import notify 25 27 from StringIO import StringIO 26 28 from zope.component import createObject, getUtility 29 from waeup.kofa.applicants.container import ApplicantsContainer 27 30 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup 28 31 from waeup.kofa.interfaces import ( … … 249 252 self.assertTrue(fd is None) 250 253 251 def test_upload_credentialform_by_student(self):252 self.login()253 self.browser.open(self.edit_path)254 # Create a pseudo file and select it to be uploaded in form255 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size256 pseudo_pdf = StringIO(pdf_content)257 ctrl = self.browser.getControl(name='form.credentialform')258 file_ctrl = ctrl.mech_control259 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')260 self.browser.getControl("Save").click() # submit form261 # We get a warning message262 self.assertTrue(263 'Uploaded file is too big' in self.browser.contents)264 # Create a pseudo file with acceptable size265 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size266 pseudo_pdf = StringIO(pdf_content)267 ctrl = self.browser.getControl(name='form.credentialform')268 file_ctrl = ctrl.mech_control269 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')270 self.browser.getControl("Save").click() # submit form271 # Even though the form could not be saved ...272 self.assertTrue('Required input is missing' in self.browser.contents)273 # ... the file has been successfully uploaded274 pdf_url = self.edit_path.replace('edit', 'credentialform.pdf')275 self.browser.open(pdf_url)276 self.assertEqual(277 self.browser.headers['content-type'], 'application/pdf')278 self.assertEqual(len(self.browser.contents), 307200)279 # There is really a file stored for the applicant280 storage = getUtility(IExtFileStore)281 file_id = IFileStoreNameChooser(self.applicant).chooseName(282 attr='credentialform.pdf')283 # The stored file can be fetched284 fd = storage.getFile(file_id)285 file_len = len(fd.read())286 self.assertEqual(file_len, 307200)287 # A file link is displayed on the edit view ...288 self.browser.open(self.edit_path)289 self.assertTrue('<a href="credentialform.pdf">' in self.browser.contents)290 # ... and on the dislay view291 self.browser.open(self.view_path)292 self.assertTrue('<a href="credentialform.pdf">Credential Form</a>'293 in self.browser.contents)294 295 254 def test_upload_credentialform_by_manager(self): 296 255 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 299 258 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 300 259 pseudo_pdf = StringIO(pdf_content) 260 # This is a ug applicant, thus the credential form is not 261 # required 262 self.assertFalse('credentialform">' in self.browser.contents) 263 264 # We have to add a pg applicants container 265 container_name = u'pg%s' % (datetime.now().year - 1) 266 applicantscontainer = ApplicantsContainer() 267 applicantscontainer.code = container_name 268 applicantscontainer.prefix = 'pgft' 269 applicantscontainer.year = datetime.now().year - 1 270 applicantscontainer.title = u'This is the %s container' % container_name 271 applicantscontainer.application_category = 'pg_ft' 272 applicantscontainer.mode = 'create' 273 applicantscontainer.strict_deadline = True 274 delta = timedelta(days=10) 275 applicantscontainer.startdate = datetime.now(pytz.utc) - delta 276 applicantscontainer.enddate = datetime.now(pytz.utc) + delta 277 self.app['applicants'][container_name] = applicantscontainer 278 applicant = createObject('waeup.Applicant') 279 # reg_number is the only field which has to be preset here 280 # because managers are allowed to edit this required field 281 applicant.reg_number = u'2345' 282 applicant.course1 = self.certificate 283 self.app['applicants'][container_name].addApplicant(applicant) 284 self.manage_path_pg = 'http://localhost/app/applicants/%s/%s/%s' % ( 285 container_name, applicant.application_number, 'manage') 286 self.view_path_pg = 'http://localhost/app/applicants/%s/%s' % ( 287 container_name, applicant.application_number) 288 289 self.browser.open(self.manage_path_pg) 301 290 ctrl = self.browser.getControl(name='form.credentialform') 302 291 file_ctrl = ctrl.mech_control … … 306 295 self.assertTrue('Required input is missing' in self.browser.contents) 307 296 # ... the file has been successfully uploaded 308 pdf_url = self.manage_path .replace('manage', 'credentialform.pdf')297 pdf_url = self.manage_path_pg.replace('manage', 'credentialform.pdf') 309 298 self.browser.open(pdf_url) 310 299 self.assertEqual( … … 313 302 # There is rally a file stored for the applicant 314 303 storage = getUtility(IExtFileStore) 315 file_id = IFileStoreNameChooser( self.applicant).chooseName(304 file_id = IFileStoreNameChooser(applicant).chooseName( 316 305 attr='credentialform.pdf') 317 306 # The stored file can be fetched … … 320 309 self.assertEqual(file_len, 307200) 321 310 # A file link is displayed on the edit view ... 322 self.browser.open(self.manage_path )311 self.browser.open(self.manage_path_pg) 323 312 self.assertTrue('<a href="credentialform.pdf">' in self.browser.contents) 324 313 # ... and on the dislay view 325 self.browser.open(self.view_path )314 self.browser.open(self.view_path_pg) 326 315 self.assertTrue('<a href="credentialform.pdf">Credential Form</a>' 327 316 in self.browser.contents) … … 333 322 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 334 323 ' - %s - saved: credentialform' 335 % ( self.applicant.applicant_id)324 % (applicant.applicant_id) 336 325 in logcontent) 337 326 # When an applicant is removed, also the pdf files are gone. 338 del self.app['applicants'][ 'app2011'][self.applicant.application_number]327 del self.app['applicants'][container_name][applicant.application_number] 339 328 fd = storage.getFile(file_id) 340 329 self.assertTrue(fd is None)
Note: See TracChangeset for help on using the changeset viewer.