Permalink
Browse files

changed behaviour of enctype so multi-part is only used when form con…

…tains file-uploads
  • Loading branch information...
1 parent 95d7a49 commit 298f59bd920285054c9b155ef3e146f3cf8035fb Tim Parkin committed Jul 15, 2009
View
@@ -2,6 +2,11 @@
Changlelog
==========
+0.8.1b
+------
+
+ * changed behaviour of enctype so that multi-part is only used if there is a file upload on the form
+
0.8.1a
------
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: formish
-Version: 0.8.1a
+Version: 0.8.1b
Summary: Formish is a schema backed, templating language agnostic form generation and handling library.
Home-page: http://form.ish.io
Author: Tim Parkin, Matt Goodall
View
@@ -449,6 +449,15 @@ def fields(self):
"""
return CollectionFieldsWrapper(self)
+ @property
+ def allfields(self):
+ fields = []
+ for field in self.fields:
+ if hasattr(field,'allfields'):
+ fields.extend( field.allfields )
+ else:
+ fields.append(field)
+ return fields
def bind(self, attr_name, attr):
"""
@@ -942,6 +951,26 @@ def fields(self):
"""
return FormFieldsWrapper(self)
+ def _has_upload_fields(self):
+ for f in self.allfields:
+ if isinstance(f.attr, schemaish.File):
+ return True
+ return False
+
+ @property
+ def allfields(self):
+ """
+ Return a generator that yields all of the fields at the top level of
+ the form (e.g. if a field is a subsection or sequence, it will be up to
+ the application to iterate that field's fields.
+ """
+ fields = []
+ for field in self.fields:
+ if hasattr(field,'allfields'):
+ fields.extend( field.allfields )
+ else:
+ fields.append(field)
+ return fields
def get_field(self, name):
@@ -7,5 +7,9 @@
id = 'id="%s" '%form.name
else:
id = ''
+if form._has_upload_fields():
+ enctype = ' enctype="multipart/form-data"'
+else:
+ enctype = ''
%>
-<form ${id|n}action="${action_url}" class="formish-form" method="${form.method.lower()}" enctype="multipart/form-data" accept-charset="utf-8">
+<form ${id|n}action="${action_url}" class="formish-form" method="${form.method.lower()}"${enctype} accept-charset="utf-8">
@@ -1267,6 +1267,23 @@ def form_UploadStructure(request):
form['myStruct.a'].widget = formish.FileUpload(filestore=CachedTempFilestore())
return form
+def form_NestedStructures(request):
+ """
+ Allow the emission of parts of a form schema using field names.
+ """
+ schema = schemaish.Structure()
+ schema.add( 'a', schemaish.String())
+ schema.add( 'b', schemaish.String())
+
+ sub_schema = schemaish.Structure()
+ sub_schema.add('x',schemaish.String())
+
+ schema.add('c', sub_schema)
+
+
+ form = formish.Form(schema, 'form')
+
+ return form
#########################
@@ -71,7 +71,7 @@
<h3>Structures</h3>
<%
-ids = ['SimpleStructure','StructureWithReadonly','UploadStructure']
+ids = ['SimpleStructure','StructureWithReadonly','UploadStructure','NestedStructures']
links(ids)
%>
View
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os, glob
-version = '0.8.1a'
+version = '0.8.1b'
setup(name='formish',
version=version,

0 comments on commit 298f59b

Please sign in to comment.