quixote/form form.ptl,1.5,1.6

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

Modified Files:
	form.ptl 
Log Message:
Added option to specify enctype.


Index: form.ptl
===================================================================
RCS file: /home/cvs/quixote/form/form.ptl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- form.ptl	1 Nov 2002 20:56:21 -0000	1.5
+++ form.ptl	7 Nov 2002 17:49:15 -0000	1.6
@@ -85,12 +85,20 @@
 
     TOKEN_NAME = "_form_id" # name of hidden token widget
 
-    def __init__ (self, method="post", use_tokens=1):
+    def __init__ (self, method="post", enctype=None, use_tokens=1):
 
         if method not in ("post", "get"):
-            raise ValueError, "Form method must be 'post' or 'get'"
+            raise ValueError("Form method must be 'post' or 'get' "
+                             "not %s" % method)
         self.method = method
 
+        if enctype is not None and enctype not in (
+            "application/x-www-form-urlencoded", "multipart/form-data"):
+            raise ValueError, ("Form enctype must be "
+                               "'application/x-www-form-urlencoded' or "
+                               "'multipart/form-data' not %s" % enctype)
+        self.enctype = enctype
+
         # The first major component of a form: its widgets.  We want
         # both easy access and order, so we have a dictionary and a list
         # of the same objects.  The dictionary is keyed on widget name.
@@ -138,12 +146,14 @@
         #
         # Render a form as HTML.
         assert type(action_url) in (StringType, htmltext)
-        self._render_start(request, action_url, self.method)
+        self._render_start(request, action_url, self.enctype, self.method)
         self._render_body(request)
         self._render_finish(request)
 
-    def _render_start [html] (self, request, action, method='post', name=None):
-        htmltag('form', method=method, action=action, name=name)
+    def _render_start [html] (self, request, action,
+                              enctype=None, method='post', name=None):
+        htmltag('form', enctype=enctype, method=method,
+                action=action, name=name)
         "\n"
         self._render_hidden_widgets(request)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.