root/qPingTool/tags/0.3.1/adapter.py

Revision 697 (checked in by mylan, 2 years ago)

Merge trunk to 622 rev. of branches/plone-2.5 (svn merge -r 577:623 http://svn.quintagroup.com/products/qPingTool/branches/plone-2.5 and svn del unnecessery files)

  • 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     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
60 def 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 browser.