Author: chrisz
Date: Tue Aug 22 15:19:23 2006
New Revision: 5629
Modified:
Webware/trunk/WebKit/Examples/FileUpload.py
Webware/trunk/WebKit/Examples/ListBox.py
Log:
More cosmetic on Examples
Modified: Webware/trunk/WebKit/Examples/FileUpload.py
==============================================================================
--- Webware/trunk/WebKit/Examples/FileUpload.py (original)
+++ Webware/trunk/WebKit/Examples/FileUpload.py Tue Aug 22 15:19:23 2006
@@ -3,7 +3,7 @@
class FileUpload(ExamplePage):
- """ This servlet shows how to handle uploaded files.
+ """This servlet shows how to handle uploaded files.
The process is fairly self explanatory. You use a form like the one below in the
writeContent method. When the form is uploaded, the request field with the name you
@@ -21,35 +21,32 @@
def title(self):
return "File Upload Example"
- def actions(self):
- return ExamplePage.actions(self) + ['fileupload']
-
def writeContent(self):
- self.writeln('''<h1>Upload Test</h1>
-<p>%s<p>
-
-<form action="FileUpload.py" method="post" enctype="multipart/form-data">
+ self.writeln("<h1>Upload Test</h1>")
+ try:
+ f = self.request().field('filename')
+ contents = f.file.read()
+ except:
+ output = '''<p>%s<p>
+<form method="post" enctype="multipart/form-data">
<input type="file" name="filename">
-<input type="submit" name="_action_fileupload" value="Upload File">
-</form>''' % (Funcs.htmlEncode(self.__doc__)))
-
- def fileupload(self):
- f = self.request().field('filename')
- contents = f.file.read()
- self.write('''<body style="background-color:#EEEEFF;padding:6pt">
-<h4>Here's the file you submitted:</h4>
-<table border cellspacing="0" cellpadding="6">
-<tr><th>name</th><td><strong>%s</strong></td></tr>
-<tr><th>type</th><td>%s</td></tr>
-<tr><th>type_options</th><td>%s</td></tr>
-<tr><th>disposition</th><td>%s</td></tr>
-<tr><th>disposition_options</th><td>%s</td></tr>
-<tr><th>headers</th><td>%s</td></tr>
-<tr><th>size</th><td>%s bytes</td></tr>
-<tr><th valign="top">contents</th>
-<td><pre style="font-size:small;margin:0pt">%s</pre></td></tr>
-</table></body>
- ''' % (f.filename, f.type, f.type_options,
- f.disposition, f.disposition_options,
- f.headers, len(contents),
- Funcs.htmlEncode(contents.strip())))
+<input type="submit" value="Upload File">
+</form>''' % Funcs.htmlEncode(self.__doc__)
+ else:
+ output = '''<h4>Here's the file you submitted:</h4>
+ <table border cellspacing="0" cellpadding="6">
+ <tr><th>name</th><td><strong>%s</strong></td></tr>
+ <tr><th>type</th><td>%s</td></tr>
+ <tr><th>type_options</th><td>%s</td></tr>
+ <tr><th>disposition</th><td>%s</td></tr>
+ <tr><th>disposition_options</th><td>%s</td></tr>
+ <tr><th>headers</th><td>%s</td></tr>
+ <tr><th>size</th><td>%s bytes</td></tr>
+ <tr><th valign="top">contents</th>
+ <td><pre style="font-size:small;margin:0pt">%s</pre></td></tr>
+ </table>''' % (
+ f.filename, f.type, f.type_options,
+ f.disposition, f.disposition_options,
+ f.headers, len(contents),
+ Funcs.htmlEncode(contents.strip()))
+ self.writeln(output)
Modified: Webware/trunk/WebKit/Examples/ListBox.py
==============================================================================
--- Webware/trunk/WebKit/Examples/ListBox.py (original)
+++ Webware/trunk/WebKit/Examples/ListBox.py Tue Aug 22 15:19:23 2006
@@ -47,7 +47,7 @@
vars = self.vars()
for item in vars['list']:
self.writeln('<option value="%d">%s</option>' % (index, self.htmlEncode(item['name'])))
- index = index + 1
+ index += 1
self.writeln('''
</select>
<p>
@@ -74,13 +74,13 @@
## Commands ##
def vars(self):
- """Returns a dictionary of values, stored in the session, for this page only."""
+ """Return a dictionary of values, stored in the session, for this page only."""
return self.session().value('form')
def new(self):
vars = self.vars()
vars['list'].append({'name': 'New item %d'%vars['newCount']})
- vars['newCount'] = vars['newCount'] + 1
+ vars['newCount'] += 1
self.writeBody()
def delete(self):
@@ -103,24 +103,24 @@
def taller(self):
vars = self.vars()
- vars['height'] = vars['height'] + self.heightChange()
+ vars['height'] += self.heightChange()
self.writeBody()
def shorter(self):
vars = self.vars()
if vars['height'] > 2:
- vars['height'] = vars['height'] - self.heightChange()
+ vars['height'] -= self.heightChange()
self.writeBody()
def wider(self):
vars = self.vars()
- vars['width'] = vars['width'] + self.widthChange()
+ vars['width'] += self.widthChange()
self.writeBody()
def narrower(self):
vars = self.vars()
if vars['width'] >= 60:
- vars['width'] = vars['width'] - self.widthChange()
+ vars['width'] -= self.widthChange()
self.writeBody()
|