Changeset 10096 for main/waeup.futminna/trunk/src
- Timestamp:
- 23 Apr 2013, 09:45:04 (12 years ago)
- Location:
- main/waeup.futminna/trunk/src/waeup/futminna/applicants
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser.py
r10088 r10096 19 19 """ 20 20 import grok 21 import os 22 from zope.component import getUtility 23 from waeup.kofa.interfaces import ( 24 IExtFileStore, IFileStoreNameChooser) 21 25 from zope.formlib.textwidgets import BytesDisplayWidget 26 from waeup.kofa.utils.helpers import string_from_bytes, file_size 22 27 from waeup.futminna.applicants.interfaces import ( 28 ICustomApplicant, 23 29 ICustomUGApplicant, 24 30 ICustomPGApplicant, … … 34 40 PG_OMIT_EDIT_FIELDS, 35 41 ) 42 from waeup.futminna.interfaces import MessageFactory as _ 36 43 from kofacustom.nigeria.applicants.browser import ( 37 44 NigeriaApplicantDisplayFormPage, … … 40 47 NigeriaPDFApplicationSlip) 41 48 49 MAX_FILE_UPLOAD_SIZE = 1024 * 500 50 51 def handle_file_upload(upload, context, view, attr=None): 52 """Handle upload of applicant files. 53 54 Returns `True` in case of success or `False`. 55 56 Please note that file pointer passed in (`upload`) most probably 57 points to end of file when leaving this function. 58 """ 59 size = file_size(upload) 60 if size > MAX_FILE_UPLOAD_SIZE: 61 view.flash(_('Uploaded file is too big!')) 62 return False 63 dummy, ext = os.path.splitext(upload.filename) 64 ext.lower() 65 if ext != '.pdf': 66 view.flash(_('pdf file extension expected.')) 67 return False 68 upload.seek(0) # file pointer moved when determining size 69 store = getUtility(IExtFileStore) 70 file_id = IFileStoreNameChooser(context).chooseName(attr=attr) 71 store.createFile(file_id, upload) 72 return True 42 73 43 74 class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): … … 48 79 49 80 @property 81 def file_links(self): 82 html = '' 83 pdf = getUtility(IExtFileStore).getFileByContext( 84 self.context, attr='formextension.pdf') 85 if pdf: 86 html += '<a href="formextension.pdf">Offline Form Extension</a>' 87 return html 88 89 @property 50 90 def form_fields(self): 51 91 target = getattr(self.context.__parent__, 'prefix', None) … … 58 98 for field in UG_OMIT_DISPLAY_FIELDS: 59 99 form_fields = form_fields.omit(field) 60 form_fields['perm_address'].custom_widget = BytesDisplayWidget 100 if form_fields.get('perm_address', None): 101 form_fields['perm_address'].custom_widget = BytesDisplayWidget 61 102 form_fields['notice'].custom_widget = BytesDisplayWidget 62 103 if not getattr(self.context, 'student_id'): … … 70 111 return form_fields 71 112 113 def update(self): 114 super(CustomApplicantDisplayFormPage, self).update() 115 self.formextension_url = self.url(self.context, 'formextension.pdf') 116 return 117 72 118 class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): 73 119 … … 96 142 """A full edit view for applicant data. 97 143 """ 98 144 grok.template('applicanteditpage') 145 99 146 @property 100 147 def form_fields(self): … … 112 159 return form_fields 113 160 161 def update(self): 162 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') 170 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE) 171 return 172 114 173 class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): 115 174 """An applicant-centered edit view for applicant data. 116 175 """ 176 grok.template('applicanteditpage') 117 177 118 178 @property … … 130 190 form_fields['reg_number'].for_display = True 131 191 return form_fields 192 193 def dataNotComplete(self): 194 store = getUtility(IExtFileStore) 195 if not store.getFileByContext(self.context, attr=u'passport.jpg'): 196 return _('No passport picture uploaded.') 197 if not store.getFileByContext(self.context, attr=u'formextension.pdf'): 198 return _('No form extension pdf file uploaded.') 199 if not self.request.form.get('confirm_passport', False): 200 return _('Passport picture confirmation box not ticked.') 201 return False 202 203 def update(self): 204 if self.context.locked or ( 205 self.context.__parent__.expired and 206 self.context.__parent__.strict_deadline): 207 self.emit_lock_message() 208 return 209 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') 215 self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE) 216 return 217 218 class FormExtension(grok.View): 219 """Renders the pdf form extension for applicants. 220 """ 221 grok.name('formextension.pdf') 222 grok.context(ICustomApplicant) 223 grok.require('waeup.viewApplication') 224 225 def render(self): 226 pdf = getUtility(IExtFileStore).getFileByContext( 227 self.context, attr='formextension.pdf') 228 self.response.setHeader('Content-Type', 'application/pdf') 229 return pdf -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser_templates/applicantdisplaypage.pt
r10088 r10096 36 36 </td> 37 37 <tr> 38 <tr> 39 <td class="fieldname" i18n:translate=""> 40 Files: 41 </td> 42 <td> 43 <span tal:replace="structure view/file_links" /> 44 </td> 45 </tr> 38 46 </tbody> 39 47 </table> -
main/waeup.futminna/trunk/src/waeup/futminna/applicants/interfaces.py
r10088 r10096 136 136 """ 137 137 138 class ICustomUGApplicantEdit(I NigeriaUGApplicantEdit):138 class ICustomUGApplicantEdit(ICustomUGApplicant): 139 139 """An undergraduate applicant interface for edit forms. 140 140 … … 148 148 """ 149 149 150 class ICustomPGApplicantEdit(I NigeriaPGApplicantEdit):150 class ICustomPGApplicantEdit(ICustomPGApplicant): 151 151 """A postgraduate applicant interface for editing. 152 152 … … 160 160 """ 161 161 162 162 163 class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment): 163 164 """An applicant payment via payment gateways. 164 165 165 """166 167 class IPUTMEApplicantEdit(IPUTMEApplicantEdit):168 """An undergraduate applicant interface for editing.169 170 Here we can repeat the fields from base data and set the171 `required` and `readonly` attributes to True to further restrict172 the data access. Or we can allow only certain certificates to be173 selected by choosing the appropriate source.174 175 We cannot omit fields here. This has to be done in the176 respective form page.177 166 """ 178 167
Note: See TracChangeset for help on using the changeset viewer.