Commit 307baa8d authored by 's avatar

Fixed behaviour of documents (and images and files) after editing

Removed 'icon' from manage_options - it is obsolete
Moved things back to constructors while I was at it
parent 191a9d60
"""Document object"""
__version__='$Revision: 1.36 $'[11:-2]
__version__='$Revision: 1.37 $'[11:-2]
from Globals import HTML, HTMLFile
from Globals import HTML, HTMLFile, MessageDialog
from string import join,split,strip,rfind,atoi
from AccessControl.Role import RoleManager
import SimpleItem, regex
import Acquisition
class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
Acquisition.Explicit):
"""Document object"""
meta_type ='Document'
icon='p_/doc'
from SimpleItem import Item_w__name__
from Acquisition import Explicit
import regex
class Document(HTML, Explicit, RoleManager, Item_w__name__):
""" """
meta_type='Document'
icon ='p_/doc'
__state_names__=HTML.__state_names__+('title','__roles__')
# Documents masquerade as functions:
......@@ -21,17 +22,17 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
func_code.co_varnames='self','REQUEST','RESPONSE'
func_code.co_argcount=3
manage_options=({'icon':'', 'label':'Edit',
'action':'manage_main', 'target':'manage_main',
manage_options=({'label':'Edit', 'action':'manage_main',
'target':'manage_main',
},
{'icon':'', 'label':'Upload',
'action':'manage_uploadForm', 'target':'manage_main',
{'label':'Upload', 'action':'manage_uploadForm',
'target':'manage_main',
},
{'icon':'', 'label':'View',
'action':'', 'target':'manage_main',
{'label':'View', 'action':'',
'target':'manage_main',
},
{'icon':'', 'label':'Security',
'action':'manage_access', 'target':'manage_main',
{'label':'Security', 'action':'manage_access',
'target':'manage_main',
},
)
......@@ -47,6 +48,7 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
)
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
""" """
kw['document_id'] =self.id
kw['document_title']=self.title
r=apply(HTML.__call__, (self, client, REQUEST), kw)
......@@ -75,7 +77,7 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
def manage_edit(self,data,title,SUBMIT='Change',dtpref_cols='50',
dtpref_rows='20',REQUEST=None):
"""Edit method"""
""" """
if SUBMIT=='Smaller':
rows=atoi(dtpref_rows)-5
cols=atoi(dtpref_cols)-5
......@@ -83,9 +85,8 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
return self.manage_editForm(self,REQUEST,title=title,__str__=data,
acl_type=acl_type,acl_roles=acl_roles,
dtpref_cols=cols,dtpref_rows=rows)
return self.manage_main(self,REQUEST,title=title,__str__=data,
dtpref_cols=cols,dtpref_rows=rows)
if SUBMIT=='Bigger':
rows=atoi(dtpref_rows)+5
cols=atoi(dtpref_cols)+5
......@@ -93,24 +94,25 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__,
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
return self.manage_editForm(self,REQUEST,title=title,__str__=data,
acl_type=acl_type,acl_roles=acl_roles,
dtpref_cols=cols,dtpref_rows=rows)
return self.manage_main(self,REQUEST,title=title,__str__=data,
dtpref_cols=cols,dtpref_rows=rows)
self.title=title
self.munge(data)
if REQUEST: return self.manage_editedDialog(REQUEST)
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def manage_upload(self,file='', REQUEST=None):
"""Change image data"""
""" """
self.munge(file.read())
if REQUEST: return self.manage_editedDialog(REQUEST)
def validRoles(self):
return self.aq_parent.validRoles()
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def PUT(self, BODY, REQUEST):
'handle PUT requests'
""" """
self.munge(BODY)
return 'OK'
......@@ -123,13 +125,11 @@ the <!--#var title_and_id--> Folder.</P>
class DocumentHandler:
"""Document object handler mixin"""
#meta_types=({'name':'Document', 'action':'manage_addDocumentForm'},)
""" """
manage_addDocumentForm=HTMLFile('documentAdd', globals())
def manage_addDocument(self,id,title='',file='',REQUEST=None):
"""Add a new Document object"""
""" """
if not file: file=default_html
i=Document(file, __name__=id)
i.title=title
......
"""Folder object
$Id: Folder.py,v 1.30 1997/12/31 17:13:23 brian Exp $"""
$Id: Folder.py,v 1.31 1998/01/02 17:22:56 brian Exp $"""
__version__='$Revision: 1.30 $'[11:-2]
__version__='$Revision: 1.31 $'[11:-2]
from Globals import HTMLFile
from ObjectManager import ObjectManager
from CopySupport import CopyContainer
from Image import ImageHandler
from Image import Image, File, ImageHandler
from Document import DocumentHandler
from AccessControl.User import UserFolderHandler
from AccessControl.Role import RoleManager
import SimpleItem
from string import rfind, lower
from content_types import content_type, find_binary, text_type
import Image
class FolderHandler:
"""Folder object handler"""
# meta_types=({'name':'Folder', 'action':'manage_addFolderForm'},)
class FolderHandler:
""" """
manage_addFolderForm=HTMLFile('folderAdd', globals())
def folderClass(self):
......@@ -36,13 +33,9 @@ class FolderHandler:
i.id=id
i.title=title
self._setObject(id,i)
if createUserF: i.manage_addUserFolder()
if createPublic:
i.manage_addDocument(id='index_html', title='')
if REQUEST is not None:
return self.manage_main(self,REQUEST)
if createUserF: i.manage_addUserFolder()
if createPublic: i.manage_addDocument(id='index_html',title='')
if REQUEST: return self.manage_main(self,REQUEST)
def folderIds(self):
t=[]
......@@ -66,21 +59,19 @@ class FolderHandler:
test_url___allow_groups__=None
def test_url_(self):
'''Method for testing server connection information
when configuring aqueduct clients'''
"""Test connection"""
return 'PING'
class Folder(ObjectManager,RoleManager,DocumentHandler,
ImageHandler,FolderHandler,UserFolderHandler,
SimpleItem.Item,CopyContainer):
"""Folder object"""
""" """
meta_type='Folder'
id ='folder'
title ='Folder object'
icon='p_/folder'
icon ='p_/folder'
_properties=({'id':'title', 'type': 'string'},)
meta_types=()
......@@ -89,16 +80,16 @@ class Folder(ObjectManager,RoleManager,DocumentHandler,
)
manage_options=(
{'icon':icon, 'label':'Contents',
'action':'manage_main', 'target':'manage_main'},
{'icon':'OFS/Properties_icon.gif', 'label':'Properties',
'action':'manage_propertiesForm', 'target':'manage_main'},
{'icon':'AccessControl/AccessControl_icon.gif', 'label':'Security',
'action':'manage_access', 'target':'manage_main'},
{'icon':'App/undo_icon.gif', 'label':'Undo',
'action':'manage_UndoForm', 'target':'manage_main'},
# {'icon':'OFS/Help_icon.gif', 'label':'Help',
# 'action':'manage_help', 'target':'_new'},
{'label':'Contents', 'action':'manage_main',
'target':'manage_main'},
{'label':'Properties', 'action':'manage_propertiesForm',
'target':'manage_main'},
{'label':'Security', 'action':'manage_access',
'target':'manage_main'},
{'label':'Undo', 'action':'manage_UndoForm',
'target':'manage_main'},
# {'label':'Help', 'action':'manage_help',
# 'target':'_new'},
)
__ac_permissions__=(
......@@ -139,25 +130,20 @@ class Folder(ObjectManager,RoleManager,DocumentHandler,
id=key[19:]
if hasattr(self, id): return getattr(self, id).manage_supervisor()
raise KeyError, key
try:
if self.REQUEST['REQUEST_METHOD']=='PUT': return PUTer(self,key)
except: pass
raise KeyError, key
class PUTer:
'Temporary objects to handle PUT to non-existent images or documents'
class PUTer:
""" """
def __init__(self, parent, key):
self._parent=parent
self._key=key
def __str__(self): return self._key
PUT__roles__='manage',
def PUT(self, REQUEST, BODY):
' '
""" """
name=self._key
try: type=REQUEST['CONTENT_TYPE']
except KeyError: type=''
......@@ -174,18 +160,21 @@ class PUTer:
raise 'Bad Request', 'Could not determine file type'
else: type=text_type(BODY)
__traceback_info__=suf, dot, name, type
if lower(type)=='text/html':
return self._parent.manage_addDocument(name,'',BODY,
REQUEST=REQUEST)
if lower(type)[:6]=='image/': i=Image.Image()
else: i=Image.File()
i._init(name, BODY, type)
i.title=''
self._parent._setObject(name,i)
if lower(type)[:6]=='image/':
self._parent._setObject(name, Image(name, '', BODY, type))
else:
self._parent._setObject(name, File(name, '', BODY, type))
return 'OK'
def __str__(self): return self._key
def subclass(c,super):
if c is super: return 1
......@@ -194,3 +183,5 @@ def subclass(c,super):
if subclass(base,super): return 1
except: pass
return 0
"""Image object"""
__version__='$Revision: 1.20 $'[11:-2]
__version__='$Revision: 1.21 $'[11:-2]
from Persistence import Persistent
from Globals import HTMLFile
from Globals import MessageDialog
from Globals import HTMLFile, MessageDialog
from AccessControl.Role import RoleManager
import SimpleItem
import Acquisition
from SimpleItem import Item_w__name__
from Persistence import Persistent
from Acquisition import Implicit
class File(Persistent,RoleManager,SimpleItem.Item_w__name__,
Acquisition.Implicit):
"""Image object"""
class File(Persistent,Implicit,RoleManager,Item_w__name__):
""" """
meta_type='File'
icon='p_/file'
manage_editForm =HTMLFile('imageEdit', globals(), Kind='File', kind='file')
manage_uploadForm =HTMLFile('imageUpload', globals(), Kind='File', kind='file')
manage_editForm =HTMLFile('imageEdit',globals(),Kind='File',kind='file')
manage_uploadForm=HTMLFile('imageUpload',globals(),Kind='File',kind='file')
manage=manage_main=manage_editForm
manage_options=({'icon':'', 'label':'Edit',
'action':'manage_main', 'target':'manage_main',
manage_options=({'label':'Edit', 'action':'manage_main',
'target':'manage_main',
},
{'icon':'', 'label':'Upload',
'action':'manage_uploadForm', 'target':'manage_main',
{'label':'Upload', 'action':'manage_uploadForm',
'target':'manage_main',
},
{'icon':'', 'label':'View',
'action':'index_html', 'target':'manage_main',
{'label':'View', 'action':'index_html',
'target':'manage_main',
},
{'icon':'', 'label':'Security',
'action':'manage_access', 'target':'manage_main',
{'label':'Security', 'action':'manage_access',
'target':'manage_main',
},
{'icon':'', 'label':'Undo',
'action':'manage_UndoForm', 'target':'manage_main',
{'label':'Undo', 'action':'manage_UndoForm',
'target':'manage_main',
},
)
......@@ -47,46 +46,47 @@ class File(Persistent,RoleManager,SimpleItem.Item_w__name__,
('View Access', ['View',]),
)
def manage_edit(self,title,content_type,REQUEST=None):
""" """
self.title=title
self.content_type=content_type
if REQUEST: return self.manage_editedDialog(REQUEST)
def manage_upload(self,file='', REQUEST=None):
"""Change image data"""
headers=file.headers
data=file.read()
content_type=headers['content-type']
self.data=data
self.content_type=content_type
if REQUEST: return self.manage_editedDialog(REQUEST)
def _init(self,id,file,content_type=''):
def __init__(self,id,title,file,content_type=''):
try: headers=file.headers
except: headers=None
if headers is None:
if not content_type: raise 'BadValue', (
'No content type specified')
if not content_type:
raise 'BadValue', 'No content type specified'
self.content_type=content_type
self.data=file
else:
self.content_type=headers['content-type']
self.data=file.read()
self.__name__=id
self.title=title
def id(self): return self.__name__
def index_html(self, RESPONSE):
"""Default document"""
""" """
RESPONSE['content-type']=self.content_type
return self.data
def __str__(self): return self.data
def manage_edit(self,title,content_type,REQUEST=None):
""" """
self.title=title
self.content_type=content_type
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def __len__(self):
# This is bogus and needed because of the way Python tests truth.
return 1
def manage_upload(self,file='',REQUEST=None):
""" """
headers=file.headers
data=file.read()
content_type=headers['content-type']
self.data=data
self.content_type=content_type
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
def PUT(self, BODY, REQUEST):
'handle PUT requests'
......@@ -96,14 +96,18 @@ class File(Persistent,RoleManager,SimpleItem.Item_w__name__,
if type: self.content_type=type
except KeyError: pass
def __str__(self): return self.data
def __len__(self): return 1
class Image(File):
class Image(File):
meta_type='Image'
icon='p_/image'
icon ='p_/image'
manage_editForm =HTMLFile('imageEdit', globals(), Kind='Image', kind='image')
manage_uploadForm =HTMLFile('imageUpload', globals(), Kind='Image', kind='image')
manage_editForm =HTMLFile('imageEdit',globals(),Kind='Image',kind='image')
manage_uploadForm=HTMLFile('imageUpload',globals(),Kind='Image',kind='image')
manage=manage_main=manage_editForm
def __str__(self):
......@@ -111,26 +115,18 @@ class Image(File):
class ImageHandler:
"""Image object handler mixin"""
#meta_types=({'name':'Image', 'action':'manage_addImageForm'},)
manage_addFileForm=HTMLFile('imageAdd', globals(), Kind='File', kind='file')
manage_addImageForm=HTMLFile('imageAdd', globals(), Kind='Image', kind='image')
""" """
manage_addFileForm=HTMLFile('imageAdd', globals(),Kind='File',kind='file')
manage_addImageForm=HTMLFile('imageAdd',globals(),Kind='Image',kind='image')
def manage_addImage(self,id,file,title='',REQUEST=None):
"""Add a new Image object"""
i=Image()
i._init(id,file)
i.title=title
self._setObject(id,i)
""" """
self._setObject(id, Image(id,title,file))
return self.manage_main(self,REQUEST)
def manage_addFile(self,id,file,title='',REQUEST=None):
"""Add a new Image object"""
i=File()
i._init(id,file)
i.title=title
self._setObject(id,i)
""" """
self._setObject(id, File(id,title,file))
return self.manage_main(self,REQUEST)
def imageIds(self):
......
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