Changeset 7055


Ignore:
Timestamp:
9 Nov 2011, 07:02:02 (13 years ago)
Author:
uli
Message:

Minor clean ups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/applicants/browser.py

    r7054 r7055  
    5454    ManageActionButton, PrimaryNavTab, LeftSidebarLink
    5555    )
    56 from waeup.sirp.image.image import createWAeUPImageFile
    5756from waeup.sirp.interfaces import (
    5857    IWAeUPObject, ILocalRolesAssignable, IExtFileStore, IFileStoreNameChooser)
     
    425424        # If application has ended and applicant record doesn't exist,
    426425        # logout without marking AC as used
    427         if not pin in self.context.keys() and self.context.enddate < date.today():
     426        if not pin in self.context.keys() and (
     427            self.context.enddate < date.today()):
    428428            self.flash('Application has ended.')
    429429            auth = getUtility(IAuthentication)
     
    433433
    434434        # Mark AC as used (this also fires a pin related transition)
    435         if get_access_code(pin).state == USED:
    436             pass
    437         else:
     435        if get_access_code(pin).state != USED:
    438436            comment = u"AC invalidated"
    439437            # Here we know that the ac is in state initialized so we do not
     
    514512            applicant_object = get_applicant_data(access_code)
    515513            return absoluteURL(applicant_object, self.request) + self.target
    516         #else:
    517         #    return ''
     514        return ''
    518515
    519516class AccessCodeEditLink(AccessCodeViewLink):
     
    534531                return ''
    535532            return absoluteURL(applicant_object, self.request) + self.target
    536         #else:
    537         #    return ''
     533        return ''
    538534
    539535class AccessCodeSlipLink(AccessCodeViewLink):
     
    550546    form_fields = grok.AutoFields(IApplicant).omit(
    551547        'locked').omit('course_admitted')
    552     #form_fields['fst_sit_results'].custom_widget = list_results_display_widget
    553     #form_fields['passport'].custom_widget = ThumbnailWidget
    554548    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    555549    label = 'Applicant'
     
    586580class PDFActionButton(ManageActionButton):
    587581    grok.context(IApplicant)
    588     #grok.view(DisplayApplicant)
    589582    grok.require('waeup.manageApplications')
    590583    icon = 'actionicon_pdf.png'
     
    628621
    629622    def render(self):
    630         # (0,0),(-1,-1) = whole table
    631         # (0,0),(0,-1) = first column
    632         # (-1,0),(-1,-1) = last column
    633         # (0,0),(-1,0) = first row
    634         # (0,-1),(-1,-1) = last row
    635623        SLIP_STYLE = TableStyle(
    636624            [('VALIGN',(0,0),(-1,-1),'TOP')]
     
    705693    target = 'edit_full'
    706694
     695def handle_img_upload(upload, context):
     696    """Handle upload of applicant image.
     697    """
     698    store = getUtility(IExtFileStore)
     699    file_id = IFileStoreNameChooser(context).chooseName()
     700    store.createFile(file_id, upload)
     701    upload.seek(0) # XXX: really neccessary?
     702    return
     703
    707704class EditApplicantFull(WAeUPEditFormPage):
    708705    """A full edit view for applicant data.
     
    712709    grok.require('waeup.manageApplications')
    713710    form_fields = grok.AutoFields(IApplicant)
    714     #form_fields['passport'].custom_widget = EncodingImageFileWidget
    715711    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
    716712    grok.template('form_edit')
     
    725721        if upload:
    726722            # We got a fresh upload
    727             #from waeup.sirp.interfaces import IExtFileStorage
    728             #from zope.component import queryUtility
    729             #storage = queryUtility(IExtFileStorage)
    730             # filename = '__img_appl__' + str(self.context.reg_no) #upload.filename
    731             store = getUtility(IExtFileStore)
    732             file_id = IFileStoreNameChooser(self.context).chooseName()
    733             store.createFile(file_id, upload)
    734             #filename = '__img_appl__' + str(
    735             #    self.context.access_code) + '.jpg' #upload.filename
    736             print "FILENAME: ", file_id
    737             # image = createWAeUPImageFile(upload.filename, upload)
    738             #image = createWAeUPImageFile(filename, upload)
    739             # This would normally be totally illegal. We set context
    740             # data without the complete form data being
    741             # verified. Normally data is set in methods like `save`
    742             # only, which is only called when all form data is correct
    743             # (and if not, the context is not touched). With images
    744             # and their uploads the problem then is, that the uploaded
    745             # image won't be shown in a partially erranous form
    746             # because the new uploaded image is still not part of the
    747             # context obeject and the image widget cannot work around
    748             # that (it has no access to the new data). For this reason
    749             # we set the image here and not in 'save()' or other
    750             # methods.
    751             #self.context.passport = image
    752             upload.seek(0)
     723            handle_img_upload(upload, self.context)
    753724            self.passport_changed = True
    754725        return
     
    778749        changed_fields = self.applyData(self.context, **data)
    779750        changed_fields = changed_fields.values()
    780         fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields)
     751        fields_string = '+'.join(
     752            ' + '.join(str(i) for i in b) for b in changed_fields)
    781753        self.context._p_changed = True
    782754        form = self.request.form
     
    800772        'screening_score',
    801773        )
    802     #form_fields['passport'].custom_widget = EncodingImageFileWidget
    803774    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
    804775    grok.template('form_edit')
     
    806777    title = u'Your Application Form'
    807778
    808 
    809779    def emitLockMessage(self):
    810780        self.flash('The requested form is locked (read-only).')
     
    820790        if upload:
    821791            # We got a fresh upload
    822             image = createWAeUPImageFile(upload.filename, upload)
    823             # This would normally be totally illegal. We set context
    824             # data without the complete form data being
    825             # verified. Normally data is set in methods like `save`
    826             # only, which is only called when all form data is correct
    827             # (and if not, the context is not touched). With images
    828             # and their uploads the problem then is, that the uploaded
    829             # image won't be shown in a partially erranous form
    830             # because the new uploaded image is still not part of the
    831             # context obeject and the image widget cannot work around
    832             # that (it has no access to the new data). For this reason
    833             # we set the image here and not in 'save()' or other
    834             # methods.
    835             self.context.passport = image
    836             upload.seek(0)
     792            handle_img_upload(upload, self.context)
    837793            self.passport_changed = True
    838794        super(EditApplicantStudent, self).update()
     
    842798        if not self.request.form.get('confirm_passport', False):
    843799            return 'Passport confirmation box not ticked.'
    844         #if len(self.errors) > 0:
    845         #    return 'Form has errors.'
    846800        return False
    847801
    848802    @grok.action('Save')
    849803    def save(self, **data):
    850         #if self.context.locked:
    851         #    self.emitLockMessage()
    852         #    return
    853804        self.applyData(self.context, **data)
    854805        self.context._p_changed = True
     
    858809    @grok.action('Final Submit')
    859810    def finalsubmit(self, **data):
    860         #if self.context.locked:
    861         #    self.emitLockMessage()
    862         #    return
    863811        self.applyData(self.context, **data)
    864812        self.context._p_changed = True
     
    897845        # A filename chooser turns a context into a filename suitable
    898846        # for file storage.
    899         chooser = IFileStoreNameChooser(self.context)
    900         file_id = chooser.chooseName()
    901         image = getUtility(IExtFileStore).getFile(file_id)
     847        image = getUtility(IExtFileStore).getFileByContext(self.context)
    902848        self.response.setHeader(
    903849            'Content-Type', 'image/jpeg')
Note: See TracChangeset for help on using the changeset viewer.