Changeset 2103 in products for quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/adapters.py
- Timestamp:
- Apr 12, 2010 11:44:04 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/adapters.py
r1933 r2103 18 18 19 19 20 class DefaultCanonical PathAdapter(object):21 """ Adapts base content to canonical path.20 class DefaultCanonicalAdapter(object): 21 """Generic canonical adapter. 22 22 """ 23 23 adapts(ITraversable) 24 implements(ICanonicalPath) 24 25 prop = None 25 26 26 27 def __init__(self, context): … … 28 29 self.purl = getToolByName(self.context,'portal_url') 29 30 30 def _validate _path(self, value):31 def _validate(self, value): 31 32 value.strip() 32 33 if not _is_canonical(value): … … 34 35 return value 35 36 36 def getCanonicalPath(self): 37 """ First of all return value from the PROPERTY_PATH, 38 if PROPERTY_PATH not exist - return default value 37 def getDefault(self): 38 """Return default value for the self.prop""" 39 raise NotImplementedError() 40 41 def getProp(self): 42 """ First of all return value from the self.prop, 43 if self.prop not exist - return default value 39 44 """ 40 if self.context.hasProperty( PROPERTY_PATH):41 return self.context.getProperty( PROPERTY_PATH)45 if self.context.hasProperty(self.prop): 46 return self.context.getProperty(self.prop) 42 47 48 return self.getDefault() 49 50 def setProp(self, value): 51 """ First validate value, than add/updater self.prop 52 """ 53 value = self._validate(value) 54 55 if self.context.hasProperty(self.prop): 56 self.context._updateProperty(self.prop, value) 57 else: 58 self.context._setProperty(self.prop, value, type="string") 59 60 def delProp(self): 61 """ Delete self.prop customization 62 """ 63 if self.context.hasProperty(self.prop): 64 self.context.manage_delProperties(ids=[self.prop,]) 65 66 67 class DefaultCanonicalPathAdapter(DefaultCanonicalAdapter): 68 """Adapts base content to canonical path. 69 """ 70 implements(ICanonicalLink) 71 72 prop = PROPERTY_PATH 73 74 def getDefault(self): 43 75 return '/'+'/'.join(self.purl.getRelativeContentPath(self.context)) 44 76 45 def setCanonicalPath(self, value): 46 """ First validate value, than add/updater PROPERTY_PATH 47 """ 48 value = self._validate_path(value) 49 50 if self.context.hasProperty(PROPERTY_PATH): 51 self.context._updateProperty(PROPERTY_PATH, value) 52 else: 53 self.context._setProperty(PROPERTY_PATH, value, type="string") 54 55 def delCanonicalPath(self): 56 """ Delete PROPERTY_PATH customization 57 """ 58 if self.context.hasProperty(PROPERTY_PATH): 59 self.context.manage_delProperties(ids=[PROPERTY_PATH,]) 60 61 canonical_path = property(getCanonicalPath, setCanonicalPath, delCanonicalPath) 77 canonical_path = property(getProp, setProp, delProp) 62 78 63 79 64 class DefaultCanonicalLinkAdapter( object):80 class DefaultCanonicalLinkAdapter(DefaultCanonicalAdapter): 65 81 """Adapts base content to canonical link. 66 82 """ 67 adapts(ITraversable)68 83 implements(ICanonicalLink) 69 84 70 def __init__(self, context): 71 self.context = context 72 self.purl = getToolByName(self.context,'portal_url') 85 prop = PROPERTY_LINK 73 86 74 def _validate_link(self, value): 75 value.strip() 76 if not _is_canonical(value): 77 raise InvalidValue(value) 78 return value 79 80 def getCanonicalLink(self): 81 """ First of all return value from the PROPERTY_LINK, 82 if PROPERTY_LINK not exist - return default value 83 """ 84 if self.context.hasProperty(PROPERTY_LINK): 85 return self.context.getProperty(PROPERTY_LINK) 86 87 def getDefault(self): 87 88 return self.context.absolute_url() 88 89 89 def setCanonicalLink(self, value): 90 """ First validate value, than add/updater PROPERTY_LINK 91 """ 92 value = self._validate_link(value) 93 94 if self.context.hasProperty(PROPERTY_LINK): 95 self.context._updateProperty(PROPERTY_LINK, value) 96 else: 97 self.context._setProperty(PROPERTY_LINK, value, type="string") 98 99 def delCanonicalLink(self): 100 """ Delete PROPERTY_LINK customization 101 """ 102 if self.context.hasProperty(PROPERTY_LINK): 103 self.context.manage_delProperties(ids=[PROPERTY_LINK,]) 104 105 canonical_link = property(getCanonicalLink, setCanonicalLink, delCanonicalLink) 106 90 canonical_link = property(getProp, setProp, delProp)
Note: See TracChangeset
for help on using the changeset viewer.