root/qPingTool/trunk/adapter.py

Revision 1243 (checked in by liebster, 4 months ago)

fixed add/update canonical_url

  • Property svn:eol-style set to native
Line 
1 from zope.interface import Interface, implements #, Attribute
2 from Products.CMFCore.utils import getToolByName
3
4 class ICanonicalURL(Interface):
5     """ Interface for canonical URL API providing."""
6
7     def getCanonicalURL():
8         """Get canonical_url property value."""
9
10     #def setCanonicalURL():
11         #"""Set canonical_url property value."""
12
13     #def addCanonicalURL(value):
14         #"""Add canonical_url property value"""
15
16     #def hasCanonicalURL():
17         #"""Check if portal has canonical_url property"""
18
19
20 class CanonicalURL(object):
21     """ CanonicalURL adapter
22
23     >>> ICanonicalURL.implementedBy(CanonicalURL)
24     True
25     >>> ICanonicalURL(CanonicalURL(object)) is not None
26     True
27     """
28
29     implements(ICanonicalURL)
30
31     def __init__(self, context):
32         """ init
33         """
34         self.context = context
35
36     def getCanonicalURL(self):
37         """Get canonical_url property value
38         """
39         portal = getToolByName(self.context, 'portal_url').getPortalObject()
40         return portal.getProperty('canonical_url',None)
41
42     #def setCanonicalURL(self, value):
43         #"""Update canonical_url property value
44         #"""
45         #portal = getToolByName(self, 'portal_url').getPortalObject()
46         #portal.manage_changeProperties(canonical_url=str(value))
47
48
49     #def addCanonicalURL(self, value):
50         #"""Add canonical_url property value
51         #"""
52         #portal = getToolByName(self, 'portal_url').getPortalObject()
53         #if not portal.hasProperty('canonical_url'):
54             #portal.manage_delProperties(ids=['canonical_url'])
55         #portal.manage_addProperty('canonical_url', str(value), 'string')
56
57
58     #def hasCanonicalURL(self):
59         #"""Check if portal has canonical_url property
60         #"""
61         #portal = getToolByName(self, 'portal_url').getPortalObject()
62         #return portal.hasProperty('canonical_url')
63
64 # Register adapter
65
66 def registerAdapter():
67     from Products.CMFPlone.interfaces import IPloneBaseTool
68     from zope.component import provideAdapter
69     provideAdapter(CanonicalURL, adapts=[IPloneBaseTool,], provides=ICanonicalURL )
Note: See TracBrowser for help on using the browser.