Commit 13518798 authored by Tres Seaver's avatar Tres Seaver

PEP8, remove unused imports, normalize docstrings.

parent 0c91be2a
...@@ -11,41 +11,34 @@ ...@@ -11,41 +11,34 @@
# #
############################################################################## ##############################################################################
"""DTML Document objects. """DTML Document objects.
$Id$
""" """
from sgmllib import SGMLParser
from urllib import quote from urllib import quote
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl.Permissions import change_dtml_methods from AccessControl.Permissions import change_dtml_methods
from AccessControl.Permissions import change_dtml_documents from AccessControl.Permissions import change_dtml_documents
from App.class_init import InitializeClass from App.class_init import InitializeClass
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from App.special_dtml import HTML from App.special_dtml import HTML
from OFS.DTMLMethod import decapitate from OFS.DTMLMethod import decapitate
from OFS.DTMLMethod import DTMLMethod from OFS.DTMLMethod import DTMLMethod
from webdav.common import rfc1123_date from OFS.PropertyManager import PropertyManager
from webdav.Lockable import ResourceLockedError from webdav.Lockable import ResourceLockedError
from zExceptions.TracebackSupplement import PathTracebackSupplement from zExceptions.TracebackSupplement import PathTracebackSupplement
from zope.contenttype import guess_content_type from zope.contenttype import guess_content_type
from ZPublisher.Converters import type_converters
from OFS.PropertyManager import PropertyManager
done='done' done = 'done'
_marker = [] # Create a new marker object. _marker = [] # Create a new marker object.
class DTMLDocument(PropertyManager, DTMLMethod): class DTMLDocument(PropertyManager, DTMLMethod):
"""DTML Document objects are DocumentTemplate.HTML objects that act """ DocumentTemplate.HTML objects whose 'self' is the DTML object.
as methods whose 'self' is the DTML Document itself.""" """
meta_type = 'DTML Document'
meta_type='DTML Document'
icon ='p_/dtmldoc' icon ='p_/dtmldoc'
manage_options=( manage_options = (
DTMLMethod.manage_options[:2] + DTMLMethod.manage_options[:2] +
PropertyManager.manage_options + PropertyManager.manage_options +
DTMLMethod.manage_options[2:] DTMLMethod.manage_options[2:]
...@@ -58,10 +51,13 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -58,10 +51,13 @@ class DTMLDocument(PropertyManager, DTMLMethod):
or perms or perms
for perms in DTMLMethod.__ac_permissions__]) for perms in DTMLMethod.__ac_permissions__])
def manage_edit(self,data,title,SUBMIT='Change',dtpref_cols='100%', def manage_edit(self, data, title,
dtpref_rows='20',REQUEST=None): SUBMIT='Change',
""" dtpref_cols='100%',
Replaces a Documents contents with Data, Title with Title. dtpref_rows='20',
REQUEST=None
):
""" Replace contents with 'data', title with 'title'.
The SUBMIT parameter is also used to change the size of the editing 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", area on the default Document edit screen. If the value is "Smaller",
...@@ -71,41 +67,45 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -71,41 +67,45 @@ class DTMLDocument(PropertyManager, DTMLMethod):
""" """
self._validateProxy(REQUEST) self._validateProxy(REQUEST)
if self._size_changes.has_key(SUBMIT): if self._size_changes.has_key(SUBMIT):
return self._er(data,title,SUBMIT,dtpref_cols,dtpref_rows,REQUEST) return self._er(data, title,
SUBMIT, dtpref_cols, dtpref_rows, REQUEST)
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, ( raise ResourceLockedError(
'This document has been locked via WebDAV.') 'This document has been locked via WebDAV.')
self.title=str(title) self.title = str(title)
if type(data) is not type(''): data=data.read() if type(data) is not type(''):
data = data.read()
self.munge(data) self.munge(data)
self.ZCacheable_invalidate() self.ZCacheable_invalidate()
if REQUEST: if REQUEST:
message="Content changed." message = "Content changed."
return self.manage_main(self,REQUEST,manage_tabs_message=message) return self.manage_main(self, REQUEST, manage_tabs_message=message)
def manage_upload(self,file='', REQUEST=None): def manage_upload(self, file='', REQUEST=None):
"""Replace the contents of the document with the text in file.""" """ Replace the contents of the document with the text in 'file'.
"""
self._validateProxy(REQUEST) self._validateProxy(REQUEST)
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, ( raise ResourceLockedError(
'This document has been locked via WebDAV.') 'This document has been locked via WebDAV.')
if type(file) is not type(''): if type(file) is not type(''):
if REQUEST and not file: if REQUEST and not file:
raise ValueError, 'No file specified' raise ValueError, 'No file specified'
file=file.read() file = file.read()
self.munge(file) self.munge(file)
self.ZCacheable_invalidate() self.ZCacheable_invalidate()
if REQUEST: if REQUEST:
message="Content uploaded." message = "Content uploaded."
return self.manage_main(self,REQUEST,manage_tabs_message=message) return self.manage_main(self, REQUEST, manage_tabs_message=message)
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping, """Render the document with the given client object.
Response, and key word arguments."""
o If supplied, use REQUEST mapping, Response, and key word arguments.
"""
if not self._cache_namespace_keys: if not self._cache_namespace_keys:
data = self.ZCacheable_get(default=_marker) data = self.ZCacheable_get(default=_marker)
if data is not _marker: if data is not _marker:
...@@ -113,26 +113,27 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -113,26 +113,27 @@ class DTMLDocument(PropertyManager, DTMLMethod):
return data return data
__traceback_supplement__ = (PathTracebackSupplement, self) __traceback_supplement__ = (PathTracebackSupplement, self)
kw['document_id'] =self.getId() kw['document_id'] = self.getId()
kw['document_title']=self.title kw['document_title'] =self.title
if hasattr(self, 'aq_explicit'): if hasattr(self, 'aq_explicit'):
bself=self.aq_explicit bself = self.aq_explicit
else: bself=self else:
bself = self
security=getSecurityManager() security = getSecurityManager()
security.addContext(self) security.addContext(self)
try: try:
if client is None: if client is None:
# Called as subtemplate, so don't need error propigation! # Called as subtemplate, so don't need error propigation!
r=apply(HTML.__call__, (self, bself, REQUEST), kw) r = apply(HTML.__call__, (self, bself, REQUEST), kw)
if RESPONSE is None: result = r if RESPONSE is None: result = r
else: result = decapitate(r, RESPONSE) else: result = decapitate(r, RESPONSE)
if not self._cache_namespace_keys: if not self._cache_namespace_keys:
self.ZCacheable_set(result) self.ZCacheable_set(result)
return result return result
r=apply(HTML.__call__, (self, (client, bself), REQUEST), kw) r = apply(HTML.__call__, (self, (client, bself), REQUEST), kw)
if type(r) is not type('') or RESPONSE is None: if type(r) is not type('') or RESPONSE is None:
if not self._cache_namespace_keys: if not self._cache_namespace_keys:
self.ZCacheable_set(r) self.ZCacheable_set(r)
...@@ -140,12 +141,12 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -140,12 +141,12 @@ class DTMLDocument(PropertyManager, DTMLMethod):
finally: security.removeContext(self) finally: security.removeContext(self)
have_key=RESPONSE.headers.has_key have_key = RESPONSE.headers.has_key
if not (have_key('content-type') or have_key('Content-Type')): if not (have_key('content-type') or have_key('Content-Type')):
if self.__dict__.has_key('content_type'): if self.__dict__.has_key('content_type'):
c=self.content_type c = self.content_type
else: else:
c, e=guess_content_type(self.__name__, r) c, e = guess_content_type(self.__name__, r)
RESPONSE.setHeader('Content-Type', c) RESPONSE.setHeader('Content-Type', c)
result = decapitate(r, RESPONSE) result = decapitate(r, RESPONSE)
if not self._cache_namespace_keys: if not self._cache_namespace_keys:
...@@ -169,16 +170,21 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None): ...@@ -169,16 +170,21 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
"""Add a DTML Document object with the contents of file. If """Add a DTML Document object with the contents of file. If
'file' is empty, default document text is used. 'file' is empty, default document text is used.
""" """
if type(file) is not type(''): file=file.read() if type(file) is not type(''):
if not file: file=default_dd_html file = file.read()
id=str(id) if not file:
title=str(title) file = default_dd_html
ob=DTMLDocument(file, __name__=id) id =str(id)
ob.title=title title = str(title)
id=self._setObject(id, ob) ob = DTMLDocument(file, __name__=id)
ob.title = title
id = self._setObject(id, ob)
if REQUEST is not None: if REQUEST is not None:
try: u=self.DestinationURL() try:
except: u=REQUEST['URL1'] u = self.DestinationURL()
if submit==" Add and Edit ": u="%s/%s" % (u,quote(id)) except:
u = REQUEST['URL1']
if submit == " Add and Edit ":
u = "%s/%s" % (u,quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main') REQUEST.RESPONSE.redirect(u+'/manage_main')
return '' return ''
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