Ignore:
Timestamp:
4 Nov 2011, 18:36:27 (13 years ago)
Author:
uli
Message:

Throw in the complete mess of last 2 weeks. External file storage now works basically (tests pass), although there are lots of things still to remove, finetune, document, etc.

File:
1 edited

Legend:

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

    r6816 r7002  
    2222"""UI components for basic applicants and related components.
    2323"""
     24import os
    2425import sys
    2526import grok
     
    5758    )
    5859from waeup.sirp.image.image import createWAeUPImageFile
    59 from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable
     60from waeup.sirp.interfaces import (
     61    IWAeUPObject, ILocalRolesAssignable, IExtFileStore, IFileStoreNameChooser)
    6062from waeup.sirp.permissions import get_users_with_local_roles
    6163from waeup.sirp.university.interfaces import ICertificate
     
    6567from waeup.sirp.widgets.objectwidget import (
    6668    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
    67 from waeup.sirp.applicants import ResultEntry, Applicant, get_applicant_data
     69from waeup.sirp.applicants import (
     70    ResultEntry, Applicant, get_applicant_data, get_regno_or_ac)
    6871from waeup.sirp.applicants.interfaces import (
    6972    IApplicant, IApplicantPrincipal,IApplicantEdit, IApplicantsRoot,
    70     IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab
     73    IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab,
     74    IMAGE_PATH,
    7175    )
    7276from waeup.sirp.applicants.workflow import INITIALIZED, STARTED
     
    551555        'locked').omit('course_admitted')
    552556    #form_fields['fst_sit_results'].custom_widget = list_results_display_widget
    553     form_fields['passport'].custom_widget = ThumbnailWidget
     557    #form_fields['passport'].custom_widget = ThumbnailWidget
    554558    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    555559    label = 'Applicant'
    556560    grok.template('form_display')
    557561    pnav = 3
     562
     563    def update(self):
     564        self.passport_url = self.url(self.context, 'passport.jpg')
     565        return
    558566
    559567    @property
     
    705713    grok.require('waeup.manageApplications')
    706714    form_fields = grok.AutoFields(IApplicant)
    707     form_fields['passport'].custom_widget = EncodingImageFileWidget
     715    #form_fields['passport'].custom_widget = EncodingImageFileWidget
    708716    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
    709717    grok.template('form_edit')
     
    718726        if upload:
    719727            # We got a fresh upload
    720             image = createWAeUPImageFile(upload.filename, upload)
     728            #from waeup.sirp.interfaces import IExtFileStorage
     729            #from zope.component import queryUtility
     730            #storage = queryUtility(IExtFileStorage)
     731            # filename = '__img_appl__' + str(self.context.reg_no) #upload.filename
     732            from waeup.sirp.interfaces import (
     733                IExtFileStore, IFileStoreNameChooser)
     734            store = getUtility(IExtFileStore)
     735            file_id = IFileStoreNameChooser(self.context).chooseName()
     736            store.createFile(file_id, upload)
     737            #filename = '__img_appl__' + str(
     738            #    self.context.access_code) + '.jpg' #upload.filename
     739            print "FILENAME: ", file_id
     740            # image = createWAeUPImageFile(upload.filename, upload)
     741            #image = createWAeUPImageFile(filename, upload)
    721742            # This would normally be totally illegal. We set context
    722743            # data without the complete form data being
     
    731752            # we set the image here and not in 'save()' or other
    732753            # methods.
    733             self.context.passport = image
     754            #self.context.passport = image
    734755            upload.seek(0)
    735756            self.passport_changed = True
     
    782803        'screening_score',
    783804        )
    784     form_fields['passport'].custom_widget = EncodingImageFileWidget
     805    #form_fields['passport'].custom_widget = EncodingImageFileWidget
    785806    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
    786807    grok.template('form_edit')
     
    868889    text = 'View application record'
    869890    target = 'index'
     891
     892class PassportImage(grok.View):
     893    """Renders the passport image for applicants.
     894    """
     895    grok.name('passport.jpg')
     896    grok.context(IApplicant)
     897    grok.require('waeup.handleApplication')
     898
     899    def render(self):
     900        # A filename chooser turns a context into a filename suitable
     901        # for file storage.
     902        chooser = IFileStoreNameChooser(self.context)
     903        file_id = chooser.chooseName()
     904        image = getUtility(IExtFileStore).getFile(file_id)
     905        self.response.setHeader(
     906            'Content-Type', 'image/jpeg')
     907        if image is None:
     908            # show placeholder image
     909            return open(os.path.join(IMAGE_PATH, 'placeholder_m.jpg'), 'rb')
     910        return image
Note: See TracChangeset for help on using the changeset viewer.