Skip to content

Commit

Permalink
Allow upload with Add, and include binding meta-data in read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Simpson committed Dec 8, 2000
1 parent 9ad69e0 commit 59cc090
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#
##############################################################################

__version__='$Revision: 1.2 $'[11:-2]
__version__='$Revision: 1.3 $'[11:-2]

import Globals
from Globals import Persistent, HTMLFile, package_home
Expand Down Expand Up @@ -148,6 +148,10 @@ def getAssignedName(self, name, default=_marker):
raise KeyError, name
return val

def getAssignedNames(self):
# Returns a copy of the assigned names mapping
return self._asgns.copy()

def getAssignedNamesInOrder(self):
# Returns the assigned names in the same order as that of
# self._exprs.
Expand Down
27 changes: 24 additions & 3 deletions PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
Python code.
"""

__version__='$Revision: 1.2 $'[11:-2]
__version__='$Revision: 1.3 $'[11:-2]

import sys, os, traceback, re
from Globals import MessageDialog, HTMLFile, package_home
Expand All @@ -113,6 +113,10 @@ def manage_addPythonScript(self, id, REQUEST=None):
id = str(id)
id = self._setObject(id, PythonScript(id))
if REQUEST is not None:
file = REQUEST.form.get('file', None)
if file:
if type(file) is not type(''): file = file.read()
getattr(self, id).write(file)
try: u = self.DestinationURL()
except: u = REQUEST['URL1']
REQUEST.RESPONSE.redirect('%s/%s/manage_main' % (u, quote(id)))
Expand Down Expand Up @@ -337,6 +341,8 @@ def PUT(self, REQUEST, RESPONSE):
def write(self, text):
self._validateProxy()
mdata = self._metadata_map()
bindmap = self.getBindingAssignments().getAssignedNames()
bup = 0
st = 0
try:
while 1:
Expand Down Expand Up @@ -371,8 +377,13 @@ def write(self, text):
self.title = v
elif k == 'parameters':
self._params = v
elif k[:5] == 'bind ':
bindmap[_nice_bind_names[k[5:]]] = v
bup = 1

self._body = rstrip(body)
if bup:
self._setupBindings(bindmap)
self._makeFunction(1)
except:
LOG(self.meta_type, ERROR, 'write failed', error=sys.exc_info())
Expand All @@ -384,10 +395,14 @@ def manage_FTPget(self):
return self.read()

def _metadata_map(self):
return {
m = {
'title': self.title,
'parameters': self._params,
}
bindmap = self.getBindingAssignments().getAssignedNames()
for k, v in _nice_bind_names.items():
m['bind '+k] = bindmap.get(v, '')
return m

def read(self):
# Construct metadata header lines, indented the same as the body.
Expand All @@ -396,7 +411,9 @@ def read(self):
else: prefix = '##'

hlines = ['%s %s "%s"' % (prefix, self.meta_type, self.id)]
for kv in self._metadata_map().items():
mm = self._metadata_map().items()
mm.sort()
for kv in mm:
hlines.append('%s=%s' % kv)
hlines.append('')
return join(hlines, '\n' + prefix) + '\n' + self._body
Expand All @@ -419,3 +436,7 @@ def document_src(self, REQUEST=None, RESPONSE=None):

_first_indent = re.compile('(?m)^ *(?! |$)')
_nonempty_line = re.compile('(?m)^(.*\S.*)$')

_nice_bind_names = {'context': 'name_context', 'container': 'name_container',
'script': 'name_m_self', 'namespace': 'name_ns',
'subpath': 'name_subpath'}
9 changes: 7 additions & 2 deletions www/pyScriptAdd.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
<P>
Python Scripts allow you to add functionality to Zope by writing
scripts in the Python programming language
that are exposed as callable Zope objects.
that are exposed as callable Zope objects. You may choose to upload
the script from a local file by typing the file name or using the
<i>Browse</i> button.
</P>

<form action="&dtml-URL1;" method="POST">
<form action="&dtml-URL1;" method="POST" enctype="multipart/form-data">
<input type="hidden" name="manage_addPythonScript:default_method" value="">
<p>
<strong>ID:</strong> <input type="text" name="id" size="20">
</p>
<p>
<strong>File:</strong> <input type="file" name="file" size="25">
</p>
<p>
<input type="submit" value="Add and Edit" name="addedit">
<input type="submit" value="Cancel" name="manage_workspace:method">
</p>
Expand Down

0 comments on commit 59cc090

Please sign in to comment.