| 1 |
############################################################################## |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (c) 2005-2006 Nuxeo and Contributors. |
|---|
| 4 |
# All Rights Reserved. |
|---|
| 5 |
# |
|---|
| 6 |
# This software is subject to the provisions of the Zope Public License, |
|---|
| 7 |
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|---|
| 8 |
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|---|
| 9 |
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 10 |
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|---|
| 11 |
# FOR A PARTICULAR PURPOSE. |
|---|
| 12 |
# |
|---|
| 13 |
############################################################################## |
|---|
| 14 |
""" |
|---|
| 15 |
|
|---|
| 16 |
$Id$ |
|---|
| 17 |
""" |
|---|
| 18 |
__docformat__ = "reStructuredText" |
|---|
| 19 |
|
|---|
| 20 |
from zope.traversing.interfaces import IPathAdapter |
|---|
| 21 |
from zope.interface import implements |
|---|
| 22 |
from zope.component import queryUtility |
|---|
| 23 |
|
|---|
| 24 |
from cpsskins.elements.interfaces import IFormattable |
|---|
| 25 |
from cpsskins.elements.interfaces import IPresentable |
|---|
| 26 |
from cpsskins.setup.interfaces import IType |
|---|
| 27 |
|
|---|
| 28 |
class Presentable(object): |
|---|
| 29 |
"""This adapter makes elements presentable, i.e. formattable |
|---|
| 30 |
according to the factory presets. |
|---|
| 31 |
|
|---|
| 32 |
""" |
|---|
| 33 |
implements(IPresentable, IPathAdapter) |
|---|
| 34 |
|
|---|
| 35 |
def __init__(self, context): |
|---|
| 36 |
self.context = context |
|---|
| 37 |
|
|---|
| 38 |
def this(self): |
|---|
| 39 |
"""Return the adapted object. |
|---|
| 40 |
""" |
|---|
| 41 |
return self |
|---|
| 42 |
|
|---|
| 43 |
def addPresentation(self, perspective=None): |
|---|
| 44 |
context = self.context |
|---|
| 45 |
formattable = IFormattable(context) |
|---|
| 46 |
|
|---|
| 47 |
factory_info = queryUtility(IType(context).getContentType(), |
|---|
| 48 |
name=u'presentation') |
|---|
| 49 |
|
|---|
| 50 |
if factory_info is None: |
|---|
| 51 |
factory_info = queryUtility(IType(context).getElementType(), |
|---|
| 52 |
name=u'presentation') |
|---|
| 53 |
|
|---|
| 54 |
for name, types in factory_info.formats.items(): |
|---|
| 55 |
formattable.addFormat(name=name, types=types) |
|---|
| 56 |
|
|---|
| 57 |
def removePresentation(self, perspective=None): |
|---|
| 58 |
"""Remove a presentation associated to an element. |
|---|
| 59 |
""" |
|---|
| 60 |
context = self.context |
|---|
| 61 |
formattable = IFormattable(context) |
|---|
| 62 |
formattable.removeFormats() |
|---|
| 63 |
|
|---|
| 64 |
def customizeFormat(self, name=u'', perspective=None): |
|---|
| 65 |
raise NotImplementedError |
|---|
| 66 |
|
|---|
| 67 |
def decustomizeFormat(self, name=u'', perspective=None): |
|---|
| 68 |
raise NotImplementedError |
|---|
| 69 |
|
|---|