vendor/CMF/1.6.3/CMFCore

view FSSTXMethod.py @ 2:4c712d7bd1d7

Added tag 1.6.3 for changeset 1babb9d61518
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Fri, 09 Sep 2011 12:44:00 +0200
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ FSSTXMethod: Filesystem methodish Structured Text document.
15 $Id$
16 """
18 import Globals
19 from AccessControl import ClassSecurityInfo
20 from StructuredText.StructuredText import HTML
22 from permissions import FTPAccess
23 from permissions import View
24 from permissions import ViewManagementScreens
25 from DirectoryView import registerFileExtension
26 from DirectoryView import registerMetaType
27 from FSObject import FSObject
28 from utils import _dtmldir
29 from utils import expandpath
32 class FSSTXMethod( FSObject ):
33 """
34 A chunk of StructuredText, rendered as a skin method of a
35 CMFSite.
36 """
38 meta_type = 'Filesystem STX Method'
40 manage_options=( { 'label' : 'Customize'
41 , 'action' : 'manage_main'
42 }
43 , { 'label' : 'View'
44 , 'action' : ''
45 , 'help' : ('OFSP'
46 ,'DTML-DocumentOrMethod_View.stx'
47 )
48 }
49 )
51 security = ClassSecurityInfo()
52 security.declareObjectProtected( View )
54 security.declareProtected( ViewManagementScreens, 'manage_main')
55 manage_main = Globals.DTMLFile( 'custstx', _dtmldir )
57 #
58 # FSObject interface
59 #
60 def _createZODBClone(self):
61 """
62 Create a ZODB (editable) equivalent of this object.
63 """
64 raise NotImplementedError, "See next week's model."
66 def _readFile( self, reparse ):
68 fp = expandpath( self._filepath )
69 file = open( fp, 'r' ) # not binary, we want CRLF munging here.
71 try:
72 data = file.read()
73 finally:
74 file.close()
76 self.raw = data
78 if reparse:
79 self.cook()
81 #
82 # "Wesleyan" interface (we need to be "methodish").
83 #
84 class func_code:
85 pass
87 func_code=func_code()
88 func_code.co_varnames= ()
89 func_code.co_argcount=0
90 func_code.__roles__=()
92 func_defaults__roles__=()
93 func_defaults=()
95 index_html = None # No accidental acquisition
97 default_content_type = 'text/html'
99 def cook( self ):
100 if not hasattr( self, '_v_cooked' ):
101 self._v_cooked = HTML(self.raw, level=1, header=0)
102 return self._v_cooked
104 _default_template = Globals.HTML( """\
105 <dtml-var standard_html_header>
106 <div class="Desktop">
107 <dtml-var cooked>
108 </div>
109 <dtml-var standard_html_footer>""" )
111 def __call__( self, REQUEST={}, RESPONSE=None, **kw ):
112 """
113 Return our rendered StructuredText.
114 """
115 self._updateFromFS()
117 if RESPONSE is not None:
118 RESPONSE.setHeader( 'Content-Type', 'text/html' )
119 return self._render(REQUEST, RESPONSE, **kw)
121 security.declarePrivate( '_render' )
122 def _render( self, REQUEST={}, RESPONSE=None, **kw ):
123 """
124 Find the appropriate rendering template and use it to
125 render us.
126 """
127 template = getattr( self, 'stxmethod_view', self._default_template )
129 if getattr( template, 'isDocTemp', 0 ):
130 posargs = ( self, REQUEST, RESPONSE )
131 else:
132 posargs = ()
134 return template(*posargs, **{ 'cooked' : self.cook() } )
136 security.declareProtected( FTPAccess, 'manage_FTPget' )
137 def manage_FTPget( self ):
138 """
139 Fetch our source for delivery via FTP.
140 """
141 return self.raw
143 security.declareProtected( ViewManagementScreens, 'PrincipiaSearchSource' )
144 def PrincipiaSearchSource( self ):
145 """
146 Fetch our source for indexing in a catalog.
147 """
148 return self.raw
150 security.declareProtected( ViewManagementScreens, 'document_src' )
151 def document_src( self ):
152 """
153 Fetch our source for indexing in a catalog.
154 """
155 return self.raw
157 Globals.InitializeClass( FSSTXMethod )
159 registerFileExtension( 'stx', FSSTXMethod )
160 registerMetaType( 'STX Method', FSSTXMethod )