web/formfields.py
changeset 3503 06bced8edddf
parent 3451 6b46d73823f5
parent 3496 35a67ac6efe8
child 3524 a3431f4e2f40
--- a/web/formfields.py	Sat Sep 26 11:44:35 2009 +0200
+++ b/web/formfields.py	Mon Sep 28 12:37:01 2009 +0200
@@ -336,10 +336,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
@@ -347,6 +349,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)]
@@ -358,6 +362,8 @@
                          xml_escape(form._cw.build_url('data/puce_down.png')),
                          form._cw._('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:
@@ -626,7 +632,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,