Changeset 15947
- Timestamp:
- 23 Jan 2020, 14:35:44 (5 years ago)
- Location:
- main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/applicant.py
r15942 r15947 27 27 ICustomApplicant, ICustomUGApplicantEdit, ICustomPGApplicantEdit, IPUTMEApplicantEdit) 28 28 29 @grok.subscribe(ICustomApplicant, grok.IObjectRemovedEvent)30 def custom_handle_applicant_removed(applicant, event):31 """If an applicant is removed also pdf files of this applicant are removed.32 """33 file_store = getUtility(IExtFileStore)34 file_store.deleteFileByContext(applicant, attr='res_stat.pdf')35 return36 37 29 class CustomApplicant(NigeriaApplicant): 38 30 -
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser.py
r15942 r15947 26 26 from waeup.kofa.utils.helpers import string_from_bytes, file_size, now 27 27 from waeup.kofa.applicants.browser import ( 28 ApplicantRegistrationPage, ApplicantsContainerPage )28 ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile) 29 29 from waeup.kofa.applicants.interfaces import ( 30 30 ISpecialApplicant, IApplicantsContainer) … … 78 78 'aggregate') 79 79 80 def handle_file_upload(upload, context, view, attr=None):81 """Handle upload of applicant files.82 83 Returns `True` in case of success or `False`.84 85 Please note that file pointer passed in (`upload`) most probably86 points to end of file when leaving this function.87 """88 size = file_size(upload)89 if size > MAX_FILE_UPLOAD_SIZE:90 view.flash(_('Uploaded file is too big!'))91 return False92 dummy, ext = os.path.splitext(upload.filename)93 ext.lower()94 if ext != '.pdf':95 view.flash(_('pdf file extension expected.'))96 return False97 upload.seek(0) # file pointer moved when determining size98 store = getUtility(IExtFileStore)99 file_id = IFileStoreNameChooser(context).chooseName(attr=attr)100 store.createFile(file_id, upload)101 return True102 103 80 class CustomApplicantsContainerPage(ApplicantsContainerPage): 104 81 """The standard view for regular applicant containers. … … 121 98 """A display view for applicant data. 122 99 """ 123 124 @property125 def file_links(self):126 html = ''127 pdf = getUtility(IExtFileStore).getFileByContext(128 self.context, attr='res_stat.pdf')129 if pdf:130 html += '<a href="%s">Statement of Result</a>' % self.url(131 self.context, 'res_stat.pdf')132 return html133 100 134 101 @property … … 172 139 return form_fields 173 140 174 def update(self):175 super(CustomApplicantManageFormPage, self).update()176 upload_res_stat = self.request.form.get('form.res_stat', None)177 if upload_res_stat:178 # We got a fresh res_stat upload179 success = handle_file_upload(180 upload_res_stat, self.context, self, attr='res_stat.pdf')181 if success:182 self.context.writeLogMessage(self, 'saved: res_stat')183 else:184 self.upload_success = False185 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)186 return187 188 141 class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): 189 142 """An applicant-centered edit view for applicant data. 190 143 """ 144 145 def display_fileupload(self, filename): 146 if filename[1] == 'res_stat.pdf': 147 if self.context.subtype != 'transfer': 148 return False 149 return True 191 150 192 151 def dataNotComplete(self, data): … … 217 176 return form_fields 218 177 219 def update(self):220 if self.context.locked or (221 self.context.__parent__.expired and222 self.context.__parent__.strict_deadline):223 self.emit_lock_message()224 return225 super(CustomApplicantEditFormPage, self).update()226 upload_res_stat = self.request.form.get('form.res_stat', None)227 if upload_res_stat:228 # We got a fresh res_stat upload229 success = handle_file_upload(230 upload_res_stat, self.context, self, attr='res_stat.pdf')231 if not success:232 self.upload_success = False233 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)234 return235 236 178 class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): 237 179 … … 256 198 return form_fields 257 199 258 class ResultStatement( grok.View):200 class ResultStatement(AdditionalFile): 259 201 """Renders the pdf form extension for applicants. 260 202 """ 261 203 grok.name('res_stat.pdf') 262 grok.context(ICustomApplicant) 263 grok.require('waeup.viewApplication') 264 265 def render(self): 266 pdf = getUtility(IExtFileStore).getFileByContext( 267 self.context, attr='res_stat.pdf') 268 self.response.setHeader('Content-Type', 'application/pdf') 269 return pdf 204 205 class JAMBResult(AdditionalFile): 206 """Renders the pdf form extension for applicants. 207 """ 208 grok.name('jamb.pdf') -
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py
r15942 r15947 134 134 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 135 135 pseudo_pdf = StringIO(pdf_content) 136 ctrl = self.browser.getControl(name=' form.res_stat')136 ctrl = self.browser.getControl(name='res_stat.pdf') 137 137 file_ctrl = ctrl.mech_control 138 138 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') … … 167 167 self.assertTrue( 168 168 'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage' 169 ' - %s - saved: res_stat '169 ' - %s - saved: res_stat.pdf' 170 170 % (self.transapplicant.applicant_id) 171 171 in logcontent) -
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/utils.py
r15942 r15947 30 30 """ 31 31 32 #: A tuple of names of files to be copied over 33 #: to students section. 34 FILENAMES = ('res_stat.pdf',) 32 ADDITIONAL_FILES = (('Statement of Result','res_stat.pdf'), 33 ('JAMB Result','jamb.pdf')) 35 34 36 35 APP_TYPES_DICT = {
Note: See TracChangeset for help on using the changeset viewer.