source: products/qPingTool/tags/0.3.1/adapter.py

Last change on this file was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1from zope.interface import Interface, implements #, Attribute
2from Products.CMFCore.utils import getToolByName
3
4class 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
20class CanonicalURL(object):
21    """ CanonicalURL adapter
22    """
23    implements(ICanonicalURL)
24
25    def __init__(self, context):
26        """ init
27        """
28        self.context = context
29
30    def getCanonicalURL(self):
31        """Get canonical_url property value
32        """
33        portal = getToolByName(self.context, 'portal_url').getPortalObject()
34        return portal.getProperty('canonical_url',None)
35
36    #def setCanonicalURL(self, value):
37        #"""Update canonical_url property value
38        #"""
39        #portal = getToolByName(self, 'portal_url').getPortalObject()
40        #portal.manage_changeProperties(canonical_url=str(value))
41
42
43    #def addCanonicalURL(self, value):
44        #"""Add canonical_url property value
45        #"""
46        #portal = getToolByName(self, 'portal_url').getPortalObject()
47        #if not portal.hasProperty('canonical_url'):
48            #portal.manage_delProperties(ids=['canonical_url'])
49        #portal.manage_addProperty('canonical_url', str(value), 'string')
50
51
52    #def hasCanonicalURL(self):
53        #"""Check if portal has canonical_url property
54        #"""
55        #portal = getToolByName(self, 'portal_url').getPortalObject()
56        #return portal.hasProperty('canonical_url')
57
58# Register adapter
59
60def registerAdapter():
61    from Products.CMFPlone.interfaces import IPloneBaseTool
62    from zope.component import provideAdapter
63    provideAdapter(CanonicalURL, adapts=[IPloneBaseTool,], provides=ICanonicalURL )
Note: See TracBrowser for help on using the repository browser.