Changeset 15948 for main/waeup.aaue/trunk/src/waeup/aaue
- Timestamp:
- 23 Jan 2020, 21:13:14 (5 years ago)
- Location:
- main/waeup.aaue/trunk/src/waeup/aaue
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser.py
r15841 r15948 28 28 from waeup.kofa.utils.helpers import string_from_bytes, file_size 29 29 from waeup.kofa.applicants.browser import ( 30 ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage) 30 ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage, 31 AdditionalFile) 31 32 from waeup.kofa.applicants.workflow import STARTED, PAID 32 33 from waeup.kofa.applicants.viewlets import PDFActionButton … … 228 229 MAX_FILE_UPLOAD_SIZE = 1024 * 500 229 230 230 def handle_file_upload(upload, context, view, attr=None):231 """Handle upload of applicant files.232 233 Returns `True` in case of success or `False`.234 235 Please note that file pointer passed in (`upload`) most probably236 points to end of file when leaving this function.237 """238 size = file_size(upload)239 if size > MAX_FILE_UPLOAD_SIZE:240 view.flash(_('Uploaded file is too big!'))241 return False242 dummy, ext = os.path.splitext(upload.filename)243 ext.lower()244 if ext != '.pdf':245 view.flash(_('pdf file extension expected.'))246 return False247 upload.seek(0) # file pointer moved when determining size248 store = getUtility(IExtFileStore)249 file_id = IFileStoreNameChooser(context).chooseName(attr=attr)250 store.createFile(file_id, upload)251 return True252 253 231 class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): 254 232 """A display view for applicant data. 255 233 """ 256 257 @property258 def file_links(self):259 html = ''260 pdf = getUtility(IExtFileStore).getFileByContext(261 self.context, attr='stateresult.pdf')262 if pdf:263 html += '<a href="%s">Statement of Result</a>' % self.url(264 self.context, 'stateresult.pdf')265 pdf = getUtility(IExtFileStore).getFileByContext(266 self.context, attr='verificationdoc.pdf')267 if pdf:268 html += '<a href="%s">Result/Certificate Document</a>' % self.url(269 self.context, 'verificationdoc.pdf')270 return html271 234 272 235 @property … … 335 298 return '<a href="%s">%s - %s</a>' %(url,code,title) 336 299 return '' 337 338 #def update(self):339 # super(CustomApplicantDisplayFormPage, self).update()340 # #self.extraform_url = self.url(self.context, 'stateresult.pdf')341 # return342 300 343 301 class CustomPDFActionButton(PDFActionButton): … … 430 388 """ 431 389 390 def display_fileupload(self, filename): 391 if filename[1] == 'stateresult.pdf': 392 if self.target in ('trans', 'cert'): 393 return True 394 if filename[1] == 'verificationdoc.pdf': 395 if self.target in ('ver', 'send'): 396 return True 397 return False 398 432 399 @property 433 400 def form_fields(self): … … 466 433 return form_fields 467 434 468 def update(self):469 super(CustomApplicantManageFormPage, self).update()470 upload_stateresult = self.request.form.get('form.stateresult', None)471 upload_verificationdoc = self.request.form.get('form.verificationdoc', None)472 if upload_stateresult:473 # We got a fresh stateresult upload474 success = handle_file_upload(475 upload_stateresult, self.context, self, attr='stateresult.pdf')476 if success:477 self.context.writeLogMessage(self, 'saved: stateresult')478 else:479 self.upload_success = False480 if upload_verificationdoc:481 # We got a fresh verificationdoc upload482 success = handle_file_upload(483 upload_verificationdoc, self.context, self, attr='verificationdoc.pdf')484 if success:485 self.context.writeLogMessage(self, 'saved: verificationdoc')486 else:487 self.upload_success = False488 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)489 return490 491 435 class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): 492 436 """An applicant-centered edit view for applicant data. 493 437 """ 438 439 def display_fileupload(self, filename): 440 if filename[1] == 'stateresult.pdf': 441 if self.target in ('trans', 'cert'): 442 return True 443 if filename[1] == 'verificationdoc.pdf': 444 if self.target in ('ver', 'send'): 445 return True 446 return False 494 447 495 448 def unremovable(self, ticket): … … 625 578 return 626 579 super(CustomApplicantEditFormPage, self).update() 627 upload_stateresult = self.request.form.get('form.stateresult', None)628 upload_verificationdoc = self.request.form.get('form.verificationdoc', None)629 if upload_stateresult:630 # We got a fresh stateresult upload631 success = handle_file_upload(632 upload_stateresult, self.context, self, attr='stateresult.pdf')633 if not success:634 self.upload_success = False635 if upload_verificationdoc:636 # We got a fresh verificationdoc upload637 success = handle_file_upload(638 upload_verificationdoc, self.context, self, attr='verificationdoc.pdf')639 if not success:640 self.upload_success = False641 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)642 580 return 643 581 … … 769 707 self.context, applicantview, note=self.note) 770 708 771 class StateResult( grok.View):709 class StateResult(AdditionalFile): 772 710 """Renders the pdf form extension for applicants. 773 711 """ 774 712 grok.name('stateresult.pdf') 775 grok.context(ICustomApplicant) 776 grok.require('waeup.viewApplication') 777 778 def render(self): 779 pdf = getUtility(IExtFileStore).getFileByContext( 780 self.context, attr='stateresult.pdf') 781 self.response.setHeader('Content-Type', 'application/pdf') 782 return pdf 783 784 class VerificationDoc(grok.View): 713 714 class VerificationDoc(AdditionalFile): 785 715 """Renders the pdf form extension for applicants. 786 716 """ 787 717 grok.name('verificationdoc.pdf') 788 grok.context(ICustomApplicant)789 grok.require('waeup.viewApplication')790 791 def render(self):792 pdf = getUtility(IExtFileStore).getFileByContext(793 self.context, attr='verificationdoc.pdf')794 self.response.setHeader('Content-Type', 'application/pdf')795 return pdf -
main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser_templates/applicanteditpage.pt
r15735 r15948 3 3 autocomplete="off"> 4 4 5 <h2 i18n:domain="waeup.kofa" >5 <h2 i18n:domain="waeup.kofa" tal:condition="context/translated_state"> 6 6 ... 7 7 <span tal:replace="context/translated_state">APPLICATIONSTATE … … 13 13 </h2> 14 14 15 <div class="workflow" >15 <div class="workflow" tal:condition="context/history"> 16 16 <div tal:repeat="msg context/history/messages"> 17 17 <span tal:replace="msg">MESSAGE</span><br /> … … 43 43 <span tal:replace="view/max_upload_size">10 KB</span> 44 44 </tr> 45 <tr tal:condition="python: view.target in ('trans', 'cert')"> 46 <td class="fieldname" i18n:translate=""> 47 Statement of Result: 48 </td> 49 <td> 50 <p tal:condition="python: view.file_exists('stateresult.pdf')"> 51 <a href="stateresult.pdf" 52 i18n:translate=""> 53 Download pdf file 54 </a> 55 </p> 56 <div class="input-group half"> 57 <div class="input-group-btn"> 58 <div class="btn btn-default btn-file"> 59 Select… 60 <input type="file" name="form.stateresult" /> 45 46 <tal:files> 47 <tr tal:repeat="filename view/additional_files"> 48 <tal:cond tal:condition="python:view.display_fileupload(filename)"> 49 <td class="fieldname"> 50 <span tal:replace="python:filename[0]">FILENAME</span>: 51 </td> 52 <td> 53 <p tal:condition="python:view.file_exists(filename[1])"> 54 <a tal:attributes="href python:filename[1]"i18n:translate=""> 55 Download pdf file 56 </a> 57 </p> 58 <div class="input-group half"> 59 <div class="input-group-btn"> 60 <div class="btn btn-default btn-file"> 61 Select… 62 <input type="file" tal:attributes="name python:filename[1]" /> 63 </div> 64 </div> 65 <input type="text" class="form-control" readonly> 61 66 </div> 62 </div> 63 <input type="text" class="form-control" readonly> 64 </div> 65 <span i18n:translate=""> 66 PDF files only. Max. file size: 67 </span> 68 <span tal:replace="view/max_file_upload_size">10 KB</span> 69 </tr> 70 <tr tal:condition="python: view.target in ('ver', 'send')"> 71 <td class="fieldname" i18n:translate=""> 72 Scanned Document: 73 </td> 74 <td> 75 <p tal:condition="python: view.file_exists('verificationdoc.pdf')"> 76 <a href="verificationdoc.pdf" 77 i18n:translate=""> 78 Download pdf file 79 </a> 80 </p> 81 <div class="input-group half"> 82 <div class="input-group-btn"> 83 <div class="btn btn-default btn-file"> 84 Select… 85 <input type="file" name="form.verificationdoc" /> 86 </div> 87 </div> 88 <input type="text" class="form-control" readonly> 89 </div> 90 <span i18n:translate=""> 91 PDF files only. Max. file size: 92 </span> 93 <span tal:replace="view/max_file_upload_size">10 KB</span> 94 </tr> 67 <span i18n:translate=""> 68 PDF files only. Max. file size: 69 </span> 70 <span tal:replace="view/max_file_upload_size">10 KB</span> 71 </td> 72 </tal:cond> 73 </tr> 74 </tal:files> 75 95 76 <tr tal:condition="view/manage_applications"> 96 77 <td class="fieldname" i18n:translate="">Password:</td> … … 141 122 <span i18n:translate=""> 142 123 I hereby confirm that the Passport Photograph uploaded on this form is a 143 true picture of me. 124 true picture of me. 144 125 </span> 145 126 </div> … … 153 134 </span> 154 135 </div> 136 137 <tal:refereereports condition="view/display_refereereports"> 138 <br /><br /> 139 <h3 i18n:translate=""> 140 Referee Reports 141 </h3> 142 <table i18n:domain="waeup.kofa" class="table table-condensed"> 143 <thead> 144 <tr> 145 <th i18n:translate="">Report Id</th> 146 <th i18n:translate="">Creation Date</th> 147 <th i18n:translate="">Referee</th> 148 <th i18n:translate="">Email Address</th> 149 </tr> 150 </thead> 151 <tbody> 152 <tr tal:repeat="cl context/refereereports"> 153 <td> <a tal:attributes="href python:view.url(cl)"> 154 <span tal:content="cl/r_id">RID</span></a></td> 155 <td tal:content="python: layout.formatDatetime(cl.creation_date)">CREATION DATE</td> 156 <td tal:content="cl/name">REFEREE</td> 157 <td tal:content="cl/email">EMAIL</td> 158 </tr> 159 </tbody> 160 </table> 161 </tal:refereereports> 155 162 156 163 <tal:payments condition="view/display_payments"> … … 175 182 <tr tal:repeat="cl context/payments"> 176 183 <td> 177 <input type="checkbox" name="val_id"178 184 <input type="checkbox" name="val_id" 185 tal:attributes="value cl/__name__" 179 186 tal:condition="python: not view.unremovable(cl)" /> 180 187 </td> -
main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py
r15867 r15948 346 346 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 347 347 pseudo_pdf = StringIO(pdf_content) 348 ctrl = self.browser.getControl(name=' form.stateresult')348 ctrl = self.browser.getControl(name='stateresult.pdf') 349 349 file_ctrl = ctrl.mech_control 350 350 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') … … 418 418 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 419 419 pseudo_pdf = StringIO(pdf_content) 420 ctrl = self.browser.getControl(name=' form.verificationdoc')420 ctrl = self.browser.getControl(name='verificationdoc.pdf') 421 421 file_ctrl = ctrl.mech_control 422 422 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') -
main/waeup.aaue/trunk/src/waeup/aaue/applicants/utils.py
r15531 r15948 27 27 """A collection of parameters and methods subject to customization. 28 28 """ 29 30 ADDITIONAL_FILES = (('Statement of Result','stateresult.pdf'), 31 ('Result/Certificate Document','verificationdoc.pdf')) 29 32 30 33 APP_TYPES_DICT = { -
main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py
r15927 r15948 350 350 xmldict['institution_amt'] = 100 * ( 351 351 gateway_net_amt(self.context.amount_auth)) 352 353 354 352 elif self.context.p_category == 'schoolfee_2': 355 353 xmldict['institution_amt'] = 100 * gateway_net_amt( -
main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py
r15925 r15948 602 602 'accommodationpayments', 603 603 'transcriptdata') 604 605 # Maximum size of upload files in kB 606 MAX_KB = 500
Note: See TracChangeset for help on using the changeset viewer.