source: cmfdeployment/branches/kenw-p4-wip/Descriptor.py @ 2380

Last change on this file since 2380 was 2380, checked in by kenw, 8 years ago

Committing new branch intended for Plone 4 compatibility; mostly required imports of new zope packages

File size: 5.6 KB
Line 
1##################################################################
2#
3# (C) Copyright 2002-2006 Kapil Thangavelu <k_vertigo@objectrealms.net>
4# All Rights Reserved
5#
6# This file is part of CMFDeployment.
7#
8# CMFDeployment is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# CMFDeployment is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with CMFDeployment; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21##################################################################
22"""
23Purpose: Data object to track a deployed content object
24Author: kapil thangavelu <k_vertigo@objectrealms.net> @2002-2006
25License: GPL
26Created: 8/10/2002
27$Id: Descriptor.py 1238 2006-03-15 01:20:14Z hazmat $
28"""
29
30from Acquisition import aq_base
31
32class DescriptorFactory:
33
34    def __init__(self, ctx):
35        self.ctx = ctx
36        org  = ctx.getContentOrganization()
37        self.is_composite = make_lookup(org.getActiveStructure().getCompositeDocumentTypes())
38
39    def __call__(self, content):
40        d = ContentDescriptor(content)
41        d.content_url = content.absolute_url(relative=1)
42        d.content_folderish_p = getattr(aq_base(content), 'isAnObjectManager', 0)
43        d.composite_content_p = self.is_composite(content.getPortalTypeName())
44        return d
45       
46def make_lookup(seq):
47    d = {}
48    for s in seq:
49        d[s]=None
50    return d.has_key
51   
52
53class DescriptorContainer(list):
54    """
55    container object for descriptors
56    """
57
58class ContentDescriptor(object):
59    """
60    a drop of water in a sieve
61    """
62
63    def __init__(self, content):
64        self.content = content
65        self.extension = None
66        self.rendered  = None
67        self.render_method = None
68        self.binary = None
69        self.ghost = None
70        self.content_path = None
71        self.source_path = None # relative path to content
72        self.content_url = None
73        self.content_folderish_p = None
74        self.composite_content_p = None
75        self.child_descriptors = None
76
77        self.rule_id = None # id of rule that processed descriptor / matched content
78
79        self.dependencies = None
80        self.reverse_dependencies = None
81        self.aliases = None
82       
83    def getId(self):
84        return self.content.getId()
85
86    def getDescriptors(self):
87        descriptors = self.getChildDescriptors()
88        if descriptors is None:
89            return (self,)
90        return (self,)+tuple(descriptors)
91
92    def getAliases(self):
93        return self.aliases or ()
94
95    def getContent(self):
96        return self.content
97
98    def getRendered(self):
99        return self.rendered
100
101    def setRendered(self, rendered):
102        self.rendered = rendered
103       
104    def getRenderMethod(self):
105        return self.render_method
106
107    def setRenderMethod(self, method_name):
108        self.render_method = method_name
109
110    #################################
111    # this is a misnomer it reflects the entire
112    # portion of the last path segment ie foo.txt
113
114    def getExtension(self):
115        return self.extension
116
117    def setExtension(self, extension):
118        self.extension = extension
119
120    setFileName = setExtension
121   
122    def getFileName(self):
123        return self.extension
124    #################################
125   
126    def getContentURL(self):
127        return self.content_url
128
129    def setContentURL(self, content_url):
130        self.content_url = content_url
131
132    def setContentFolderish(self, flag):
133        self.content_folderish_p = flag
134       
135    def isContentFolderish(self):
136        return not not self.content_folderish_p
137
138    def setCompositeContent(self, flag):
139        self.composite_content_p = not not flag
140
141    def isCompositeContent(self):
142        return self.composite_content_p
143   
144    def isGhost(self):
145        return not not self.ghost
146
147    def setGhost(self, flag):
148        self.ghost = flag
149
150    def isBinary(self):
151        return not not self.binary
152
153    def setBinary(self, flag):
154        self.binary = flag
155
156    def setContentPath(self, path):
157        self.content_path = path
158
159    def getContentPath(self):
160        return self.content_path
161
162    def setSourcePath(self, path):
163        self.source_path = path
164       
165    def getSourcePath(self):
166        return self.source_path
167
168    #################################
169    # child resource management - for non portal content
170   
171    def addChildDescriptor(self, descriptor):
172        if self.child_descriptors is None:
173            self.child_descriptors = DescriptorContainer()
174        self.child_descriptors.append( descriptor )
175           
176    def getChildDescriptors(self):
177        return self.child_descriptors or ()
178
179    def getContainedDescriptors(self, include_self=True):
180        if include_self:
181            yield self
182        for d in self.getChildDescriptors():
183            for s in d.getContainedDescriptors():
184                yield s
185
186    #################################
187    # dependency management
188
189    def getDependencies( self ):
190        return self.dependencies or ()
191
192    def setDependencies( self, dependencies ):
193        self.dependencies = dependencies
194
195    def getReverseDependencies( self ):
196        return self.reverse_dependencies or []
197
198    def setReverseDependencies( self, reverse_dependencies ):
199        self.reverse_dependencies = reverse_dependencies
200
Note: See TracBrowser for help on using the repository browser.