Commit 8a06860b authored by 's avatar

Added DTML Methods/Docs with properties

parent b2d051e8
......@@ -85,8 +85,8 @@
__doc__='''Application support
$Id: Application.py,v 1.84 1999/01/21 22:48:18 jim Exp $'''
__version__='$Revision: 1.84 $'[11:-2]
$Id: Application.py,v 1.85 1999/01/27 20:30:28 brian Exp $'''
__version__='$Revision: 1.85 $'[11:-2]
import Globals,Folder,os,regex,sys,App.Product, App.ProductRegistry
......@@ -157,7 +157,9 @@ class Application(Globals.ApplicationDefaultPermissions, Folder.Folder,
folder=ImageFile('www/Folder_icon.gif', globals())
image =ImageFile('www/Image_icon.gif', globals())
file =ImageFile('www/File_icon.gif', globals())
doc =ImageFile('www/Document_icon.gif', globals())
dtmldoc=doc=ImageFile('www/dtmldoc.gif', globals())
dtmlmethod =ImageFile('www/dtmlmethod.gif', globals())
broken=ImageFile('www/broken.gif', globals())
UserFolder=ImageFile('AccessControl/www/UserFolder_icon.gif')
......
......@@ -100,311 +100,11 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
"""Document object"""
"""Deprecated - use DTMLMethod"""
__version__='$Revision: 1.71 $'[11:-2]
__version__='$Revision: 1.72 $'[11:-2]
from Globals import HTML, HTMLFile, MessageDialog
from string import join,split,strip,rfind,atoi,lower
from AccessControl.Role import RoleManager
from SimpleItem import Item_w__name__, pretty_tb
from Acquisition import Explicit
import regex, Globals, sys
from DocumentTemplate.DT_Util import cDocument
class Document(cDocument, HTML, Explicit,
RoleManager, Item_w__name__):
"""Document object. Basically a DocumentTemplate.HTML object
which operates as a Principia object."""
meta_type='Document'
icon ='p_/doc'
_proxy_roles=()
# Documents masquerade as functions:
class func_code: pass
func_code=func_code()
func_code.co_varnames='self','REQUEST','RESPONSE'
func_code.co_argcount=3
manage_options=({'label':'Edit', 'action':'manage_main',
'target':'manage_main',
},
{'label':'Upload', 'action':'manage_uploadForm',
'target':'manage_main',
},
{'label':'View', 'action':'',
'target':'manage_main',
},
{'label':'Proxy', 'action':'manage_proxyForm',
'target':'manage_main',
},
{'label':'Security', 'action':'manage_access',
'target':'manage_main',
},
)
__ac_permissions__=(
('View management screens',
['manage', 'manage_main','manage_editForm', 'manage_tabs',
'manage_uploadForm']),
('Change permissions', ['manage_access']),
('Change Documents', ['manage_edit','manage_upload','PUT']),
('Change proxy roles', ['manage_proxyForm','manage_proxy']),
('View', ['__call__', '']),
('FTP access', ('manage_FTPstat','manage_FTPget','manage_FTPlist')),
)
_state_name={'raw':1, 'globals':1, '__name__':1, '_vars':1,
'_proxy_roles':1, 'title':1}.has_key
def __getstate__(self):
r={}
state_name=self._state_name
for k, v in self.__dict__.items():
if state_name(k) or k[-11:]=='_Permission' or k[-9:]=="__roles__":
r[k]=v
return r
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping,
Response, and key word arguments."""
kw['document_id'] =self.id
kw['document_title']=self.title
if client is None:
# Called as subtemplate, so don't need error propigation!
r=apply(HTML.__call__, (self, client, REQUEST), kw)
if RESPONSE is None: return r
return decapitate(r, RESPONSE)
try: r=apply(HTML.__call__, (self, client, REQUEST), kw)
except:
if self.id()=='standard_error_message':
raise sys.exc_type, sys.exc_value, sys.exc_traceback
return self.raise_standardErrorMessage(client, REQUEST)
if RESPONSE is None: return r
return decapitate(r, RESPONSE)
def oldvalidate(self, inst, parent, name, value, md):
if hasattr(value, '__roles__'):
roles=value.__roles__
elif inst is parent:
return 1
else:
# if str(name)[:6]=='manage': return 0
if hasattr(parent,'__roles__'):
roles=parent.__roles__
elif hasattr(parent, 'aq_acquire'):
try: roles=parent.aq_acquire('__roles__')
except AttributeError: return 0
else: return 0
value=parent
if roles is None: return 1
try:
if md.AUTHENTICATED_USER.hasRole(value, roles):
return 1
except AttributeError: pass
for r in self._proxy_roles:
if r in roles: return 1
if inst is parent:
raise 'Unauthorized', (
'You are not authorized to access <em>%s</em>.' % name)
return 0
manage_editForm=HTMLFile('documentEdit', globals())
manage_uploadForm=HTMLFile('documentUpload', globals())
manage=manage_main=manage_editDocument=manage_editForm
manage_proxyForm=HTMLFile('documentProxy', globals())
_size_changes={
'Bigger': (5,5),
'Smaller': (-5,-5),
'Narrower': (0,-5),
'Wider': (0,5),
'Taller': (5,0),
'Shorter': (-5,0),
}
def _er(self,data,title,SUBMIT,dtpref_cols,dtpref_rows,REQUEST):
dr,dc = self._size_changes[SUBMIT]
rows=max(1,atoi(dtpref_rows)+dr)
cols=max(40,atoi(dtpref_cols)+dc)
e='Friday, 31-Dec-99 23:59:59 GMT'
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
return self.manage_main(
self,REQUEST,title=title,__str__=self.quotedHTML(data),
dtpref_cols=cols,dtpref_rows=rows)
def manage_edit(self,data,title,SUBMIT='Change',dtpref_cols='50',
dtpref_rows='20',REQUEST=None):
"""
Replaces a Documents contents with Data, Title with Title.
The SUBMIT parameter is also used to change the size of the editing
area on the default Document edit screen. If the value is "Smaller",
the rows and columns decrease by 5. If the value is "Bigger", the
rows and columns increase by 5. If any other or no value is supplied,
the data gets checked for DTML errors and is saved.
"""
self._validateProxy(REQUEST)
if self._size_changes.has_key(SUBMIT):
return self._er(data,title,SUBMIT,dtpref_cols,dtpref_rows,REQUEST)
self.title=title
self.munge(data)
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def manage_upload(self,file='', REQUEST=None):
"""
replace the contents of the document with the text in file.
"""
self._validateProxy(REQUEST)
self.munge(file.read())
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def PUT(self, BODY, REQUEST):
"""
replaces the contents of the document with the BODY of an HTTP PUT request.
"""
self._validateProxy(REQUEST)
self.munge(BODY)
return 'OK'
def manage_haveProxy(self,r): return r in self._proxy_roles
def _validateProxy(self, request, roles=None):
if roles is None: roles=self._proxy_roles
if not roles: return
user=u=request.get('AUTHENTICATED_USER',None)
if user is not None:
user=user.hasRole
for r in roles:
if r and not user(None, (r,)):
user=None
break
if user is not None: return
raise 'Forbidden', (
'You are not authorized to change <em>%s</em> because you '
'do not have proxy roles.\n<!--%s, %s-->' % (self.__name__, u, roles))
def manage_proxy(self, roles=(), REQUEST=None):
"Change Proxy Roles"
self._validateProxy(REQUEST, roles)
self._validateProxy(REQUEST)
self._proxy_roles=tuple(roles)
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def PrincipiaSearchSource(self):
"Support for searching - the document's contents are searched."
return self.read()
def manage_FTPget(self):
"Get source for FTP download"
return self.read()
default_html="""<!--#var standard_html_header-->
<H2><!--#var title_or_id--> <!--#var document_title--></H2>
<P>This is the <!--#var document_id--> Document in
the <!--#var title_and_id--> Folder.</P>
<!--#var standard_html_footer-->"""
manage_addDocumentForm=HTMLFile('documentAdd', globals())
def manage_addDocument(self, id, title='',file='', REQUEST=None, submit=None):
"""
Add a Document object with the contents of file.
If 'file' is empty or unspecified, the created documents contents are set
to Principia's preset default.
"""
if not file: file=default_html
i=Document(file, __name__=id)
i.title=title
self._setObject(id,i)
if REQUEST is not None:
u=REQUEST['URL1']
if submit==" Add and Edit ": u="%s/%s" % (u,id)
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''
class DocumentHandler:
"""Mixin class for objects that can contain Documents."""
def documentIds(self):
t=[]
for i in self.objectMap():
if i['meta_type']=='Document':
t.append(i['id'])
return t
def documentValues(self):
t=[]
for i in self.objectMap():
if i['meta_type']=='Document':
t.append(getattr(self,i['id']))
return t
def decapitate(html, RESPONSE=None,
header_re=regex.compile(
'\(\('
'[^\n\0\- <>:]+:[^\n]*\n'
'\|'
'[ \t]+[^\0\- ][^\n]*\n'
'\)+\)[ \t]*\n\([\0-\377]+\)'
),
space_re=regex.compile('\([ \t]+\)'),
name_re=regex.compile('\([^\0\- <>:]+\):\([^\n]*\)'),
):
if header_re.match(html) < 0: return html
headers, html = header_re.group(1,3)
headers=split(headers,'\n')
i=1
while i < len(headers):
if not headers[i]:
del headers[i]
elif space_re.match(headers[i]) >= 0:
headers[i-1]="%s %s" % (headers[i-1],
headers[i][len(space_re.group(1)):])
del headers[i]
else:
i=i+1
for i in range(len(headers)):
if name_re.match(headers[i]) >= 0:
k, v = name_re.group(1,2)
v=strip(v)
else:
raise ValueError, 'Invalid Header (%d): %s ' % (i,headers[i])
RESPONSE.setHeader(k,v)
return html
import DTMLMethod
Document=DTMLMethod.DTMLMethod
manage_addDocument=DTMLMethod.add
......@@ -105,9 +105,9 @@
Folders are the basic container objects and are analogous to directories.
$Id: Folder.py,v 1.57 1999/01/19 23:59:09 amos Exp $"""
$Id: Folder.py,v 1.58 1999/01/27 20:30:28 brian Exp $"""
__version__='$Revision: 1.57 $'[11:-2]
__version__='$Revision: 1.58 $'[11:-2]
from Globals import HTMLFile
......@@ -116,7 +116,6 @@ from PropertyManager import PropertyManager
from CopySupport import CopyContainer
from FindSupport import FindSupport
from Image import Image, File
from Document import DocumentHandler
from AccessControl.Role import RoleManager
import SimpleItem
from string import rfind, lower
......@@ -139,16 +138,11 @@ def manage_addFolder(self,id,title='',createPublic=0,createUserF=0,
i.title=title
self._setObject(id,i)
if createUserF: i.manage_addUserFolder()
if createPublic: i.manage_addDocument(id='index_html',title='')
if createPublic: i.manage_addDTMLDocument(id='index_html',title='')
if REQUEST is not None: return self.manage_main(self,REQUEST,update_menu=1)
class Folder(ObjectManager,
PropertyManager,
RoleManager,
DocumentHandler,
SimpleItem.Item,
CopyContainer,
FindSupport):
class Folder(ObjectManager, PropertyManager, RoleManager, SimpleItem.Item,
CopyContainer, FindSupport):
"""
The basic container object in Principia. Folders can hold almost all
other Principia objects.
......@@ -292,8 +286,8 @@ class PUTer(Acquisition.Explicit):
else: type=text_type(BODY)
__traceback_info__=suf, dot, name, type
if lower(type)[:5]=='text/':
return self._parent.manage_addDocument(name,'',BODY,
REQUEST=REQUEST)
return self._parent.manage_addDTMLDocument(name,'',BODY,
REQUEST=REQUEST)
if lower(type)[:6]=='image/':
self._parent._setObject(name, Image(name, '', BODY,
content_type=type))
......
......@@ -83,22 +83,10 @@
#
##############################################################################
"""Property management"""
__version__='$Revision: 1.2 $'[11:-2]
"""Property management."""
__version__='$Revision: 1.3 $'[11:-2]
## from ObjectManager import ObjectManager
## from CopySupport import CopyContainer
## from FindSupport import FindSupport
## from Image import Image, File
## from Document import DocumentHandler
## from AccessControl.Role import RoleManager
## import SimpleItem
## from string import rfind, lower
## from content_types import content_type, find_binary, text_type
## import Globals
from ZPublisher.Converters import type_converters
from Globals import HTMLFile, MessageDialog
from string import find,join,lower,split
......@@ -107,12 +95,6 @@ from DateTime import DateTime
def aq_base(ob):
if hasattr(ob, 'aq_base'):
return ob.aq_base
return ob
class PropertyManager:
"""
The PropertyManager mixin class provides an object with
......@@ -328,3 +310,9 @@ class PropertyManager:
v=getattr(self,n)
r.append({'id': n, 'input': imap[t](None,n,t,v)})
return r
def aq_base(ob):
if hasattr(ob, 'aq_base'):
return ob.aq_base
return ob
<HTML>
<HEAD>
<TITLE>Add Document</TITLE>
<TITLE>Add DTML Document</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<H2>Add Document</H2>
<H2>Add DTML Document</H2>
<P>
You may create a new html document using the form below.
Also, you may choose to upload an existing html file from your
local computer by clicking the <I>Browse</I> button.
You may create a new DTML Document using the form below.
You may also choose to upload an existing html file from your
local computer by clicking the <I>Browse</I> button.
<FORM ACTION="manage_addDocument" METHOD="POST"
<FORM ACTION="manage_addDTMLDocument" METHOD="POST"
ENCTYPE="multipart/form-data" TARGET="manage_main">
<TABLE CELLSPACING="2">
<TR>
......
<HTML>
<HEAD>
<TITLE>Add DTML Method</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<H2>Add DTML Method</H2>
<P>
You may create a new DTML Method object using the form below.
You may also choose to upload an existing html file from your
local computer by clicking the <I>Browse</I> button.
<FORM ACTION="manage_addDTMLMethod" METHOD="POST"
ENCTYPE="multipart/form-data" TARGET="manage_main">
<TABLE CELLSPACING="2">
<TR>
<TH ALIGN="LEFT" VALIGN="TOP">Id</TH>
<TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="id" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="LEFT" VALIGN="TOP"><EM>Title</EM></TH>
<TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="title" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="LEFT" VALIGN="TOP"><EM><STRONG>File</STRONG></EM></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="file" NAME="file:string" SIZE="25" VALUE="">
</TD>
</TR>
<TR><TH></TH>
<TD>
<INPUT TYPE="SUBMIT" VALUE=" Add ">
<INPUT TYPE="SUBMIT" VALUE=" Add and Edit " NAME="submit">
</TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment