quixote/form widget.py,1.38,1.39

Anton Benard <abenard-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 07 Nov 2002 12:49:46 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Update of /home/cvs/quixote/form
In directory hewson:/tmp/cvs-serv1944/form

Modified Files:
	widget.py 
Log Message:
Added FileWidget().


Index: widget.py
===================================================================
RCS file: /home/cvs/quixote/form/widget.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- widget.py	1 Nov 2002 21:43:01 -0000	1.38
+++ widget.py	7 Nov 2002 17:49:44 -0000	1.39
@@ -11,7 +11,7 @@
 from types import FloatType, IntType, ListType, StringType, TupleType
 from quixote import get_request
 from quixote.html import htmltext, htmlescape, htmltag, ValuelessAttr
-
+from quixote.upload import Upload
 
 class FormValueError (Exception):
     """Raised whenever a widget has problems parsing its value."""
@@ -146,6 +146,24 @@
                        size=self.size,
                        maxlength=self.maxlength,
                        value=self.value)
+
+
+class FileWidget (StringWidget):
+    """Trivial subclass of StringWidget for uploading files.
+
+    Instance attributes: none
+    """
+    widget_type = "file"
+    html_type = "file"
+
+    def parse (self, request):
+        """parse(request) -> any"""
+        value = request.form.get(self.name)
+        if isinstance(value, Upload):
+            self.value = value
+        else:
+            self.value = None
+        return self.value
 
 
 class PasswordWidget (StringWidget):