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