Changeset 7103 for main


Ignore:
Timestamp:
13 Nov 2011, 10:22:25 (13 years ago)
Author:
Henrik Bettermann
Message:

File name choosers generally don't know the extension of the file stored. So we have to feed the chooseName method with the extension (ext) of the file stored in the file system.

This may conflict somehow with the idea behind the file name chooser. I think you (Uli) intended to use only the attr parameter to select a proper extension. In my opinion it's better to use attr and ext.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicant.py

    r7067 r7103  
    146146        return name == self.chooseName()
    147147
    148     def chooseName(self, name=None, attr=None):
     148    def chooseName(self, name=None, attr=None, ext=None):
    149149        """Get a valid file id for applicant context.
    150150
  • main/waeup.sirp/trunk/src/waeup/sirp/imagestorage.py

    r7093 r7103  
    223223        return False
    224224
    225     def chooseName(self, name, attr=None):
     225    def chooseName(self, name, attr=None, ext=None):
    226226        """Choose a unique valid file id for the object.
    227227
     
    233233
    234234        For this default name chooser we return the given name if it
    235         is valid or ``unknown_file`` else. The `attr` param is not
    236         taken into account here.
     235        is valid or ``unknown_file`` else. The `attr` and the `ext` params
     236        are not taken into account here.
    237237        """
    238238        if self.checkName(name):
     
    344344        return fd
    345345
    346     def getFileByContext(self, context, attr=None):
     346    def getFileByContext(self, context, attr=None, ext=None):
    347347        """Get a file for given context.
    348348
     
    355355        id for the context and `attr` given.
    356356
    357         Both, `context` and `attr` are used to find (`context`)
     357        `context`, `attr` and `ext` are used to find (`context`)
    358358        and feed (`attr`) an appropriate file name chooser.
    359359
     
    364364                     :class:`DefaultFileStoreHandler`.
    365365        """
    366         file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
     366        file_id = IFileStoreNameChooser(context).chooseName(attr=attr, ext=ext)
    367367        return self.getFile(file_id)
    368368
     
    378378        return
    379379
    380     def deleteFileByContext(self, context, attr=None):
     380    def deleteFileByContext(self, context, attr=None, ext=None):
    381381        """Remove file identified by `context` and `attr` if it exists.
    382382
     
    385385        id for the context and `attr` given.
    386386
    387         Both, `context` and `attr` are used to find (`context`)
     387        `context`, `attr` and `ext` are used to find (`context`)
    388388        and feed (`attr`) an appropriate file name chooser.
    389389
     
    395395
    396396        """
    397         file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
     397        file_id = IFileStoreNameChooser(context).chooseName(attr=attr, ext=ext)
    398398        return self.deleteFile(file_id)
    399399
  • main/waeup.sirp/trunk/src/waeup/sirp/students/student.py

    r7102 r7103  
    177177        return name == self.chooseName()
    178178
    179     def chooseName(self, name=None, attr=None):
     179    def chooseName(self, name=None, attr=None, ext=u''):
    180180        """Get a valid file id for student context.
    181181
     
    195195
    196196        """
    197         ext = u''
    198197        if name and name.count('.') == 1:
    199198            basename, ext = os.path.splitext(name)
    200         ext.lower()
     199            ext.lower()
    201200        stud_id = self.context.student_id
    202201        marked_filename = '__%s__%s/%s/%s_%s%s' % (
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7102 r7103  
    288288    grok.baseclass()
    289289    attr = None
     290    ext = u'.jpg'
    290291
    291292    def render(self):
     
    293294        # for file storage.
    294295        image = getUtility(IExtFileStore).getFileByContext(
    295             self.context, attr=self.attr)
     296            self.context, attr=self.attr, ext=self.ext)
    296297        self.response.setHeader(
    297298            'Content-Type', 'image/jpeg')
     
    306307    grok.name('birth_certificate.jpg')
    307308    attr = u'birth_certificate'
     309    ext = u'.jpg'
  • main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py

    r7092 r7103  
    158158        self.context = context
    159159
    160     def chooseName(self, name=None, attr=None):
     160    def chooseName(self, name=None, attr=None, ext=None):
    161161        # this name chooser returns different file ids depending on
    162162        # the `attr` parameter, a simple string.
Note: See TracChangeset for help on using the changeset viewer.