Changeset 2369 in products


Ignore:
Timestamp:
May 21, 2010 10:36:44 AM (14 years ago)
Author:
mylan
Message:

Extract DefaultPropertyAdapter? into separate one from DefaultCanonicalAdapter?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/adapters.py

    r2105 r2369  
    55 
    66from OFS.interfaces import ITraversable 
     7from OFS.interfaces import IPropertyManager 
     8 
    79from Products.CMFCore.utils import getToolByName 
    810 
     
    1820 
    1921 
    20 class DefaultCanonicalAdapter(object): 
    21     """Generic canonical adapter. 
     22class DefaultPropertyAdapter(object): 
     23    """Generic property adapter. 
    2224    """ 
    23     adapts(ITraversable) 
     25    adapts(IPropertyManager) 
    2426 
    2527    prop = None 
     
    2729    def __init__(self, context): 
    2830        self.context = context 
    29         self.purl = getToolByName(self.context,'portal_url') 
    30  
    31     def _validate(self, value): 
    32         value.strip() 
    33         if not _is_canonical(value): 
    34             raise InvalidValue(value) 
    35         return value 
    3631 
    3732    def getDefault(self): 
     
    5146        """ First validate value, than add/updater self.prop 
    5247        """ 
    53         value = self._validate(value) 
    54  
    5548        if self.context.hasProperty(self.prop): 
    5649            self.context._updateProperty(self.prop, value) 
     
    6558 
    6659 
     60class DefaultCanonicalAdapter(DefaultPropertyAdapter): 
     61    """Generic canonical adapter. 
     62       Add validation support to functionality of DefaultPropertyAdapter. 
     63    """ 
     64    adapts(ITraversable) 
     65 
     66    def _validate(self, value): 
     67        value.strip() 
     68        if not _is_canonical(value): 
     69            raise InvalidValue(value) 
     70        return value 
     71 
     72    def setProp(self, value): 
     73        """ First validate value, than add/updater self.prop 
     74        """ 
     75        value = self._validate(value) 
     76        super(DefaultCanonicalAdapter, self).setProp(value) 
     77 
     78 
    6779class DefaultCanonicalPathAdapter(DefaultCanonicalAdapter): 
    6880    """Adapts base content to canonical path. 
     
    7183 
    7284    prop = PROPERTY_PATH 
     85 
     86    def __init__(self, context): 
     87        super(DefaultCanonicalPathAdapter, self).__init__(context) 
     88        self.purl = getToolByName(self.context,'portal_url') 
    7389 
    7490    def getDefault(self): 
Note: See TracChangeset for help on using the changeset viewer.