web/formfields.py
branchstable
changeset 3496 35a67ac6efe8
parent 3347 428f95118556
child 3503 06bced8edddf
child 3510 bf746bf4a394
--- a/web/formfields.py	Mon Sep 28 10:56:37 2009 +0200
+++ b/web/formfields.py	Mon Sep 28 11:01:32 2009 +0200
@@ -320,10 +320,12 @@
     widget = FileInput
     needs_multipart = True
 
-    def __init__(self, format_field=None, encoding_field=None, **kwargs):
+    def __init__(self, format_field=None, encoding_field=None, name_field=None,
+                 **kwargs):
         super(FileField, self).__init__(**kwargs)
         self.format_field = format_field
         self.encoding_field = encoding_field
+        self.name_field = name_field
 
     def actual_fields(self, form):
         yield self
@@ -331,6 +333,8 @@
             yield self.format_field
         if self.encoding_field:
             yield self.encoding_field
+        if self.name_field:
+            yield self.name_field
 
     def render(self, form, renderer):
         wdgs = [self.get_widget(form).render(form, self, renderer)]
@@ -342,6 +346,8 @@
                          xml_escape(form.req.build_url('data/puce_down.png')),
                          form.req._('show advanced fields')))
             wdgs.append(u'<div id="%s" class="hidden">' % divid)
+            if self.name_field:
+                wdgs.append(self.render_subfield(form, self.name_field, renderer))
             if self.format_field:
                 wdgs.append(self.render_subfield(form, self.format_field, renderer))
             if self.encoding_field:
@@ -563,7 +569,7 @@
                     kwargs['max_length'] = cstr.max
             return StringField(**kwargs)
         if fieldclass is FileField:
-            for metadata in ('format', 'encoding'):
+            for metadata in ('format', 'encoding', 'name'):
                 metaschema = eschema.has_metadata(rschema, metadata)
                 if metaschema is not None:
                     kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,