I have been experimenting with the FileWidget widget in Quixote 2.0 and
have been unable to get it to work.
When the code included below is executed (through a web browser and
Apache), the following information appears in the output file:
Thu May 19 14:26:39 2005: type of try1 =
Thu May 19 14:26:39 2005: type of try2 =
Thu May 19 14:26:39 2005: try2 = fred.txt
I anticipated that the types of try1 and try2 would both be instances of
Upload. Instead, try1 is always None and try2 is a string containing the
name of the selected file.
I have browsed the Quixote websites extensively (and even changed a
HTTPRequest.get_form_var() to get_field() here and there on Wikis) but
have not been able to resolve this issue. Any help would be welcome.
Chris Hobbs
=======================code follows===========
#!/usr/bin/python
import time
import string
import quixote
from quixote.directory import Directory
from quixote.directory import Resolving
from quixote.form import widget
from quixote.form import Form
from quixote.form.widget import FileWidget
from quixote.form.widget import SubmitWidget
from quixote.form.css import BASIC_FORM_CSS
from quixote import get_request
#**********************************************
# CGI for System Record screen
#**********************************************
class RecordDirectory(Resolving, Directory):
_q_exports = ['', 'new', 'sorry']
def _q_index(self):
def display [html] ():
''
'Main Content'
''
''
''
''
self.form = Form(enctype="multipart/form-data")
self.form.add(FileWidget, "myFileWidget", size=35)
self.form.add(SubmitWidget, "mySave", "Save")
if not self.form.is_submitted() or self.form.has_errors():
return display()
else:
fp = file('/home/dpucsek/zulu/src/cgi-bin/file.txt',"a")
# Firstly try getting the information through
# the Form class
try1 = self.form.get_widget("myFileWidget").parse()
fp.write("%s: type of try1 = %s\n" %
(time.ctime(), type(try1)))
# Then try going to the HTTPRequest object directly
try2 = get_request().get_field('myFileWidget')
fp.write("%s: type of try2 = %s\n" %
(time.ctime(), type(try2)))
fp.write("%s: try2 = %s\n" % (time.ctime(), try2))
fp.close()