Changeset 7106 for main/waeup.sirp/trunk
- Timestamp:
- 13 Nov 2011, 20:13:07 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/filedisplay.pt
r7098 r7106 7 7 <td class="field"> 8 8 <span class="widget"> 9 <a tal:attributes="href viewlet/ img_src"10 tal:content="viewlet/ img_src"9 <a tal:attributes="href viewlet/download_name" 10 tal:content="viewlet/download_name" 11 11 target="image"> 12 12 LINK -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/fileupload.pt
r7098 r7106 7 7 <td class="field"> 8 8 <span class="widget"> 9 <a tal:attributes="href viewlet/ img_src"10 tal:content="viewlet/ img_src"9 <a tal:attributes="href viewlet/download_name" 10 tal:content="viewlet/download_name" 11 11 target="image"> 12 12 LINK -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/imagedisplay.pt
r7098 r7106 7 7 <td class="field"> 8 8 <span class="widget"> 9 <img tal:attributes="src viewlet/ img_src" /><br />9 <img tal:attributes="src viewlet/download_name" /><br /> 10 10 </span> 11 11 </td> -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/imageupload.pt
r7098 r7106 7 7 <td class="field"> 8 8 <span class="widget"> 9 <img tal:attributes="src viewlet/ img_src" /><br />9 <img tal:attributes="src viewlet/download_name" /><br /> 10 10 <input type="file" tal:attributes="name viewlet/input_name"/> 11 11 <br /> -
main/waeup.sirp/trunk/src/waeup/sirp/students/student.py
r7105 r7106 177 177 return name == self.chooseName() 178 178 179 def chooseName(self, name=None, attr=None):179 def chooseName(self, attr, name=None): 180 180 """Get a valid file id for student context. 181 181 … … 183 183 184 184 For a student with student id ``'A123456'`` and 185 with attr ``'nice_image '`` stored in185 with attr ``'nice_image.jpeg'`` stored in 186 186 the students container this chooser would create: 187 187 188 ``'__file-student__students/A/A123456/nice_image_A123456.jp g'``188 ``'__file-student__students/A/A123456/nice_image_A123456.jpeg'`` 189 189 190 190 meaning that the nice image of this applicant would be 191 191 stored in the site-wide file storage in path: 192 192 193 ``students/A/A123456/nice_image_A123456.jpg`` 194 195 """ 193 ``students/A/A123456/nice_image_A123456.jpeg`` 194 195 """ 196 basename, ext = os.path.splitext(attr) 196 197 stud_id = self.context.student_id 197 marked_filename = '__%s__%s/%s/%s_%s .jpg' % (198 STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, attr, stud_id)198 marked_filename = '__%s__%s/%s/%s_%s%s' % ( 199 STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, basename, stud_id, ext) 199 200 return marked_filename 200 201 -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7101 r7106 393 393 self.browser.getControl("Save").click() # submit form 394 394 self.assertTrue( 395 'Uploaded image is too big' in self.browser.contents)395 'Uploaded file is too big' in self.browser.contents) 396 396 397 397 def test_manage_course_lists(self): -
main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py
r7105 r7106 1 import os 1 2 import grok 2 3 from zope.component import getUtility … … 198 199 return self.view.application_url() + rel_link 199 200 200 def handle_ img_upload(upload, context, view, max_size, attr=None):201 """Handle upload of applicant image.201 def handle_file_upload(upload, context, view, max_size, download_name=None): 202 """Handle upload of student file. 202 203 203 204 Returns `True` in case of success or `False`. … … 206 207 points to end of file when leaving this function. 207 208 """ 209 # Check some file requirements first 210 if upload.filename.count('.') == 0: 211 view.flash('File name has no extension.') 212 return False 213 if upload.filename.count('.') > 1: 214 view.flash('File name contains more than one dot.') 215 return False 216 basename, expected_ext = os.path.splitext(download_name) 217 dummy, ext = os.path.splitext(upload.filename) 218 ext.lower() 219 if ext != expected_ext: 220 view.flash('%s extension expected.' % expected_ext) 221 return False 208 222 size = file_size(upload) 209 223 if size > max_size: 210 view.flash('Uploaded image is too big!')224 view.flash('Uploaded file is too big.') 211 225 return False 212 226 upload.seek(0) # file pointer moved when determining size 213 227 store = getUtility(IExtFileStore) 214 file_id = IFileStoreNameChooser(context).chooseName(attr= attr)228 file_id = IFileStoreNameChooser(context).chooseName(attr=download_name) 215 229 store.createFile(file_id, upload) 216 230 return True … … 231 245 grok.order(1) 232 246 grok.require('waeup.viewStudent') 233 label = u'Some Text:' 234 img_src = u'filename.jpg' 235 attr = None 247 label = u'File:' 248 download_name = u'filename.jpg' 236 249 237 250 class FileUpload(FileDisplay): … … 252 265 if upload: 253 266 # We got a fresh upload 254 file_changed = handle_ img_upload(255 upload, self.context, self.view, self.mus, self. attr)267 file_changed = handle_file_upload( 268 upload, self.context, self.view, self.mus, self.download_name) 256 269 if file_changed is False: # False is not None! 257 self.view.redirect(self.view.url(self.context)) 258 return # error during image upload. Ignore other values 270 self.view.redirect( 271 self.view.url(self.context, self.view.__name__)) 272 return # error during file upload. Ignore other values 259 273 else: 260 self.view.files_changed += self. img_src274 self.view.files_changed += self.download_name 261 275 return 262 276 … … 266 280 grok.order(1) 267 281 label = u'Birth Certificate:' 268 img_src = u'birth_certificate.jpg' 269 attr = u'birth_certificate' 282 download_name = u'birth_certificate.jpg' 270 283 271 284 class BirthCertificateUpload(FileUpload): … … 273 286 """ 274 287 grok.order(1) 275 label = u'Birth Certificate :'288 label = u'Birth Certificate (jpeg image):' 276 289 mus = 1024 * 150 277 img_src= u'birth_certificate.jpg'290 download_name = u'birth_certificate.jpg' 278 291 input_name = u'form.birth_certificate' 279 attr = u'birth_certificate'280 292 281 293 class Image(grok.View): 282 """Renders image for students. 283 """ 294 """Renders jpeg images for students. 295 """ 296 grok.baseclass() 284 297 grok.name('none.jpg') 285 298 grok.view(StudentClearanceManageFormPage) 286 299 grok.require('waeup.viewStudent') 287 grok.baseclass() 288 attr = None 300 download_name = u'none.jpg' 289 301 290 302 def render(self): … … 292 304 # for file storage. 293 305 image = getUtility(IExtFileStore).getFileByContext( 294 self.context, attr=self.attr) 306 self.context, attr=self.download_name) 307 # We expect that image is a jpeg pictures 295 308 self.response.setHeader( 296 309 'Content-Type', 'image/jpeg') … … 301 314 302 315 class BirthCertificateImage(Image): 303 """Renders birth certificate .316 """Renders birth certificate jpeg image. 304 317 """ 305 318 grok.name('birth_certificate.jpg') 306 attr = u'birth_certificate'319 download_name = u'birth_certificate.jpg'
Note: See TracChangeset for help on using the changeset viewer.