Ignore:
Timestamp:
10 Nov 2011, 13:32:33 (13 years ago)
Author:
uli
Message:

Add additional attr parameter for default file name choosers, although we do not make use of it for default files or applicant images.

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

Legend:

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

    r7063 r7066  
    209209    grok.implements(IFileStoreNameChooser)
    210210
    211     def checkName(self, name):
    212         """Check whether an object name is valid.
     211    def checkName(self, name, attr=None):
     212        """Check whether a given name (file id) is valid.
    213213
    214214        Raises a user error if the name is not valid.
    215215
    216         For the default file store name chooser any name is valid.
     216        For the default file store name chooser any name is valid as
     217        long as it is a string.
     218
     219        The `attr` is not taken into account here.
    217220        """
    218221        if isinstance(name, basestring):
     
    220223        return False
    221224
    222     def chooseName(self, name):
    223         """Choose a unique valid name for the object.
    224 
    225         The given name and object may be taken into account when
    226         choosing the name.
     225    def chooseName(self, name, attr=None):
     226        """Choose a unique valid file id for the object.
     227
     228        The given name may be taken into account when choosing the
     229        name (file id).
    227230
    228231        chooseName is expected to always choose a valid name (that
     
    230233
    231234        For this default name chooser we return the given name if it
    232         is valid or ``unknown_file`` else.
     235        is valid or ``unknown_file`` else. The `attr` param is not
     236        taken into account here.
    233237        """
    234238        if self.checkName(name):
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7063 r7066  
    600600    """See zope.container.interfaces.INameChooser for base methods.
    601601    """
    602     def checkName(name):
     602    def checkName(name, attr=None):
    603603        """Check whether an object name is valid.
    604604
     
    606606        """
    607607
    608     def chooseName(name):
    609         """Choose a unique valid name for the object.
    610 
    611         The given name and object may be taken into account when
    612         choosing the name.
    613 
    614         chooseName is expected to always choose a valid name (that would pass
    615         the checkName test) and never raise an error.
     608    def chooseName(name, attr=None):
     609        """Choose a unique valid file id for the object.
     610
     611        The given name may be taken into account when choosing the
     612        name (file id).
     613
     614        chooseName is expected to always choose a valid file id (that
     615        would pass the checkName test) and never raise an error.
     616
     617        If `attr` is not ``None`` it might been taken into account as
     618        well when generating the file id. Usual behaviour is to
     619        interpret `attr` as a hint for what type of file for a given
     620        context should be stored if there are several types
     621        possible. For instance for a certain student some file could
     622        be the connected passport photograph or some certificate scan
     623        or whatever. Each of them has to be stored in a different
     624        location so setting `attr` to a sensible value should give
     625        different file ids returned.
    616626        """
    617627
  • main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py

    r7063 r7066  
    158158        self.context = context
    159159
    160     def chooseName(self, name=None):
     160    def chooseName(self, name=None, attr=None):
     161        # this name chooser returns different file ids depending on
     162        # the `attr` parameter, a simple string.
     163        if attr=='img':
     164            return '__mymarker__mysample.jpg'
     165        elif attr=='doc':
     166            return '__mymarker__mysample.doc'
    161167        return '__mymarker__mysample.txt'
    162168
Note: See TracChangeset for help on using the changeset viewer.