Commit 6cb014f1 authored by Casey Duncan's avatar Casey Duncan

FileUpload objects now eval false if filename is empty.

Upload buttons on DTML, Py Scripts, Files, Images and PTs raise an error
if the file is not specified instead of clearing the source (Bug #144)
parent 82aa69a8
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
new Features: new Features:
- FileUpload objects now evaluate false when the have an empty file
name. Making it easier to check for omitted file upload form fields.
- ZClasses now use a python script as their constructor method - ZClasses now use a python script as their constructor method
instead of a DTML method. Also, ZClasses inherit from instead of a DTML method. Also, ZClasses inherit from
CatalogPathAwareness now instead of CatalogAwareness. CatalogPathAwareness now instead of CatalogAwareness.
...@@ -72,6 +75,10 @@ Zope Changes ...@@ -72,6 +75,10 @@ Zope Changes
Bugs: Bugs:
- Fixed bug #144: Upload button on dtml, py scripts, images, files and
pts now raises an error if the file is not specified rather than
clearing the source.
- Fixed bug #275: setPermissionDefault didn't actually set the - Fixed bug #275: setPermissionDefault didn't actually set the
right permission -> role mappings. right permission -> role mappings.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""DTML Document objects.""" """DTML Document objects."""
__version__='$Revision: 1.46 $'[11:-2] __version__='$Revision: 1.47 $'[11:-2]
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
from Globals import HTML, DTMLFile, MessageDialog from Globals import HTML, DTMLFile, MessageDialog
...@@ -87,7 +87,12 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -87,7 +87,12 @@ class DTMLDocument(PropertyManager, DTMLMethod):
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(''): file=file.read()
if type(file) is not type(''):
if REQUEST and not file:
raise ValueError, 'No file specified'
file=file.read()
self.munge(file) self.munge(file)
self.ZCacheable_invalidate() self.ZCacheable_invalidate()
if REQUEST: if REQUEST:
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""DTML Method objects.""" """DTML Method objects."""
__version__='$Revision: 1.74 $'[11:-2] __version__='$Revision: 1.75 $'[11:-2]
import History import History
from Globals import HTML, DTMLFile, MessageDialog from Globals import HTML, DTMLFile, MessageDialog
...@@ -262,7 +262,11 @@ class DTMLMethod(RestrictedDTML, HTML, Acquisition.Implicit, RoleManager, ...@@ -262,7 +262,11 @@ class DTMLMethod(RestrictedDTML, HTML, Acquisition.Implicit, RoleManager,
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, 'This DTML Method is locked via WebDAV' raise ResourceLockedError, 'This DTML Method is locked via WebDAV'
if type(file) is not type(''): file=file.read() if type(file) is not type(''):
if REQUEST and not file:
raise ValueError, 'No file specified'
file=file.read()
self.munge(file) self.munge(file)
self.ZCacheable_invalidate() self.ZCacheable_invalidate()
if REQUEST: if REQUEST:
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Image object""" """Image object"""
__version__='$Revision: 1.136 $'[11:-2] __version__='$Revision: 1.137 $'[11:-2]
import Globals, struct import Globals, struct
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
...@@ -30,6 +30,7 @@ from DateTime import DateTime ...@@ -30,6 +30,7 @@ from DateTime import DateTime
from Cache import Cacheable from Cache import Cacheable
from mimetools import choose_boundary from mimetools import choose_boundary
from ZPublisher import HTTPRangeSupport from ZPublisher import HTTPRangeSupport
from ZPublisher.HTTPRequest import FileUpload
StringType=type('') StringType=type('')
manage_addFileForm=DTMLFile('dtml/imageAdd', globals(),Kind='File',kind='file') manage_addFileForm=DTMLFile('dtml/imageAdd', globals(),Kind='File',kind='file')
...@@ -437,6 +438,8 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -437,6 +438,8 @@ class File(Persistent, Implicit, PropertyManager,
size=len(file) size=len(file)
if size < n: return file, size if size < n: return file, size
return Pdata(file), size return Pdata(file), size
elif isinstance(file, FileUpload) and not file:
raise ValueError, 'File not specified'
if hasattr(file, '__class__') and file.__class__ is Pdata: if hasattr(file, '__class__') and file.__class__ is Pdata:
size=len(file) size=len(file)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
Zope object encapsulating a Page Template. Zope object encapsulating a Page Template.
""" """
__version__='$Revision: 1.32 $'[11:-2] __version__='$Revision: 1.33 $'[11:-2]
import os, AccessControl, Acquisition, sys import os, AccessControl, Acquisition, sys
from Globals import DTMLFile, ImageFile, MessageDialog, package_home from Globals import DTMLFile, ImageFile, MessageDialog, package_home
...@@ -128,7 +128,11 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -128,7 +128,11 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
"""Replace the document with the text in file.""" """Replace the document with the text in file."""
if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked(): if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV" raise ResourceLockedError, "File is locked via WebDAV"
if type(file) is not type(''): file = file.read()
if type(file) is not type(''):
if not file: raise ValueError, 'File not specified'
file = file.read()
self.write(file) self.write(file)
message = 'Saved changes.' message = 'Saved changes.'
return self.pt_editForm(manage_tabs_message=message) return self.pt_editForm(manage_tabs_message=message)
......
...@@ -17,7 +17,7 @@ This product provides support for Script objects containing restricted ...@@ -17,7 +17,7 @@ This product provides support for Script objects containing restricted
Python code. Python code.
""" """
__version__='$Revision: 1.41 $'[11:-2] __version__='$Revision: 1.42 $'[11:-2]
import sys, os, traceback, re, marshal import sys, os, traceback, re, marshal
from Globals import DTMLFile, MessageDialog, package_home from Globals import DTMLFile, MessageDialog, package_home
...@@ -153,7 +153,11 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -153,7 +153,11 @@ class PythonScript(Script, Historical, Cacheable):
"""Replace the body of the script with the text in file.""" """Replace the body of the script with the text in file."""
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, "The script is locked via WebDAV." raise ResourceLockedError, "The script is locked via WebDAV."
if type(file) is not type(''): file = file.read()
if type(file) is not type(''):
if not file: raise ValueError, 'File not specified'
file = file.read()
self.write(file) self.write(file)
message = 'Saved changes.' message = 'Saved changes.'
return self.ZPythonScriptHTML_editForm(self, REQUEST, return self.ZPythonScriptHTML_editForm(self, REQUEST,
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.65 $'[11:-2] __version__='$Revision: 1.66 $'[11:-2]
import re, sys, os, urllib, time, random, cgi, codecs import re, sys, os, urllib, time, random, cgi, codecs
from BaseRequest import BaseRequest from BaseRequest import BaseRequest
...@@ -1054,6 +1054,12 @@ class FileUpload: ...@@ -1054,6 +1054,12 @@ class FileUpload:
# self.headers so that managed code can access them. # self.headers so that managed code can access them.
try: self.headers.__allow_access_to_unprotected_subobjects__ = 1 try: self.headers.__allow_access_to_unprotected_subobjects__ = 1
except: pass except: pass
def __nonzero__(self):
"""FileUpload objects are considered false if their
filename is empty.
"""
return not not self.filename
parse_cookie_lock=allocate_lock() parse_cookie_lock=allocate_lock()
......
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